Improve CL_Move rebuild

Ported the logic from the more recent builds into the SDK rebuild. Note that this isn't all that has changed in the live builds, but were the only things worth porting back. Frame times are now properly clamped on the client. Some testing revealed that the movement now feels identical to the live version of the game, which was the target. This commit also fixes a bug in CL_Move were the datagram was not send, and the next cmd time wasn't set if the client was NOT active, while it should have.
This commit is contained in:
Kawe Mazidjatari 2023-06-05 00:27:36 +02:00
parent 671528cb2b
commit 9f2b1b1bb5
3 changed files with 63 additions and 40 deletions

View File

@ -21,7 +21,10 @@ ConVar* debug_draw_box_depth_test = nullptr;
ConVar* developer = nullptr;
ConVar* fps_max = nullptr;
ConVar* fps_input_max = nullptr;
// Taken from S15:
ConVar* usercmd_frametime_max = nullptr;
ConVar* usercmd_frametime_min = nullptr;
ConVar* staticProp_defaultBuildFrustum = nullptr;
ConVar* staticProp_no_fade_scalar = nullptr;
@ -380,8 +383,10 @@ void ConVar_StaticInit(void)
serverbrowser_mapFilter = ConVar::StaticCreate("serverbrowser_mapFilter", "0", FCVAR_RELEASE, "Filter servers by map in the server browser", false, 0.f, false, 0.f, nullptr, nullptr);
serverbrowser_gamemodeFilter = ConVar::StaticCreate("serverbrowser_gamemodeFilter", "0", FCVAR_RELEASE, "Filter servers by gamemode in the server browser", false, 0.f, false, 0.f, nullptr, nullptr);
fps_input_max = ConVar::StaticCreate("fps_input_max", "200.0", FCVAR_RELEASE, "Max movement updates ran per second.", false, 0.f, false, 0.f, nullptr, nullptr);
#endif // !DEDICATED
// Taken from S15:
usercmd_frametime_max = ConVar::StaticCreate("usercmd_frametime_max", "0.100", FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "The largest amount of simulation seconds a UserCmd can have.", false, 0.f, false, 0.f, nullptr, nullptr);
usercmd_frametime_min = ConVar::StaticCreate("usercmd_frametime_min", "0.002857", FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "The smallest amount of simulation seconds a UserCmd can have.", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// FILESYSTEM |
fs_showWarnings = ConVar::StaticCreate("fs_showWarnings" , "0", FCVAR_DEVELOPMENTONLY, "Logs the FileSystem warnings to the console, filtered by 'fs_warning_level' ( !slower! ).", true, 0.f, true, 2.f, nullptr, "0 = log to file. 1 = 0 + log to console. 2 = 1 + log to notify.");

View File

@ -12,7 +12,10 @@ extern ConVar* debug_draw_box_depth_test;
extern ConVar* developer;
extern ConVar* fps_max;
extern ConVar* fps_input_max;
// taken from S15:
extern ConVar* usercmd_frametime_max;
extern ConVar* usercmd_frametime_min;
extern ConVar* staticProp_defaultBuildFrustum;
extern ConVar* staticProp_no_fade_scalar;

View File

@ -33,22 +33,33 @@ void H_CL_Move()
commandTick = cl->m_CurrFrameSnapshot->m_TickUpdate.m_nCommandTick;
bool sendPacket = true;
float netTime = float(*g_pNetTime);
CNetChan* chan = cl->m_NetChannel;
if (cl->m_flNextCmdTime <= (0.5 / cl_cmdrate->GetFloat()) + netTime)
// Only perform clamping and packeting if the timescale value is default,
// else the timescale change won't be handled in the player's movement.
const float hostTimeScale = host_timescale->GetFloat();
const bool isTimeScaleDefault = hostTimeScale == 1.0;
const float minFrameTime = usercmd_frametime_min->GetFloat();
const float maxFrameTime = usercmd_frametime_max->GetFloat();
const float netTime = float(*g_pNetTime);
if (cl->m_flNextCmdTime <= (maxFrameTime * 0.5f) + netTime)
sendPacket = chan->CanPacket();
else if (g_pClientState->m_nOutgoingCommandNr - (commandTick+1) < 15 || host_timescale->GetFloat() == 1.0)
else if (cl->m_nOutgoingCommandNr - (commandTick+1) < MAX_BACKUP_COMMANDS || isTimeScaleDefault)
sendPacket = false;
if (cl->IsActive())
{
float timeNow = float(Plat_FloatTime());
int outCommandNr = g_pClientState->m_nOutgoingCommandNr;
const bool isActive = cl->IsActive();
bool isPaused = g_pClientState->IsPaused();
int nextCommandNr = isPaused ? outCommandNr : outCommandNr+1;
if (isActive)
{
const float movementCallTime = float(Plat_FloatTime());
const int outCommandNr = cl->m_nOutgoingCommandNr;
const bool isPaused = cl->IsPaused();
const int nextCommandNr = isPaused ? outCommandNr : outCommandNr+1;
FOR_EACH_SPLITSCREEN_PLAYER(i)
{
@ -65,22 +76,26 @@ void H_CL_Move()
if (isPaused)
{
timeScale = 1.0f;
frameTime = timeNow - s_lastMovementCall;
frameTime = movementCallTime - s_lastMovementCall;
deltaTime = frameTime;
}
else
{
timeScale = host_timescale->GetFloat();
timeScale = hostTimeScale;
frameTime = cl->m_flFrameTime + s_LastFrameTime;
deltaTime = frameTime / timeScale;
}
if (deltaTime > 0.1f)
frameTime = timeScale * 0.1f;
// Clamp the frame time to the maximum.
if (deltaTime > maxFrameTime)
frameTime = timeScale * maxFrameTime;
// Drop this frame if delta time is below the minimum.
const bool dropFrame = (isTimeScaleDefault && deltaTime < minFrameTime);
// This check originally was 'time < 0.0049999999', but
// that caused problems when the framerate was above 190.
if ((1.0 / fps_input_max->GetFloat()) > deltaTime)
if (dropFrame)
{
s_LastFrameTime = frameTime;
return;
@ -89,41 +104,41 @@ void H_CL_Move()
s_LastFrameTime = 0.0;
}
//else if (isPaused)
//{
// // This hlClient virtual call just returns false.
//}
// Create and store usercmd structure.
g_pHLClient->CreateMove(nextCommandNr, frameTime, !isPaused);
g_pClientState->m_nOutgoingCommandNr = nextCommandNr;
cl->m_nOutgoingCommandNr = nextCommandNr;
}
CL_RunPrediction();
if (sendPacket)
{
CL_SendMove();
else
chan->SetChoked(); // Choke the packet...
CLC_ClientTick tickMsg(cl->m_nDeltaTick, cl->m_nStringTableAckTick);
chan->SendNetMsg(tickMsg, false, false);
chan->SendDatagram(nullptr);
// Use full update rate when active.
float delta = netTime - float(g_pClientState->m_flNextCmdTime);
float commandInterval = (1.0f / cl_cmdrate->GetFloat()) - 0.001f;
float maxDelta = 0.0f;
if (delta >= 0.0f)
maxDelta = fminf(commandInterval, delta);
g_pClientState->m_flNextCmdTime = double(commandInterval + netTime - maxDelta);
}
else // Choke the packet...
chan->SetChoked();
s_lastMovementCall = timeNow;
s_lastMovementCall = movementCallTime;
}
if (sendPacket)
{
if (isActive)
{
CLC_ClientTick tickMsg(cl->m_nDeltaTick, cl->m_nStringTableAckTick);
chan->SendNetMsg(tickMsg, false, false);
}
chan->SendDatagram(nullptr);
// Use full update rate when active.
float delta = netTime - float(cl->m_flNextCmdTime);
float maxDelta = fminf(fmaxf(delta, 0.0f), minFrameTime);
cl->m_flNextCmdTime = double(minFrameTime + netTime - maxDelta);
}
else // Choke the packet...
chan->SetChoked();
}
void VCL_Main::Attach() const