From 4fa1ec4ce9d78c17c2b760cdf6e0b924d7d9268a Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Wed, 22 Jul 2020 18:36:01 +0000 Subject: [PATCH] sv_main: Do perf calculations even if we're gonna sleep. Restores old behavior git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12866 d7cf8633-e32d-0410-b094-e92efae38249 --- sv_main.c | 175 +++++++++++++++++++++++++++--------------------------- 1 file changed, 89 insertions(+), 86 deletions(-) diff --git a/sv_main.c b/sv_main.c index ca813104..05028bd2 100644 --- a/sv_main.c +++ b/sv_main.c @@ -4111,16 +4111,6 @@ double SV_Frame(double time) qboolean playing; char vabuf[1024]; - if((sv_timer += time) < 0) - return sv_timer; - // limit the frametime steps to no more than 100ms each - if (sv_timer > 0.1) - { - if (!svs.threaded) - svs.perf_acc_lost += (sv_timer - 0.1); - sv_timer = 0.1; - } - if (!svs.threaded) { svs.perf_acc_sleeptime = host.sleeptime; @@ -4153,94 +4143,106 @@ double SV_Frame(double time) Con_DPrintf("Server can't keep up: %s\n", Host_TimingReport(vabuf, sizeof(vabuf))); svs.perf_acc_realtime = svs.perf_acc_sleeptime = svs.perf_acc_lost = svs.perf_acc_offset = svs.perf_acc_offset_squared = svs.perf_acc_offset_max = svs.perf_acc_offset_samples = host.sleeptime = 0; } + } - if (sv.active && sv_timer > 0) - { - // execute one or more server frames, with an upper limit on how much - // execution time to spend on server frames to avoid freezing the game if - // the server is overloaded, this execution time limit means the game will - // slow down if the server is taking too long. - int framecount, framelimit = 1; - double advancetime, aborttime = 0; - float offset; - prvm_prog_t *prog = SVVM_prog; - // receive packets on each main loop iteration, as the main loop may - // be undersleeping due to select() detecting a new packet - if (sv.active && !svs.threaded) - NetConn_ServerFrame(); - // run the world state - // don't allow simulation to run too fast or too slow or logic glitches can occur - - // stop running server frames if the wall time reaches this value - if (sys_ticrate.value <= 0) - advancetime = sv_timer; - else - { - advancetime = sys_ticrate.value; - // listen servers can run multiple server frames per client frame - framelimit = cl_maxphysicsframesperserverframe.integer; - aborttime = Sys_DirtyTime() + 0.1; - } - if(host_timescale.value > 0 && host_timescale.value < 1) - advancetime = min(advancetime, 0.1 / host_timescale.value); - else - advancetime = min(advancetime, 0.1); + if((sv_timer += time) < 0) + return sv_timer; - if(advancetime > 0) - { - offset = Sys_DirtyTime() - host.dirtytime; - if (offset < 0 || offset >= 1800) - offset = 0; - offset += sv_timer; - ++svs.perf_acc_offset_samples; - svs.perf_acc_offset += offset; - svs.perf_acc_offset_squared += offset * offset; - if(svs.perf_acc_offset_max < offset) - svs.perf_acc_offset_max = offset; - } + // limit the frametime steps to no more than 100ms each + if (sv_timer > 0.1) + { + if (!svs.threaded) + svs.perf_acc_lost += (sv_timer - 0.1); + sv_timer = 0.1; + } - // only advance time if not paused - // the game also pauses in singleplayer when menu or console is used - sv.frametime = advancetime * host_timescale.value; - if (host_framerate.value) - sv.frametime = host_framerate.value; - if (sv.paused || host.paused) - sv.frametime = 0; + if (sv.active && sv_timer > 0 && !svs.threaded) + { + // execute one or more server frames, with an upper limit on how much + // execution time to spend on server frames to avoid freezing the game if + // the server is overloaded, this execution time limit means the game will + // slow down if the server is taking too long. + int framecount, framelimit = 1; + double advancetime, aborttime = 0; + float offset; + prvm_prog_t *prog = SVVM_prog; + // receive packets on each main loop iteration, as the main loop may + // be undersleeping due to select() detecting a new packet + if (sv.active && !svs.threaded) + NetConn_ServerFrame(); + // run the world state + // don't allow simulation to run too fast or too slow or logic glitches can occur - for (framecount = 0;framecount < framelimit && sv_timer > 0;framecount++) - { - sv_timer -= advancetime; + // stop running server frames if the wall time reaches this value + if (sys_ticrate.value <= 0) + advancetime = sv_timer; + else + { + advancetime = sys_ticrate.value; + // listen servers can run multiple server frames per client frame + framelimit = cl_maxphysicsframesperserverframe.integer; + aborttime = Sys_DirtyTime() + 0.1; + } + if(host_timescale.value > 0 && host_timescale.value < 1) + advancetime = min(advancetime, 0.1 / host_timescale.value); + else + advancetime = min(advancetime, 0.1); - // move things around and think unless paused - if (sv.frametime) - SV_Physics(); + if(advancetime > 0) + { + offset = Sys_DirtyTime() - host.dirtytime; + if (offset < 0 || offset >= 1800) + offset = 0; + offset += sv_timer; + ++svs.perf_acc_offset_samples; + svs.perf_acc_offset += offset; + svs.perf_acc_offset_squared += offset * offset; + if(svs.perf_acc_offset_max < offset) + svs.perf_acc_offset_max = offset; + } - // if this server frame took too long, break out of the loop - if (framelimit > 1 && Sys_DirtyTime() >= aborttime) - break; - } - R_TimeReport("serverphysics"); + // only advance time if not paused + // the game also pauses in singleplayer when menu or console is used + sv.frametime = advancetime * host_timescale.value; + if (host_framerate.value) + sv.frametime = host_framerate.value; + if (sv.paused || host.paused) + sv.frametime = 0; - // send all messages to the clients - SV_SendClientMessages(); + for (framecount = 0;framecount < framelimit && sv_timer > 0;framecount++) + { + sv_timer -= advancetime; - if (sv.paused == 1 && host.realtime > sv.pausedstart && sv.pausedstart > 0) { - prog->globals.fp[OFS_PARM0] = host.realtime - sv.pausedstart; - PRVM_serverglobalfloat(time) = sv.time; - prog->ExecuteProgram(prog, PRVM_serverfunction(SV_PausedTic), "QC function SV_PausedTic is missing"); - } + // move things around and think unless paused + if (sv.frametime) + SV_Physics(); - // send an heartbeat if enough time has passed since the last one - NetConn_Heartbeat(0); - R_TimeReport("servernetwork"); + // if this server frame took too long, break out of the loop + if (framelimit > 1 && Sys_DirtyTime() >= aborttime) + break; } - else - { - // don't let r_speeds display jump around - R_TimeReport("serverphysics"); - R_TimeReport("servernetwork"); + R_TimeReport("serverphysics"); + + // send all messages to the clients + SV_SendClientMessages(); + + if (sv.paused == 1 && host.realtime > sv.pausedstart && sv.pausedstart > 0) { + prog->globals.fp[OFS_PARM0] = host.realtime - sv.pausedstart; + PRVM_serverglobalfloat(time) = sv.time; + prog->ExecuteProgram(prog, PRVM_serverfunction(SV_PausedTic), "QC function SV_PausedTic is missing"); } + + // send an heartbeat if enough time has passed since the last one + NetConn_Heartbeat(0); + R_TimeReport("servernetwork"); } + else + { + // don't let r_speeds display jump around + R_TimeReport("serverphysics"); + R_TimeReport("servernetwork"); + } + // if there is some time remaining from this frame, reset the timer if (sv_timer >= 0) { @@ -4248,6 +4250,7 @@ double SV_Frame(double time) svs.perf_acc_lost += sv_timer; sv_timer = 0; } + return sv_timer; } -- 2.39.2