Skip to content

Commit

Permalink
Added CVAR host_simu_time_quantums_per_sec to test quantimized time p…
Browse files Browse the repository at this point in the history
…rogression in Host_Frame
  • Loading branch information
vsonnier committed Jul 7, 2024
1 parent 38a9771 commit 15212ca
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
9 changes: 7 additions & 2 deletions Quake/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ cvar_t host_framerate = {"host_framerate", "0", CVAR_NONE}; // set for slow moti
cvar_t host_speeds = {"host_speeds", "0", CVAR_NONE}; // set for running times
cvar_t host_maxfps = {"host_maxfps", "200", CVAR_ARCHIVE}; // johnfitz
cvar_t host_timescale = {"host_timescale", "0", CVAR_NONE}; // johnfitz
cvar_t max_edicts = {"max_edicts", "8192", CVAR_NONE}; // johnfitz //ericw -- changed from 2048 to 8192, removed CVAR_ARCHIVE
cvar_t cl_nocsqc = {"cl_nocsqc", "0", CVAR_NONE}; // spike -- blocks the loading of any csqc modules

cvar_t host_simu_time_quantums_per_sec = {"host_simu_time_quantums_per_sec", "0", CVAR_ARCHIVE};

cvar_t max_edicts = {"max_edicts", "8192", CVAR_NONE}; // johnfitz //ericw -- changed from 2048 to 8192, removed CVAR_ARCHIVE
cvar_t cl_nocsqc = {"cl_nocsqc", "0", CVAR_NONE}; // spike -- blocks the loading of any csqc modules

cvar_t sys_ticrate = {"sys_ticrate", "0.025", CVAR_NONE}; // dedicated server
cvar_t serverprofile = {"serverprofile", "0", CVAR_NONE};
Expand Down Expand Up @@ -296,6 +299,8 @@ void Host_InitLocal (void)
Cvar_SetCallback (&host_maxfps, Max_Fps_f);
Cvar_RegisterVariable (&host_timescale); // johnfitz

Cvar_RegisterVariable (&host_simu_time_quantums_per_sec); // vso

Cvar_RegisterVariable (&cl_nocsqc); // spike
Cvar_RegisterVariable (&max_edicts); // johnfitz
Cvar_SetCallback (&max_edicts, Max_Edicts_f);
Expand Down
2 changes: 1 addition & 1 deletion Quake/host_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ Host_Status_f
*/
static void Host_Status_f (void)
{
void (*print_fn) (const char *fmt, ...) FUNCP_PRINTF (1, 2);
void (*print_fn) (const char *fmt, ...) FUNCP_PRINTF (1, 2);
client_t *client;
int seconds;
int minutes;
Expand Down
8 changes: 4 additions & 4 deletions Quake/main_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ int main (int argc, char *argv[])
Sys_Printf ("Host_Init\n");
Host_Init ();

oldtime = Sys_DoubleTime ();
oldtime = Sys_SimuDoubleTime (host_simu_time_quantums_per_sec.value);
if (isDedicated)
{
while (1)
{
newtime = Sys_DoubleTime ();
newtime = Sys_SimuDoubleTime (host_simu_time_quantums_per_sec.value);
time = newtime - oldtime;

while (time < sys_ticrate.value)
{
SDL_Delay (1);
newtime = Sys_DoubleTime ();
newtime = Sys_SimuDoubleTime (host_simu_time_quantums_per_sec.value);
time = newtime - oldtime;
}

Expand All @@ -116,7 +116,7 @@ int main (int argc, char *argv[])
/* If we're minimised, sleep a bit more */
if (!listening && VID_IsMinimized ())
SDL_Delay (32);
newtime = Sys_DoubleTime ();
newtime = Sys_SimuDoubleTime (host_simu_time_quantums_per_sec.value);
time = newtime - oldtime;

Host_Frame (time);
Expand Down
2 changes: 2 additions & 0 deletions Quake/quakedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ extern int host_framecount; // incremented every frame, never reset
extern double realtime; // not bounded in any way, changed at
// start of every frame, never reset

extern cvar_t host_simu_time_quantums_per_sec;

typedef struct filelist_item_s
{
char name[32];
Expand Down
4 changes: 4 additions & 0 deletions Quake/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ void Sys_Printf (const char *fmt, ...) FUNC_PRINTF (1, 2);

double Sys_DoubleTime (void);

// Simulation double time : only increments time by constant amounts
// <= 0 = identical to Sys_DoubleTime.
double Sys_SimuDoubleTime (int quantum_per_sec);

const char *Sys_ConsoleInput (void);

void Sys_Sleep (unsigned long msecs);
Expand Down
10 changes: 10 additions & 0 deletions Quake/sys_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,13 @@ int Sys_FileWrite (int handle, const void *data, int count)
assert (sys_handles[handle].file);
return fwrite (data, 1, count, sys_handles[handle].file);
}

double Sys_SimuDoubleTime (int quantums_per_sec)
{
if (quantums_per_sec <= 0)
return Sys_DoubleTime ();

double time_in_quantums = round (Sys_DoubleTime () * quantums_per_sec);

return time_in_quantums / quantums_per_sec;
}

0 comments on commit 15212ca

Please sign in to comment.