Enforce m_LastAckedSnapshot nondecreasing, Remove useless m_LatestInput

This commit is contained in:
Tater 2024-06-01 22:13:11 -05:00
parent 4b6a10624c
commit 9e279d1049
2 changed files with 11 additions and 5 deletions

View file

@ -208,7 +208,6 @@ void CServer::CClient::Reset()
for(auto &Input : m_aInputs) for(auto &Input : m_aInputs)
Input.m_GameTick = -1; Input.m_GameTick = -1;
m_CurrentInput = 0; m_CurrentInput = 0;
mem_zero(&m_LatestInput, sizeof(m_LatestInput));
m_Snapshots.PurgeAll(); m_Snapshots.PurgeAll();
m_LastAckedSnapshot = -1; m_LastAckedSnapshot = -1;
@ -1631,7 +1630,10 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
return; return;
} }
m_aClients[ClientId].m_LastAckedSnapshot = LastAckedSnapshot; // The LastAckedSnapshot should only increase
if(LastAckedSnapshot > m_aClients[ClientId].m_LastAckedSnapshot)
m_aClients[ClientId].m_LastAckedSnapshot = LastAckedSnapshot;
if(m_aClients[ClientId].m_LastAckedSnapshot > 0) if(m_aClients[ClientId].m_LastAckedSnapshot > 0)
m_aClients[ClientId].m_SnapRate = CClient::SNAPRATE_FULL; m_aClients[ClientId].m_SnapRate = CClient::SNAPRATE_FULL;
@ -1655,6 +1657,8 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
CClient::CInput *pInput = &m_aClients[ClientId].m_aInputs[m_aClients[ClientId].m_CurrentInput]; CClient::CInput *pInput = &m_aClients[ClientId].m_aInputs[m_aClients[ClientId].m_CurrentInput];
// TODO: This should probably not be here, the most recent input can be found by looping over the ring buffer
// so we should not change the inputs original intended tick since we might need that information
if(IntendedTick <= Tick()) if(IntendedTick <= Tick())
IntendedTick = Tick() + 1; IntendedTick = Tick() + 1;
@ -1670,14 +1674,17 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
} }
GameServer()->OnClientPrepareInput(ClientId, pInput->m_aData); GameServer()->OnClientPrepareInput(ClientId, pInput->m_aData);
mem_copy(m_aClients[ClientId].m_LatestInput.m_aData, pInput->m_aData, MAX_INPUT_SIZE * sizeof(int));
CClient::CInput LatestInput;
mem_copy(LatestInput.m_aData, pInput->m_aData, MAX_INPUT_SIZE * sizeof(int));
m_aClients[ClientId].m_CurrentInput++; m_aClients[ClientId].m_CurrentInput++;
m_aClients[ClientId].m_CurrentInput %= 200; m_aClients[ClientId].m_CurrentInput %= 200;
// call the mod with the fresh input data // call the mod with the fresh input data
if(m_aClients[ClientId].m_State == CClient::STATE_INGAME) if(m_aClients[ClientId].m_State == CClient::STATE_INGAME)
GameServer()->OnClientDirectInput(ClientId, m_aClients[ClientId].m_LatestInput.m_aData); GameServer()->OnClientDirectInput(ClientId, LatestInput.m_aData);
} }
else if(Msg == NETMSG_RCON_CMD) else if(Msg == NETMSG_RCON_CMD)
{ {

View file

@ -147,7 +147,6 @@ public:
int m_LastInputTick; int m_LastInputTick;
CSnapshotStorage m_Snapshots; CSnapshotStorage m_Snapshots;
CInput m_LatestInput;
CInput m_aInputs[200]; // TODO: handle input better CInput m_aInputs[200]; // TODO: handle input better
int m_CurrentInput; int m_CurrentInput;