2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-15 08:08:12 +03:00

sv_user.cpp: Small code refactoring (#810)

* Small code style fix in sv_user.cpp

* SV_EstablishTimeBase_internal: code refactoring

Co-authored-by: Sergey Shorokhov <wopox1337@ya.ru>
This commit is contained in:
Very Strange Karaulov 2021-06-19 21:44:18 +03:00 committed by GitHub
parent 478f338e37
commit f23498bef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()) if (g_psvs.maxclients == 1 || g_psv.num_consistency == 0 || cl->IsProxy())
return false; return false;
if ((!forceConsistency && mp_consistency.value == 0.0f)) if (!forceConsistency && mp_consistency.value == 0.0f)
return false; return false;
return true; return true;
@ -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) void SV_EstablishTimeBase_internal(client_t *cl, usercmd_t *cmds, int dropped, int numbackup, int numcmds)
{ {
int cmdnum; int i;
double runcmd_time; double runcmd_time = 0.0;
double time_at_end = 0.0;
constexpr int MAX_DROPPED_CMDS = 24;
runcmd_time = 0.0; // If we haven't dropped too many packets, then run some commands
cmdnum = dropped; if (dropped < MAX_DROPPED_CMDS)
if (dropped < 24)
{ {
if (dropped > numbackup) if (dropped > numbackup)
{ {
cmdnum = dropped - (dropped - numbackup); // Con_Printf("%s: lost %i cmds\n", __func__, dropped - numbackup);
runcmd_time = (double)cl->lastcmd.msec * (dropped - numbackup) / 1000.0;
} }
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 += cmds[cmdnum - 1 + numcmds].msec / 1000.0; runcmd_time += cl->lastcmd.msec / 1000.0;
} droppedcmds--;
} }
for (; numcmds > 0; numcmds--) // Now run the "history" commands if we still have dropped packets
while (droppedcmds > 0)
{ {
runcmd_time += cmds[numcmds - 1].msec / 1000.0; int cmdnum = numcmds + droppedcmds - 1;
runcmd_time += cmds[cmdnum].msec / 1000.0;
droppedcmds--;
}
} }
cl->svtimebase = host_frametime + g_psv.time - runcmd_time; // Now run any new command(s). Go backward because the most recent command is at index 0
for (i = numcmds - 1; i >= 0; i--)
{
time_at_end += cmds[i].msec / 1000.0;
}
cl->svtimebase = host_frametime + g_psv.time - (time_at_end + runcmd_time);
} }
void SV_ParseMove(client_t *pSenderClient) void SV_ParseMove(client_t *pSenderClient)