2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
cl_demo.c
|
|
|
|
|
2011-08-24 11:33:05 +00:00
|
|
|
demo playback support
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-08-28 23:05:45 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2007-03-22 23:20:57 +00:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
2001-08-21 05:35:35 +00:00
|
|
|
#include <sys/time.h>
|
2007-03-22 23:20:57 +00:00
|
|
|
#endif
|
2002-03-13 18:09:33 +00:00
|
|
|
#include <time.h>
|
2012-06-03 10:51:43 +00:00
|
|
|
#include <math.h>
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2003-08-08 17:33:34 +00:00
|
|
|
#include "QF/cbuf.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-08-28 23:05:45 +00:00
|
|
|
#include "QF/cvar.h"
|
2010-08-24 07:20:07 +00:00
|
|
|
#include "QF/dstring.h"
|
2011-12-10 07:14:25 +00:00
|
|
|
#include "QF/keys.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/msg.h"
|
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
#include "compat.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
#include "client/world.h"
|
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "qw/include/cl_cam.h"
|
|
|
|
#include "qw/include/cl_demo.h"
|
|
|
|
#include "qw/include/cl_ents.h"
|
|
|
|
#include "qw/include/cl_main.h"
|
|
|
|
#include "qw/include/client.h"
|
|
|
|
#include "qw/include/host.h"
|
2005-05-02 04:09:15 +00:00
|
|
|
#include "qw/pmove.h"
|
2001-06-29 06:29:24 +00:00
|
|
|
|
2001-11-12 07:27:44 +00:00
|
|
|
typedef struct {
|
|
|
|
int frames;
|
|
|
|
double time;
|
|
|
|
double fps;
|
|
|
|
} td_stats_t;
|
|
|
|
|
2018-08-19 15:05:00 +00:00
|
|
|
static int demo_timeframes_isactive;
|
|
|
|
static int demo_timeframes_index;
|
2012-06-03 23:20:00 +00:00
|
|
|
static int demotime_cached;
|
|
|
|
static float cached_demotime;
|
|
|
|
static byte cached_newtime;
|
2018-08-19 15:05:00 +00:00
|
|
|
static float nextdemotime;
|
|
|
|
static dstring_t *demoname;
|
|
|
|
static double *demo_timeframes_array;
|
2001-08-21 05:35:35 +00:00
|
|
|
#define CL_TIMEFRAMES_ARRAYBLOCK 4096
|
2001-08-28 23:05:45 +00:00
|
|
|
|
2011-08-24 11:33:05 +00:00
|
|
|
int timedemo_count;
|
|
|
|
int timedemo_runs;
|
2001-11-12 07:27:44 +00:00
|
|
|
td_stats_t *timedemo_data;
|
|
|
|
|
2002-11-05 19:12:51 +00:00
|
|
|
static void CL_FinishTimeDemo (void);
|
|
|
|
static void CL_TimeFrames_DumpLog (void);
|
2003-08-12 06:33:13 +00:00
|
|
|
static void CL_TimeFrames_AddTimestamp (void);
|
|
|
|
static void CL_TimeFrames_Reset (void);
|
2001-08-21 05:35:35 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
int demo_gzip;
|
|
|
|
static cvar_t demo_gzip_cvar = {
|
|
|
|
.name = "demo_gzip",
|
|
|
|
.description =
|
|
|
|
"Compress demos using gzip. 0 = none, 1 = least compression, 9 = most "
|
|
|
|
"compression. Compressed demos (1-9) will have .gz appended to the "
|
|
|
|
"name",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &demo_gzip },
|
|
|
|
};
|
|
|
|
float demo_speed;
|
|
|
|
static cvar_t demo_speed_cvar = {
|
|
|
|
.name = "demo_speed",
|
|
|
|
.description =
|
|
|
|
"adjust demo playback speed. 1.0 = normal, < 1 slow-mo, > 1 timelapse",
|
|
|
|
.default_value = "1.0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &demo_speed },
|
|
|
|
};
|
|
|
|
int demo_quit;
|
|
|
|
static cvar_t demo_quit_cvar = {
|
|
|
|
.name = "demo_quit",
|
|
|
|
.description =
|
|
|
|
"automaticly quit after a timedemo has finished",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &demo_quit },
|
|
|
|
};
|
|
|
|
int demo_timeframes;
|
|
|
|
static cvar_t demo_timeframes_cvar = {
|
|
|
|
.name = "demo_timeframes",
|
|
|
|
.description =
|
|
|
|
"write timestamps for every frame",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &demo_timeframes },
|
|
|
|
};
|
2002-06-08 23:22:26 +00:00
|
|
|
|
2011-08-24 11:33:05 +00:00
|
|
|
#define MAX_DEMMSG (MAX_MSGLEN + 8) //+8 for header
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
DEMO CODE
|
|
|
|
|
|
|
|
When a demo is playing back, all NET_SendMessages are skipped, and
|
|
|
|
NET_GetMessages are read from the demo file.
|
|
|
|
|
|
|
|
Whenever cl.time gets past the last received message, another message is
|
|
|
|
read from the demo file.
|
|
|
|
*/
|
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
|
2011-08-24 11:33:05 +00:00
|
|
|
/*
|
|
|
|
CL_WriteDemoMessage
|
|
|
|
|
|
|
|
Dumps the current net message, prefixed by the length and view angles
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
CL_WriteDemoMessage (sizebuf_t *msg)
|
|
|
|
{
|
|
|
|
byte c;
|
|
|
|
float f;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
f = LittleFloat ((float) realtime);
|
|
|
|
Qwrite (cls.demofile, &f, sizeof (f));
|
|
|
|
|
|
|
|
c = dem_read;
|
|
|
|
Qwrite (cls.demofile, &c, sizeof (c));
|
|
|
|
|
|
|
|
len = LittleLong (msg->cursize);
|
|
|
|
Qwrite (cls.demofile, &len, 4);
|
|
|
|
Qwrite (cls.demofile, msg->data, msg->cursize);
|
|
|
|
|
|
|
|
Qflush (cls.demofile);
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
CL_StopPlayback
|
|
|
|
|
|
|
|
Called when a demo file runs out, or the user starts a game
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
CL_StopPlayback (void)
|
|
|
|
{
|
|
|
|
if (!cls.demoplayback)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Qclose (cls.demofile);
|
|
|
|
cls.demofile = NULL;
|
2001-08-19 03:51:52 +00:00
|
|
|
CL_SetState (ca_disconnected);
|
2012-01-05 10:19:37 +00:00
|
|
|
cls.demo_capture = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
cls.demoplayback = 0;
|
2002-10-02 21:56:45 +00:00
|
|
|
cls.demoplayback2 = 0;
|
2001-04-20 13:09:22 +00:00
|
|
|
demotime_cached = 0;
|
2004-02-19 08:58:42 +00:00
|
|
|
net_blocksend = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (cls.timedemo)
|
|
|
|
CL_FinishTimeDemo ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-08-24 11:33:05 +00:00
|
|
|
CL_StopRecording (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2011-08-24 11:33:05 +00:00
|
|
|
// write a disconnect message to the demo file
|
|
|
|
SZ_Clear (net_message->message);
|
|
|
|
MSG_WriteLong (net_message->message, -1); // -1 sequence means out of band
|
|
|
|
MSG_WriteByte (net_message->message, svc_disconnect);
|
|
|
|
MSG_WriteString (net_message->message, "EndOfDemo");
|
|
|
|
CL_WriteDemoMessage (net_message->message);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-08-24 11:33:05 +00:00
|
|
|
// finish up
|
|
|
|
Qclose (cls.demofile);
|
|
|
|
cls.demofile = NULL;
|
|
|
|
cls.demorecording = false;
|
|
|
|
Sys_Printf ("Completed demo\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2002-10-02 21:56:45 +00:00
|
|
|
#if 0
|
|
|
|
static const char *dem_names[] = {
|
|
|
|
"dem_cmd",
|
|
|
|
"dem_read",
|
|
|
|
"dem_set",
|
|
|
|
"dem_multiple",
|
|
|
|
"dem_single",
|
|
|
|
"dem_stats",
|
|
|
|
"dem_all",
|
|
|
|
"dem_invalid",
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-06-03 23:20:00 +00:00
|
|
|
static void
|
|
|
|
get_demotime (float *demotime, byte *newtime)
|
|
|
|
{
|
|
|
|
// read the time from the packet
|
|
|
|
*newtime = 0;
|
|
|
|
if (demotime_cached) {
|
|
|
|
*demotime = cached_demotime;
|
|
|
|
*newtime = cached_newtime;
|
|
|
|
demotime_cached = 0;
|
|
|
|
} else {
|
|
|
|
if (cls.demoplayback2) {
|
|
|
|
Qread (cls.demofile, newtime, sizeof (*newtime));
|
|
|
|
*demotime = cls.basetime + (cls.prevtime + *newtime) * 0.001;
|
|
|
|
} else {
|
|
|
|
Qread (cls.demofile, demotime, sizeof (*demotime));
|
|
|
|
*demotime = LittleFloat (*demotime);
|
|
|
|
if (!nextdemotime)
|
|
|
|
realtime = nextdemotime = *demotime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
push_demotime (float demotime, byte newtime)
|
|
|
|
{
|
|
|
|
// rewind back to time
|
|
|
|
demotime_cached = 1;
|
|
|
|
cached_demotime = demotime;
|
|
|
|
cached_newtime = newtime;
|
|
|
|
}
|
|
|
|
|
2012-06-06 23:14:47 +00:00
|
|
|
// decide if it is time to grab the next message
|
2012-06-06 13:34:17 +00:00
|
|
|
static int
|
2012-06-06 23:14:47 +00:00
|
|
|
check_next_demopacket (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2012-06-06 23:14:47 +00:00
|
|
|
byte newtime;
|
|
|
|
float demotime;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-06-03 23:20:00 +00:00
|
|
|
get_demotime (&demotime, &newtime);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (cls.timedemo) {
|
|
|
|
if (cls.td_lastframe < 0)
|
|
|
|
cls.td_lastframe = demotime;
|
|
|
|
else if (demotime > cls.td_lastframe) {
|
|
|
|
cls.td_lastframe = demotime;
|
2012-06-03 23:20:00 +00:00
|
|
|
push_demotime (demotime, newtime);
|
2001-02-21 23:45:49 +00:00
|
|
|
return 0; // already read this frame's message
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
if (!cls.td_starttime && cls.state == ca_active) {
|
|
|
|
cls.td_starttime = Sys_DoubleTime ();
|
|
|
|
cls.td_startframe = host_framecount;
|
|
|
|
}
|
|
|
|
realtime = demotime; // warp
|
2001-09-07 00:11:22 +00:00
|
|
|
} else if (!cl.paused && cls.state >= ca_onserver) {
|
|
|
|
// always grab until fully connected
|
2002-10-02 21:56:45 +00:00
|
|
|
if (!cls.demoplayback2 && realtime + 1.0 < demotime) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// too far back
|
|
|
|
realtime = demotime - 1.0;
|
2012-06-03 23:20:00 +00:00
|
|
|
push_demotime (demotime, newtime);
|
2001-02-19 21:15:25 +00:00
|
|
|
return 0;
|
|
|
|
} else if (realtime < demotime) {
|
2012-06-03 23:20:00 +00:00
|
|
|
push_demotime (demotime, newtime);
|
2001-02-19 21:15:25 +00:00
|
|
|
return 0; // don't need another message yet
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
realtime = demotime; // we're warping
|
|
|
|
|
2002-10-02 21:56:45 +00:00
|
|
|
if (realtime - nextdemotime > 0.0001) {
|
|
|
|
if (nextdemotime != demotime) {
|
|
|
|
if (cls.demoplayback2) {
|
|
|
|
cls.netchan.incoming_sequence++;
|
|
|
|
cls.netchan.incoming_acknowledged++;
|
|
|
|
cls.netchan.frame_latency = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nextdemotime = demotime;
|
|
|
|
|
|
|
|
cls.prevtime += newtime;
|
2012-06-06 23:14:47 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_demopacket (void)
|
|
|
|
{
|
2021-04-04 06:53:53 +00:00
|
|
|
unsigned r;
|
2012-06-06 23:14:47 +00:00
|
|
|
|
|
|
|
Qread (cls.demofile, &net_message->message->cursize, 4);
|
|
|
|
net_message->message->cursize =
|
|
|
|
LittleLong (net_message->message->cursize);
|
|
|
|
if (net_message->message->cursize > MAX_DEMMSG)
|
|
|
|
Host_Error ("Demo message > MAX_DEMMSG: %d/%d",
|
|
|
|
net_message->message->cursize, MAX_DEMMSG);
|
|
|
|
r = Qread (cls.demofile, net_message->message->data,
|
|
|
|
net_message->message->cursize);
|
|
|
|
if (r != net_message->message->cursize) {
|
|
|
|
CL_StopPlayback ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
CL_GetDemoMessage (void)
|
|
|
|
{
|
|
|
|
byte c;
|
|
|
|
float f;
|
|
|
|
int r, i, j, tracknum;
|
|
|
|
usercmd_t *pcmd;
|
|
|
|
|
|
|
|
if (!cls.demoplayback2)
|
|
|
|
nextdemotime = realtime;
|
|
|
|
if (realtime + 1.0 < nextdemotime)
|
|
|
|
realtime = nextdemotime - 1.0;
|
|
|
|
|
|
|
|
nextdemomessage:
|
|
|
|
if (!check_next_demopacket ())
|
|
|
|
return 0;
|
2002-10-02 21:56:45 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cls.state < ca_demostart)
|
|
|
|
Host_Error ("CL_GetDemoMessage: cls.state != ca_active");
|
|
|
|
|
|
|
|
// get the msg type
|
2001-07-31 07:29:44 +00:00
|
|
|
Qread (cls.demofile, &c, sizeof (c));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-10-02 21:56:45 +00:00
|
|
|
switch (c & 7) {
|
2001-02-19 21:15:25 +00:00
|
|
|
case dem_cmd:
|
|
|
|
// user sent input
|
2002-03-15 07:35:22 +00:00
|
|
|
net_message->message->cursize = -1;
|
2001-02-19 21:15:25 +00:00
|
|
|
i = cls.netchan.outgoing_sequence & UPDATE_MASK;
|
|
|
|
pcmd = &cl.frames[i].cmd;
|
2001-07-31 07:29:44 +00:00
|
|
|
r = Qread (cls.demofile, pcmd, sizeof (*pcmd));
|
|
|
|
if (r != sizeof (*pcmd)) {
|
|
|
|
CL_StopPlayback ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// byte order stuff
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
pcmd->angles[j] = LittleFloat (pcmd->angles[j]);
|
|
|
|
pcmd->forwardmove = LittleShort (pcmd->forwardmove);
|
|
|
|
pcmd->sidemove = LittleShort (pcmd->sidemove);
|
|
|
|
pcmd->upmove = LittleShort (pcmd->upmove);
|
2012-06-06 23:14:47 +00:00
|
|
|
cl.frames[i].senttime = nextdemotime; //FIXME was demotime
|
2001-02-19 21:15:25 +00:00
|
|
|
cl.frames[i].receivedtime = -1; // we haven't gotten a reply yet
|
|
|
|
cls.netchan.outgoing_sequence++;
|
2001-07-31 07:29:44 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
Qread (cls.demofile, &f, 4);
|
2022-03-01 02:43:23 +00:00
|
|
|
cl.viewstate.player_angles[i] = LittleFloat (f);
|
2001-07-31 07:29:44 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dem_read:
|
2002-10-02 21:56:45 +00:00
|
|
|
readit:
|
2001-02-19 21:15:25 +00:00
|
|
|
// get the next message
|
2012-06-06 13:34:17 +00:00
|
|
|
if (read_demopacket () && cls.demoplayback2) {
|
2002-10-02 21:56:45 +00:00
|
|
|
tracknum = Cam_TrackNum ();
|
|
|
|
|
|
|
|
if (cls.lasttype == dem_multiple) {
|
|
|
|
if (tracknum == -1)
|
|
|
|
goto nextdemomessage;
|
|
|
|
if (!(cls.lastto & (1 << tracknum)))
|
|
|
|
goto nextdemomessage;
|
|
|
|
} else if (cls.lasttype == dem_single) {
|
|
|
|
if (tracknum == -1 || cls.lastto != spec_track)
|
|
|
|
goto nextdemomessage;
|
|
|
|
}
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case dem_set:
|
2001-07-31 07:29:44 +00:00
|
|
|
Qread (cls.demofile, &i, 4);
|
|
|
|
cls.netchan.outgoing_sequence = LittleLong (i);
|
|
|
|
Qread (cls.demofile, &i, 4);
|
|
|
|
cls.netchan.incoming_sequence = LittleLong (i);
|
2002-10-02 21:56:45 +00:00
|
|
|
if (cls.demoplayback2) {
|
|
|
|
cls.netchan.incoming_acknowledged =
|
|
|
|
cls.netchan.incoming_sequence;
|
|
|
|
goto nextdemomessage;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2002-10-02 21:56:45 +00:00
|
|
|
case dem_multiple:
|
|
|
|
r = Qread (cls.demofile, &i, 4);
|
|
|
|
if (r != 4) {
|
|
|
|
CL_StopPlayback ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
cls.lastto = LittleLong (i);
|
|
|
|
cls.lasttype = dem_multiple;
|
|
|
|
goto readit;
|
|
|
|
case dem_single:
|
|
|
|
cls.lastto = c >> 3;
|
|
|
|
cls.lasttype = dem_single;
|
|
|
|
goto readit;
|
|
|
|
case dem_stats:
|
|
|
|
cls.lastto = c >> 3;
|
|
|
|
cls.lasttype = dem_stats;
|
|
|
|
goto readit;
|
|
|
|
case dem_all:
|
|
|
|
cls.lastto = 0;
|
|
|
|
cls.lasttype = dem_all;
|
|
|
|
goto readit;
|
2001-02-19 21:15:25 +00:00
|
|
|
default:
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Corrupted demo.\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_StopPlayback ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-08-24 11:33:05 +00:00
|
|
|
static int
|
|
|
|
CL_GetPacket (void)
|
|
|
|
{
|
|
|
|
return NET_GetPacket ();
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
CL_GetMessage
|
|
|
|
|
|
|
|
Handles recording and playback of demos, on top of NET_ code
|
|
|
|
*/
|
2011-08-24 11:33:05 +00:00
|
|
|
int
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_GetMessage (void)
|
|
|
|
{
|
2003-08-12 06:33:13 +00:00
|
|
|
if (cls.demoplayback) {
|
2011-08-24 11:33:05 +00:00
|
|
|
int ret = CL_GetDemoMessage ();
|
2003-08-12 06:33:13 +00:00
|
|
|
|
2003-08-13 21:53:40 +00:00
|
|
|
if (!ret && demo_timeframes_isactive && cls.td_starttime) {
|
2003-08-12 06:33:13 +00:00
|
|
|
CL_TimeFrames_AddTimestamp ();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-08-24 11:33:05 +00:00
|
|
|
if (!CL_GetPacket ())
|
|
|
|
return 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (net_packetlog)
|
2003-03-21 21:25:44 +00:00
|
|
|
Log_Incoming_Packet (net_message->message->data,
|
2022-02-06 10:47:22 +00:00
|
|
|
net_message->message->cursize, 1);
|
2003-03-16 03:17:50 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-08-24 11:33:05 +00:00
|
|
|
if (cls.demorecording)
|
|
|
|
CL_WriteDemoMessage (net_message->message);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CL_WriteDemoCmd
|
|
|
|
|
|
|
|
Writes the current user cmd
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
CL_WriteDemoCmd (usercmd_t *pcmd)
|
|
|
|
{
|
|
|
|
byte c;
|
|
|
|
float fl;
|
|
|
|
int i;
|
|
|
|
usercmd_t cmd;
|
|
|
|
|
|
|
|
fl = LittleFloat ((float) realtime);
|
|
|
|
Qwrite (cls.demofile, &fl, sizeof (fl));
|
|
|
|
|
|
|
|
c = dem_cmd;
|
|
|
|
Qwrite (cls.demofile, &c, sizeof (c));
|
|
|
|
|
|
|
|
// correct for byte order, bytes don't matter
|
|
|
|
cmd = *pcmd;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
cmd.angles[i] = LittleFloat (cmd.angles[i]);
|
|
|
|
cmd.forwardmove = LittleShort (cmd.forwardmove);
|
|
|
|
cmd.sidemove = LittleShort (cmd.sidemove);
|
|
|
|
cmd.upmove = LittleShort (cmd.upmove);
|
|
|
|
|
|
|
|
Qwrite (cls.demofile, &cmd, sizeof (cmd));
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2022-03-01 02:43:23 +00:00
|
|
|
fl = LittleFloat (cl.viewstate.player_angles[i]);
|
2011-08-24 11:33:05 +00:00
|
|
|
Qwrite (cls.demofile, &fl, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
Qflush (cls.demofile);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CL_Stop_f
|
|
|
|
|
|
|
|
stop recording a demo
|
|
|
|
*/
|
2011-08-24 11:33:05 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_Stop_f (void)
|
|
|
|
{
|
|
|
|
if (!cls.demorecording) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Not recording a demo.\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-08-24 11:33:05 +00:00
|
|
|
CL_StopRecording ();
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-08-24 11:33:05 +00:00
|
|
|
/*
|
|
|
|
CL_Record_f
|
|
|
|
|
2012-06-08 11:07:31 +00:00
|
|
|
record <demoname>
|
2011-08-24 11:33:05 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
CL_Record_f (void)
|
|
|
|
{
|
|
|
|
if (Cmd_Argc () > 2) {
|
|
|
|
// we use a demo name like year-month-day-hours-minutes-mapname.qwd
|
|
|
|
// if there is no argument
|
|
|
|
Sys_Printf ("record [demoname]\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cls.demoplayback || cls.state != ca_active) {
|
|
|
|
Sys_Printf ("You must be connected to record.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cls.demorecording)
|
|
|
|
CL_Stop_f ();
|
|
|
|
if (Cmd_Argc () == 2)
|
|
|
|
CL_Record (Cmd_Argv (1), -1);
|
|
|
|
else
|
|
|
|
CL_Record (0, -1);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-08-24 11:33:05 +00:00
|
|
|
CL_ReRecord_f
|
|
|
|
|
|
|
|
record <demoname>
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
CL_ReRecord_f (void)
|
|
|
|
{
|
|
|
|
dstring_t *name;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = Cmd_Argc ();
|
|
|
|
if (c != 2) {
|
|
|
|
Sys_Printf ("rerecord <demoname>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cls.servername || !cls.servername->str) {
|
|
|
|
Sys_Printf ("No server to which to reconnect...\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cls.demorecording)
|
|
|
|
CL_Stop_f ();
|
|
|
|
|
|
|
|
name = dstring_newstr ();
|
|
|
|
dsprintf (name, "%s/%s", qfs_gamedir->dir.def, Cmd_Argv (1));
|
|
|
|
|
|
|
|
// open the demo file
|
|
|
|
QFS_DefaultExtension (name, ".qwd");
|
|
|
|
|
|
|
|
cls.demofile = QFS_WOpen (name->str, 0);
|
|
|
|
if (!cls.demofile) {
|
|
|
|
Sys_Printf ("ERROR: couldn't open.\n");
|
|
|
|
} else {
|
|
|
|
Sys_Printf ("recording to %s.\n", name->str);
|
|
|
|
cls.demorecording = true;
|
|
|
|
|
|
|
|
CL_Disconnect ();
|
|
|
|
CL_BeginServerConnect ();
|
|
|
|
}
|
|
|
|
dstring_delete (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CL_WriteRecordDemoMessage
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Dumps the current net message, prefixed by the length and view angles
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_WriteRecordDemoMessage (sizebuf_t *msg, int seq)
|
|
|
|
{
|
2001-09-10 17:32:22 +00:00
|
|
|
byte c;
|
|
|
|
float fl;
|
|
|
|
int len, i;
|
2001-07-31 07:29:44 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!cls.demorecording)
|
|
|
|
return;
|
|
|
|
|
2001-07-31 07:29:44 +00:00
|
|
|
fl = LittleFloat ((float) realtime);
|
|
|
|
Qwrite (cls.demofile, &fl, sizeof (fl));
|
|
|
|
|
|
|
|
c = dem_read;
|
|
|
|
Qwrite (cls.demofile, &c, sizeof (c));
|
|
|
|
|
|
|
|
len = LittleLong (msg->cursize + 8);
|
|
|
|
Qwrite (cls.demofile, &len, 4);
|
|
|
|
|
|
|
|
i = LittleLong (seq);
|
|
|
|
Qwrite (cls.demofile, &i, 4);
|
|
|
|
Qwrite (cls.demofile, &i, 4);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
Qwrite (cls.demofile, msg->data, msg->cursize);
|
|
|
|
|
|
|
|
Qflush (cls.demofile);
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_WriteSetDemoMessage (void)
|
|
|
|
{
|
2001-09-10 17:32:22 +00:00
|
|
|
byte c;
|
|
|
|
float fl;
|
|
|
|
int len;
|
2001-07-31 07:29:44 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!cls.demorecording)
|
|
|
|
return;
|
|
|
|
|
2001-07-31 07:29:44 +00:00
|
|
|
fl = LittleFloat ((float) realtime);
|
|
|
|
Qwrite (cls.demofile, &fl, sizeof (fl));
|
|
|
|
|
|
|
|
c = dem_set;
|
|
|
|
Qwrite (cls.demofile, &c, sizeof (c));
|
|
|
|
|
|
|
|
len = LittleLong (cls.netchan.outgoing_sequence);
|
|
|
|
Qwrite (cls.demofile, &len, 4);
|
|
|
|
len = LittleLong (cls.netchan.incoming_sequence);
|
|
|
|
Qwrite (cls.demofile, &len, 4);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Qflush (cls.demofile);
|
|
|
|
}
|
|
|
|
|
2012-06-03 06:14:29 +00:00
|
|
|
static dstring_t *
|
|
|
|
demo_default_name (const char *argv1)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2010-08-24 07:20:07 +00:00
|
|
|
dstring_t *name;
|
2012-06-03 06:14:29 +00:00
|
|
|
const char *mapname;
|
|
|
|
int mapname_len;
|
2002-03-13 18:09:33 +00:00
|
|
|
char timestring[20];
|
|
|
|
time_t tim;
|
2001-08-28 23:05:45 +00:00
|
|
|
|
2012-06-03 06:14:29 +00:00
|
|
|
name = dstring_new ();
|
2010-08-24 07:20:07 +00:00
|
|
|
|
2012-06-03 06:14:29 +00:00
|
|
|
if (argv1) {
|
2010-08-24 07:20:07 +00:00
|
|
|
dsprintf (name, "%s/%s", qfs_gamedir->dir.def, argv1);
|
2012-06-03 06:14:29 +00:00
|
|
|
return name;
|
2002-03-13 18:09:33 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-06-03 06:14:29 +00:00
|
|
|
// Get time to a useable format
|
|
|
|
time (&tim);
|
|
|
|
strftime (timestring, 19, "%Y-%m-%d-%H-%M", localtime (&tim));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
// the leading path-name is to be removed from cl_world.worldmodel->name
|
|
|
|
mapname = QFS_SkipPath (cl_world.worldmodel->path);
|
2012-06-03 06:14:29 +00:00
|
|
|
|
|
|
|
// the map name is cut off after any "." because this would prevent
|
|
|
|
// an extension being appended
|
|
|
|
for (mapname_len = 0; mapname[mapname_len]; mapname_len++)
|
|
|
|
if (mapname[mapname_len] == '.')
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-06-03 06:14:29 +00:00
|
|
|
dsprintf (name, "%s/%s-%.*s", qfs_gamedir->dir.def, timestring,
|
|
|
|
mapname_len, mapname);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
demo_start_recording (int track)
|
|
|
|
{
|
|
|
|
byte buf_data[MAX_MSGLEN + 10]; // + 10 for header
|
|
|
|
char *s;
|
2021-03-19 11:18:45 +00:00
|
|
|
int n, i;
|
2012-06-03 06:14:29 +00:00
|
|
|
int seq = 1;
|
|
|
|
entity_state_t *es, blankes;
|
|
|
|
player_info_t *player;
|
|
|
|
sizebuf_t buf;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// serverdata
|
2001-02-19 21:15:25 +00:00
|
|
|
// send the info about the new client to all connected clients
|
|
|
|
memset (&buf, 0, sizeof (buf));
|
|
|
|
buf.data = buf_data;
|
|
|
|
buf.maxsize = sizeof (buf_data);
|
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// send the serverdata
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (&buf, svc_serverdata);
|
|
|
|
MSG_WriteLong (&buf, PROTOCOL_VERSION);
|
|
|
|
MSG_WriteLong (&buf, cl.servercount);
|
2003-02-14 22:36:10 +00:00
|
|
|
MSG_WriteString (&buf, qfs_gamedir->gamedir);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (cl.spectator)
|
|
|
|
MSG_WriteByte (&buf, cl.playernum | 128);
|
|
|
|
else
|
|
|
|
MSG_WriteByte (&buf, cl.playernum);
|
|
|
|
|
|
|
|
// send full levelname
|
|
|
|
MSG_WriteString (&buf, cl.levelname);
|
|
|
|
|
|
|
|
// send the movevars
|
|
|
|
MSG_WriteFloat (&buf, movevars.gravity);
|
|
|
|
MSG_WriteFloat (&buf, movevars.stopspeed);
|
|
|
|
MSG_WriteFloat (&buf, movevars.maxspeed);
|
|
|
|
MSG_WriteFloat (&buf, movevars.spectatormaxspeed);
|
|
|
|
MSG_WriteFloat (&buf, movevars.accelerate);
|
|
|
|
MSG_WriteFloat (&buf, movevars.airaccelerate);
|
|
|
|
MSG_WriteFloat (&buf, movevars.wateraccelerate);
|
|
|
|
MSG_WriteFloat (&buf, movevars.friction);
|
|
|
|
MSG_WriteFloat (&buf, movevars.waterfriction);
|
|
|
|
MSG_WriteFloat (&buf, movevars.entgravity);
|
|
|
|
|
|
|
|
// send music
|
|
|
|
MSG_WriteByte (&buf, svc_cdtrack);
|
|
|
|
MSG_WriteByte (&buf, 0); // none in demos
|
|
|
|
|
|
|
|
// send server info string
|
|
|
|
MSG_WriteByte (&buf, svc_stufftext);
|
2021-01-31 07:01:20 +00:00
|
|
|
MSG_WriteString (&buf, va (0, "fullserverinfo \"%s\"\n",
|
2001-11-04 07:50:39 +00:00
|
|
|
Info_MakeString (cl.serverinfo, 0)));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// flush packet
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
SZ_Clear (&buf);
|
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// soundlist
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (&buf, svc_soundlist);
|
|
|
|
MSG_WriteByte (&buf, 0);
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
s = cl.sound_name[n + 1];
|
|
|
|
while (*s) {
|
|
|
|
MSG_WriteString (&buf, s);
|
|
|
|
if (buf.cursize > MAX_MSGLEN / 2) {
|
|
|
|
MSG_WriteByte (&buf, 0);
|
|
|
|
MSG_WriteByte (&buf, n);
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
SZ_Clear (&buf);
|
|
|
|
MSG_WriteByte (&buf, svc_soundlist);
|
|
|
|
MSG_WriteByte (&buf, n + 1);
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
s = cl.sound_name[n + 1];
|
|
|
|
}
|
|
|
|
if (buf.cursize) {
|
|
|
|
MSG_WriteByte (&buf, 0);
|
|
|
|
MSG_WriteByte (&buf, 0);
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
SZ_Clear (&buf);
|
|
|
|
}
|
2001-08-28 23:05:45 +00:00
|
|
|
// modellist
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (&buf, svc_modellist);
|
|
|
|
MSG_WriteByte (&buf, 0);
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
s = cl.model_name[n + 1];
|
|
|
|
while (*s) {
|
|
|
|
MSG_WriteString (&buf, s);
|
|
|
|
if (buf.cursize > MAX_MSGLEN / 2) {
|
|
|
|
MSG_WriteByte (&buf, 0);
|
|
|
|
MSG_WriteByte (&buf, n);
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
SZ_Clear (&buf);
|
|
|
|
MSG_WriteByte (&buf, svc_modellist);
|
|
|
|
MSG_WriteByte (&buf, n + 1);
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
s = cl.model_name[n + 1];
|
|
|
|
}
|
|
|
|
if (buf.cursize) {
|
|
|
|
MSG_WriteByte (&buf, 0);
|
|
|
|
MSG_WriteByte (&buf, 0);
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
SZ_Clear (&buf);
|
|
|
|
}
|
2001-08-28 23:05:45 +00:00
|
|
|
// spawnstatic
|
2021-03-11 00:11:08 +00:00
|
|
|
for (size_t staticIndex = 0; staticIndex < cl_static_entities.size;
|
|
|
|
staticIndex++) {
|
2021-03-19 11:18:45 +00:00
|
|
|
entity_state_t *es = &cl_static_entities.a[staticIndex];
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (&buf, svc_spawnstatic);
|
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
MSG_WriteByte (&buf, es->modelindex);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
MSG_WriteByte (&buf, es->frame);
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (&buf, 0);
|
2021-03-19 11:18:45 +00:00
|
|
|
MSG_WriteByte (&buf, es->skinnum);
|
2022-03-30 15:07:20 +00:00
|
|
|
MSG_WriteCoordAngleV (&buf, (vec_t*)&es->origin, es->angles);//FIXME
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (buf.cursize > MAX_MSGLEN / 2) {
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
SZ_Clear (&buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// spawnstaticsound
|
2001-02-19 21:15:25 +00:00
|
|
|
// static sounds are skipped in demos, life is hard
|
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// baselines
|
2001-02-19 21:15:25 +00:00
|
|
|
memset (&blankes, 0, sizeof (blankes));
|
|
|
|
for (i = 0; i < MAX_EDICTS; i++) {
|
2012-07-01 02:36:47 +00:00
|
|
|
es = qw_entstates.baseline + i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (memcmp (es, &blankes, sizeof (blankes))) {
|
|
|
|
MSG_WriteByte (&buf, svc_spawnbaseline);
|
|
|
|
MSG_WriteShort (&buf, i);
|
|
|
|
|
|
|
|
MSG_WriteByte (&buf, es->modelindex);
|
|
|
|
MSG_WriteByte (&buf, es->frame);
|
|
|
|
MSG_WriteByte (&buf, es->colormap);
|
|
|
|
MSG_WriteByte (&buf, es->skinnum);
|
2022-03-30 15:07:20 +00:00
|
|
|
MSG_WriteCoordAngleV (&buf, (vec_t*)&es->origin, es->angles);//FIXME
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (buf.cursize > MAX_MSGLEN / 2) {
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
SZ_Clear (&buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MSG_WriteByte (&buf, svc_stufftext);
|
2021-01-31 07:01:20 +00:00
|
|
|
MSG_WriteString (&buf, va (0, "cmd spawn %i 0\n", cl.servercount));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (buf.cursize) {
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
SZ_Clear (&buf);
|
|
|
|
}
|
2001-08-28 23:05:45 +00:00
|
|
|
// send current status of all other players
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_CLIENTS; i++) {
|
|
|
|
player = cl.players + i;
|
2002-02-13 17:50:47 +00:00
|
|
|
if (!player->userinfo)
|
|
|
|
continue;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
MSG_WriteByte (&buf, svc_updatefrags);
|
|
|
|
MSG_WriteByte (&buf, i);
|
|
|
|
MSG_WriteShort (&buf, player->frags);
|
|
|
|
|
|
|
|
MSG_WriteByte (&buf, svc_updateping);
|
|
|
|
MSG_WriteByte (&buf, i);
|
|
|
|
MSG_WriteShort (&buf, player->ping);
|
|
|
|
|
|
|
|
MSG_WriteByte (&buf, svc_updatepl);
|
|
|
|
MSG_WriteByte (&buf, i);
|
|
|
|
MSG_WriteByte (&buf, player->pl);
|
|
|
|
|
|
|
|
MSG_WriteByte (&buf, svc_updateentertime);
|
|
|
|
MSG_WriteByte (&buf, i);
|
2001-09-11 06:04:10 +00:00
|
|
|
MSG_WriteFloat (&buf, realtime - player->entertime);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
MSG_WriteByte (&buf, svc_updateuserinfo);
|
|
|
|
MSG_WriteByte (&buf, i);
|
|
|
|
MSG_WriteLong (&buf, player->userid);
|
2001-11-04 07:50:39 +00:00
|
|
|
MSG_WriteString (&buf, Info_MakeString (player->userinfo, 0));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (buf.cursize > MAX_MSGLEN / 2) {
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
SZ_Clear (&buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-28 23:05:45 +00:00
|
|
|
// send all current light styles
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 0; i < MAX_LIGHTSTYLES; i++) {
|
|
|
|
MSG_WriteByte (&buf, svc_lightstyle);
|
|
|
|
MSG_WriteByte (&buf, (char) i);
|
2012-02-14 10:47:02 +00:00
|
|
|
MSG_WriteString (&buf, cl.lightstyle[i].map);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CL_STATS; i++) {
|
|
|
|
MSG_WriteByte (&buf, svc_updatestatlong);
|
|
|
|
MSG_WriteByte (&buf, i);
|
|
|
|
MSG_WriteLong (&buf, cl.stats[i]);
|
|
|
|
if (buf.cursize > MAX_MSGLEN / 2) {
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
SZ_Clear (&buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the client to check and download skins
|
|
|
|
// when that is completed, a begin command will be issued
|
|
|
|
MSG_WriteByte (&buf, svc_stufftext);
|
2021-01-31 07:01:20 +00:00
|
|
|
MSG_WriteString (&buf, va (0, "skins\n"));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
CL_WriteRecordDemoMessage (&buf, seq++);
|
|
|
|
|
|
|
|
CL_WriteSetDemoMessage ();
|
|
|
|
|
|
|
|
// done
|
|
|
|
}
|
|
|
|
|
2012-06-03 06:14:29 +00:00
|
|
|
void
|
|
|
|
CL_Record (const char *argv1, int track)
|
|
|
|
{
|
|
|
|
dstring_t *name;
|
|
|
|
|
|
|
|
name = demo_default_name (argv1);
|
|
|
|
|
|
|
|
// open the demo file
|
|
|
|
#ifdef HAVE_ZLIB
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (demo_gzip) {
|
2012-06-03 06:14:29 +00:00
|
|
|
QFS_DefaultExtension (name, ".qwd.gz");
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
cls.demofile = QFS_WOpen (name->str, demo_gzip);
|
2012-06-03 06:14:29 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
QFS_DefaultExtension (name, ".qwd");
|
|
|
|
cls.demofile = QFS_WOpen (name->str, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cls.demofile) {
|
|
|
|
Sys_Printf ("ERROR: couldn't open.\n");
|
|
|
|
dstring_delete (name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Printf ("recording to %s.\n", name->str);
|
|
|
|
dstring_delete (name);
|
|
|
|
cls.demorecording = true;
|
|
|
|
|
|
|
|
demo_start_recording (track);
|
|
|
|
}
|
|
|
|
|
2012-06-03 10:51:43 +00:00
|
|
|
static inline uint32_t
|
|
|
|
get_ulong (const byte *buf)
|
|
|
|
{
|
|
|
|
return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline float
|
|
|
|
get_float (const byte *buf)
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
uint32_t u;
|
|
|
|
float f;
|
|
|
|
} uf;
|
|
|
|
uf.u = get_ulong (buf);
|
|
|
|
return uf.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
demo_check_qwd_mvd (void)
|
|
|
|
{
|
|
|
|
byte buf[22];
|
|
|
|
size_t bytes;
|
|
|
|
int c, ret = 0;
|
|
|
|
float f;
|
|
|
|
uint32_t u;
|
|
|
|
|
|
|
|
bytes = Qread (cls.demofile, buf, sizeof (buf));
|
|
|
|
if (bytes != sizeof (buf))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if ((f = get_float (buf + 0)) >= 0 && !isinf (f) && !isnan (f)
|
|
|
|
&& buf[4] == dem_read && get_ulong (buf + 5) <= MAX_DEMMSG
|
|
|
|
&& get_ulong (buf + 9) == 1 && get_ulong (buf + 13) == 1
|
|
|
|
&& buf[17] == svc_serverdata
|
|
|
|
&& (u = get_ulong (buf + 18)) >= 26 && u <= PROTOCOL_VERSION) {
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
2012-06-16 04:15:48 +00:00
|
|
|
if ((f = get_float (buf + 0)) >= 0 && !isinf (f) && !isnan (f)
|
|
|
|
&& buf[4] == dem_read && get_ulong (buf + 5) == 5
|
|
|
|
&& get_ulong (buf + 9) == 0xffffffff && buf[13] == S2C_CONNECTION) {
|
|
|
|
//FIXME for now, assuming this is qwd (recorded by qizmo)
|
|
|
|
//the particular sequence seems to be:
|
|
|
|
// dem_read S2C_CONNECTION
|
|
|
|
// dem_cmd
|
|
|
|
// dem_read real start packet (with print, even:P)
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
2012-06-03 10:51:43 +00:00
|
|
|
if (buf[0] != 0 || (buf[1] != dem_read && buf[1] != dem_all)
|
|
|
|
|| (u = get_ulong (buf + 2)) > MAX_DEMMSG)
|
|
|
|
goto done;
|
|
|
|
Qseek (cls.demofile, 6, SEEK_SET);
|
|
|
|
net_message->message->cursize = u;
|
|
|
|
bytes = Qread (cls.demofile, net_message->message->data, u);
|
|
|
|
if (bytes != u)
|
|
|
|
goto done;
|
|
|
|
MSG_BeginReading (net_message);
|
|
|
|
while (!ret) {
|
|
|
|
if (net_message->badread)
|
|
|
|
goto done;
|
|
|
|
c = MSG_ReadByte (net_message);
|
|
|
|
switch (c) {
|
|
|
|
case svc_print:
|
|
|
|
MSG_ReadString (net_message);
|
|
|
|
break;
|
|
|
|
case svc_serverdata:
|
|
|
|
if (MSG_ReadLong (net_message) != PROTOCOL_VERSION)
|
|
|
|
goto done;
|
|
|
|
ret = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
Qseek (cls.demofile, 0, SEEK_SET);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-10-10 22:00:26 +00:00
|
|
|
CL_StartDemo (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2011-08-24 11:33:05 +00:00
|
|
|
dstring_t *name;
|
2012-06-03 10:51:43 +00:00
|
|
|
int type;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
// open the demo file
|
2018-08-19 15:05:00 +00:00
|
|
|
name = dstring_strdup (demoname->str);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-06-03 11:12:34 +00:00
|
|
|
QFS_DefaultExtension (name, ".mvd");
|
2014-01-23 02:57:57 +00:00
|
|
|
cls.demofile = QFS_FOpenFile (name->str);
|
2012-06-03 11:12:34 +00:00
|
|
|
if (!cls.demofile) {
|
2018-08-19 15:05:00 +00:00
|
|
|
dstring_copystr (name, demoname->str);
|
2012-06-03 11:12:34 +00:00
|
|
|
QFS_DefaultExtension (name, ".qwd");
|
2014-01-23 02:57:57 +00:00
|
|
|
cls.demofile = QFS_FOpenFile (name->str);
|
2012-06-03 11:12:34 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!cls.demofile) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("ERROR: couldn't open.\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
cls.demonum = -1; // stop demo loop
|
2011-08-28 03:54:50 +00:00
|
|
|
dstring_delete (name);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-06-03 10:51:43 +00:00
|
|
|
if (!(type = demo_check_qwd_mvd ())) {
|
|
|
|
Sys_Printf ("%s is not a valid .qwd or .mvd file.\n", name->str);
|
|
|
|
cls.demonum = -1; // stop demo loop
|
|
|
|
dstring_delete (name);
|
|
|
|
Qclose (cls.demofile);
|
|
|
|
cls.demofile = 0;
|
|
|
|
return;
|
|
|
|
}
|
2012-06-03 11:12:34 +00:00
|
|
|
Sys_Printf ("Playing demo from %s.\n", name->str);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
cls.demoplayback = true;
|
2004-02-19 08:58:42 +00:00
|
|
|
net_blocksend = 1;
|
2012-06-03 10:51:43 +00:00
|
|
|
if (type == 2) {
|
2002-10-02 21:56:45 +00:00
|
|
|
cls.demoplayback2 = true;
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "mvd\n");
|
2002-10-02 21:56:45 +00:00
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "qwd\n");
|
2002-10-02 21:56:45 +00:00
|
|
|
}
|
2001-08-19 03:51:52 +00:00
|
|
|
CL_SetState (ca_demostart);
|
2011-07-23 08:51:07 +00:00
|
|
|
Netchan_Setup (&cls.netchan, net_from, 0, NC_QPORT_SEND);
|
2001-02-19 21:15:25 +00:00
|
|
|
realtime = 0;
|
2002-10-02 21:56:45 +00:00
|
|
|
cls.findtrack = true;
|
|
|
|
cls.lasttype = 0;
|
|
|
|
cls.lastto = 0;
|
|
|
|
cls.prevtime = 0;
|
|
|
|
cls.basetime = 0;
|
2001-09-07 00:11:22 +00:00
|
|
|
demotime_cached = 0;
|
2002-10-02 21:56:45 +00:00
|
|
|
nextdemotime = 0;
|
|
|
|
CL_ClearPredict ();
|
2010-08-24 07:20:07 +00:00
|
|
|
|
|
|
|
dstring_delete (name);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-10-10 22:00:26 +00:00
|
|
|
/*
|
|
|
|
CL_PlayDemo_f
|
|
|
|
|
|
|
|
play [demoname]
|
|
|
|
*/
|
2011-08-24 11:33:05 +00:00
|
|
|
static void
|
2001-10-10 22:00:26 +00:00
|
|
|
CL_PlayDemo_f (void)
|
|
|
|
{
|
2012-01-05 10:19:37 +00:00
|
|
|
switch (Cmd_Argc ()) {
|
2012-06-29 09:44:42 +00:00
|
|
|
case 1:
|
2018-08-19 15:05:00 +00:00
|
|
|
if (!demoname->str[0])
|
2012-06-29 09:44:42 +00:00
|
|
|
goto playdemo_error;
|
|
|
|
// fall through
|
2012-01-05 10:19:37 +00:00
|
|
|
case 2:
|
|
|
|
cls.demo_capture = 0;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (!strcmp (Cmd_Argv (2), "rec")) {
|
|
|
|
cls.demo_capture = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
default:
|
2012-06-29 09:44:42 +00:00
|
|
|
playdemo_error:
|
2012-01-05 10:19:37 +00:00
|
|
|
Sys_Printf ("play <demoname> : plays a demo\n");
|
|
|
|
return;
|
2001-10-10 22:00:26 +00:00
|
|
|
}
|
2001-11-12 22:50:27 +00:00
|
|
|
timedemo_runs = timedemo_count = 1; // make sure looped timedemos stop
|
|
|
|
// disconnect from server
|
|
|
|
CL_Disconnect ();
|
|
|
|
|
2012-06-29 09:44:42 +00:00
|
|
|
if (Cmd_Argc () > 1)
|
2018-08-19 15:05:00 +00:00
|
|
|
dstring_copystr (demoname, Cmd_Argv (1));
|
2001-10-11 04:54:50 +00:00
|
|
|
CL_StartDemo ();
|
2001-10-10 22:00:26 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-10-10 22:00:26 +00:00
|
|
|
CL_StartTimeDemo (void)
|
|
|
|
{
|
|
|
|
CL_StartDemo ();
|
|
|
|
|
|
|
|
if (cls.state != ca_demostart)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// cls.td_starttime will be grabbed at the second frame of the demo, so
|
|
|
|
// all the loading time doesn't get counted
|
|
|
|
|
|
|
|
cls.timedemo = true;
|
|
|
|
cls.td_starttime = 0;
|
|
|
|
cls.td_startframe = host_framecount;
|
|
|
|
cls.td_lastframe = -1; // get a new message this frame
|
|
|
|
|
|
|
|
CL_TimeFrames_Reset ();
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (demo_timeframes)
|
2003-08-12 06:33:13 +00:00
|
|
|
demo_timeframes_isactive = 1;
|
2001-10-10 22:00:26 +00:00
|
|
|
}
|
|
|
|
|
2001-11-12 07:27:44 +00:00
|
|
|
static inline double
|
|
|
|
sqr (double x)
|
|
|
|
{
|
|
|
|
return x * x;
|
|
|
|
}
|
|
|
|
|
2002-11-05 19:12:51 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_FinishTimeDemo (void)
|
|
|
|
{
|
2011-08-24 11:33:05 +00:00
|
|
|
int frames;
|
|
|
|
float time;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
cls.timedemo = false;
|
|
|
|
|
2001-05-14 03:08:24 +00:00
|
|
|
// the first frame didn't count
|
2001-02-19 21:15:25 +00:00
|
|
|
frames = (host_framecount - cls.td_startframe) - 1;
|
|
|
|
time = Sys_DoubleTime () - cls.td_starttime;
|
|
|
|
if (!time)
|
|
|
|
time = 1;
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%i frame%s %.4g seconds %.4g fps\n", frames,
|
2003-08-13 16:08:06 +00:00
|
|
|
frames == 1 ? "" : "s", time, frames / time);
|
2001-08-21 05:35:35 +00:00
|
|
|
|
2003-03-21 21:25:44 +00:00
|
|
|
CL_TimeFrames_DumpLog ();
|
2003-08-12 06:33:13 +00:00
|
|
|
demo_timeframes_isactive = 0;
|
2001-11-12 07:27:44 +00:00
|
|
|
|
|
|
|
timedemo_count--;
|
2011-08-24 11:33:05 +00:00
|
|
|
if (timedemo_data) {
|
|
|
|
timedemo_data[timedemo_count].frames = frames;
|
|
|
|
timedemo_data[timedemo_count].time = time;
|
|
|
|
timedemo_data[timedemo_count].fps = frames / time;
|
|
|
|
}
|
2001-11-12 07:27:44 +00:00
|
|
|
if (timedemo_count > 0) {
|
2001-10-10 22:00:26 +00:00
|
|
|
CL_StartTimeDemo ();
|
2001-11-12 07:27:44 +00:00
|
|
|
} else {
|
2011-08-24 11:33:05 +00:00
|
|
|
if (--timedemo_runs > 0 && timedemo_data) {
|
2001-11-12 07:27:44 +00:00
|
|
|
double average = 0;
|
|
|
|
double variance = 0;
|
|
|
|
double min, max;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
min = max = timedemo_data[0].fps;
|
|
|
|
for (i = 0; i < timedemo_runs; i++) {
|
|
|
|
average += timedemo_data[i].fps;
|
|
|
|
min = min (min, timedemo_data[i].fps);
|
|
|
|
max = max (max, timedemo_data[i].fps);
|
|
|
|
}
|
|
|
|
average /= timedemo_runs;
|
|
|
|
for (i = 0; i < timedemo_runs; i++)
|
|
|
|
variance += sqr (timedemo_data[i].fps - average);
|
|
|
|
variance /= timedemo_runs;
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("timedemo stats for %d runs:\n", timedemo_runs);
|
|
|
|
Sys_Printf (" average fps: %.3f\n", average);
|
|
|
|
Sys_Printf (" min/max fps: %.3f/%.3f\n", min, max);
|
|
|
|
Sys_Printf ("std deviation: %.3f fps\n", sqrt (variance));
|
2001-11-12 07:27:44 +00:00
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (demo_quit)
|
2003-08-08 17:33:34 +00:00
|
|
|
Cbuf_InsertText (cl_cbuf, "quit\n");
|
2001-11-12 07:27:44 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CL_TimeDemo_f
|
|
|
|
|
|
|
|
timedemo [demoname]
|
|
|
|
*/
|
2011-08-24 11:33:05 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_TimeDemo_f (void)
|
|
|
|
{
|
2011-08-24 11:33:05 +00:00
|
|
|
int count = 1;
|
|
|
|
|
2001-10-10 22:00:26 +00:00
|
|
|
if (Cmd_Argc () < 2 || Cmd_Argc () > 3) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("timedemo <demoname> [count]: gets demo speeds\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-11-12 22:50:27 +00:00
|
|
|
timedemo_runs = timedemo_count = 1; // make sure looped timedemos stop
|
|
|
|
// disconnect from server
|
|
|
|
CL_Disconnect ();
|
|
|
|
|
2011-08-24 11:33:05 +00:00
|
|
|
if (Cmd_Argc () == 3)
|
|
|
|
count = atoi (Cmd_Argv (2));
|
|
|
|
if (timedemo_data) {
|
2001-11-12 21:42:10 +00:00
|
|
|
free (timedemo_data);
|
2011-08-24 11:33:05 +00:00
|
|
|
timedemo_data = 0;
|
|
|
|
}
|
2001-11-12 07:27:44 +00:00
|
|
|
timedemo_data = calloc (timedemo_runs, sizeof (td_stats_t));
|
2018-08-19 15:05:00 +00:00
|
|
|
dstring_copystr (demoname, Cmd_Argv (1));
|
2001-10-10 22:00:26 +00:00
|
|
|
CL_StartTimeDemo ();
|
2011-08-24 11:33:05 +00:00
|
|
|
timedemo_runs = timedemo_count = max (count, 1);
|
|
|
|
timedemo_data = calloc (timedemo_runs, sizeof (td_stats_t));
|
2001-08-21 05:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-06-08 23:22:26 +00:00
|
|
|
CL_Demo_Init (void)
|
2001-08-21 05:35:35 +00:00
|
|
|
{
|
2018-08-19 15:05:00 +00:00
|
|
|
demoname = dstring_newstr ();
|
|
|
|
|
2003-08-12 06:33:13 +00:00
|
|
|
demo_timeframes_isactive = 0;
|
|
|
|
demo_timeframes_index = 0;
|
|
|
|
demo_timeframes_array = NULL;
|
2002-06-08 23:22:26 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&demo_gzip_cvar, 0, 0);
|
|
|
|
Cvar_Register (&demo_speed_cvar, 0, 0);
|
|
|
|
Cvar_Register (&demo_quit_cvar, 0, 0);
|
|
|
|
Cvar_Register (&demo_timeframes_cvar, 0, 0);
|
2011-08-24 11:33:05 +00:00
|
|
|
Cmd_AddCommand ("record", CL_Record_f, "Record a demo, if no filename "
|
|
|
|
"argument is given\n"
|
|
|
|
"the demo will be called Year-Month-Day-Hour-Minute-"
|
|
|
|
"Mapname");
|
|
|
|
Cmd_AddCommand ("rerecord", CL_ReRecord_f, "Rerecord a demo on the same "
|
|
|
|
"server");
|
|
|
|
Cmd_AddCommand ("stop", CL_Stop_f, "Stop recording a demo");
|
|
|
|
Cmd_AddCommand ("playdemo", CL_PlayDemo_f, "Play a recorded demo");
|
|
|
|
Cmd_AddCommand ("timedemo", CL_TimeDemo_f, "Play a demo as fast as your "
|
|
|
|
"hardware can. Useful for benchmarking.");
|
2001-08-21 05:35:35 +00:00
|
|
|
}
|
|
|
|
|
2003-08-12 06:33:13 +00:00
|
|
|
static void
|
2001-08-21 05:35:35 +00:00
|
|
|
CL_TimeFrames_Reset (void)
|
|
|
|
{
|
2003-08-12 06:33:13 +00:00
|
|
|
demo_timeframes_index = 0;
|
|
|
|
free (demo_timeframes_array);
|
|
|
|
demo_timeframes_array = NULL;
|
2001-08-21 05:35:35 +00:00
|
|
|
}
|
|
|
|
|
2003-08-12 06:33:13 +00:00
|
|
|
static void
|
2001-08-21 05:35:35 +00:00
|
|
|
CL_TimeFrames_AddTimestamp (void)
|
|
|
|
{
|
2003-08-12 06:33:13 +00:00
|
|
|
if (!(demo_timeframes_index % CL_TIMEFRAMES_ARRAYBLOCK))
|
|
|
|
demo_timeframes_array = realloc
|
|
|
|
(demo_timeframes_array, sizeof (demo_timeframes_array[0]) *
|
|
|
|
((demo_timeframes_index / CL_TIMEFRAMES_ARRAYBLOCK) + 1) *
|
|
|
|
CL_TIMEFRAMES_ARRAYBLOCK);
|
|
|
|
if (demo_timeframes_array == NULL)
|
|
|
|
Sys_Error ("Unable to allocate timeframes buffer");
|
|
|
|
demo_timeframes_array[demo_timeframes_index] = Sys_DoubleTime ();
|
|
|
|
demo_timeframes_index++;
|
2001-08-21 05:35:35 +00:00
|
|
|
}
|
|
|
|
|
2002-11-05 19:12:51 +00:00
|
|
|
static void
|
|
|
|
CL_TimeFrames_DumpLog (void)
|
2001-08-21 05:35:35 +00:00
|
|
|
{
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *filename = "timeframes.txt";
|
2011-08-24 11:33:05 +00:00
|
|
|
int i;
|
|
|
|
long frame;
|
|
|
|
QFile *outputfile;
|
2001-08-21 05:35:35 +00:00
|
|
|
|
2003-08-12 06:33:13 +00:00
|
|
|
if (demo_timeframes_isactive == 0)
|
2001-08-21 05:35:35 +00:00
|
|
|
return;
|
|
|
|
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Dumping Timed Frames log: %s\n", filename);
|
2003-05-23 17:17:01 +00:00
|
|
|
outputfile = QFS_Open (filename, "w");
|
2001-08-21 05:35:35 +00:00
|
|
|
if (!outputfile) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Could not open: %s\n", filename);
|
2001-08-21 05:35:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-08-12 06:33:13 +00:00
|
|
|
for (i = 1; i < demo_timeframes_index; i++) {
|
|
|
|
frame = (demo_timeframes_array[i] - demo_timeframes_array[i - 1]) * 1e6;
|
2001-08-21 05:35:35 +00:00
|
|
|
Qprintf (outputfile, "%09ld\n", frame);
|
|
|
|
}
|
|
|
|
Qclose (outputfile);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|