Skip to content

Commit

Permalink
sv_user.cpp: Small code refactoring (rehlds#810)
Browse files Browse the repository at this point in the history
* Small code style fix in sv_user.cpp

* SV_EstablishTimeBase_internal: code refactoring

Co-authored-by: Sergey Shorokhov <[email protected]>
  • Loading branch information
Very Strange Karaulov and SergeyShorokhov authored Jun 19, 2021
1 parent 478f338 commit f23498b
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions rehlds/engine/sv_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ bool EXT_FUNC SV_ShouldSendConsistencyList_mod(IGameClient *cl, bool forceConsis
if (g_psvs.maxclients == 1 || g_psv.num_consistency == 0 || cl->IsProxy())
return false;

if ((!forceConsistency && mp_consistency.value == 0.0f))
if (!forceConsistency && mp_consistency.value == 0.0f)
return false;

return true;
Expand Down Expand Up @@ -1502,31 +1502,44 @@ void SV_EstablishTimeBase(client_t *cl, usercmd_t *cmds, int dropped, int numbac

void SV_EstablishTimeBase_internal(client_t *cl, usercmd_t *cmds, int dropped, int numbackup, int numcmds)
{
int cmdnum;
double runcmd_time;
int i;
double runcmd_time = 0.0;
double time_at_end = 0.0;
constexpr int MAX_DROPPED_CMDS = 24;

runcmd_time = 0.0;
cmdnum = dropped;
if (dropped < 24)
// If we haven't dropped too many packets, then run some commands
if (dropped < MAX_DROPPED_CMDS)
{
if (dropped > numbackup)
{
cmdnum = dropped - (dropped - numbackup);
runcmd_time = (double)cl->lastcmd.msec * (dropped - numbackup) / 1000.0;
// Con_Printf("%s: lost %i cmds\n", __func__, dropped - numbackup);
}

for (; cmdnum > 0; cmdnum--)
int droppedcmds = dropped;

// Run the last known cmd for each dropped cmd we don't have a backup for
while (droppedcmds > numbackup)
{
runcmd_time += cl->lastcmd.msec / 1000.0;
droppedcmds--;
}

// Now run the "history" commands if we still have dropped packets
while (droppedcmds > 0)
{
runcmd_time += cmds[cmdnum - 1 + numcmds].msec / 1000.0;
int cmdnum = numcmds + droppedcmds - 1;
runcmd_time += cmds[cmdnum].msec / 1000.0;
droppedcmds--;
}
}

for (; numcmds > 0; numcmds--)
// Now run any new command(s). Go backward because the most recent command is at index 0
for (i = numcmds - 1; i >= 0; i--)
{
runcmd_time += cmds[numcmds - 1].msec / 1000.0;
time_at_end += cmds[i].msec / 1000.0;
}

cl->svtimebase = host_frametime + g_psv.time - runcmd_time;
cl->svtimebase = host_frametime + g_psv.time - (time_at_end + runcmd_time);
}

void SV_ParseMove(client_t *pSenderClient)
Expand Down

0 comments on commit f23498b

Please sign in to comment.