Skip to content

Commit

Permalink
Enforce m_LastAckedSnapshot nondecreasing, Remove useless m_LatestInput
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrc6 committed Jun 2, 2024
1 parent 4b6a106 commit 9e279d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/engine/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ void CServer::CClient::Reset()
for(auto &Input : m_aInputs)
Input.m_GameTick = -1;
m_CurrentInput = 0;
mem_zero(&m_LatestInput, sizeof(m_LatestInput));

m_Snapshots.PurgeAll();
m_LastAckedSnapshot = -1;
Expand Down Expand Up @@ -1631,7 +1630,10 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
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)
m_aClients[ClientId].m_SnapRate = CClient::SNAPRATE_FULL;

Expand All @@ -1655,6 +1657,8 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)

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())
IntendedTick = Tick() + 1;

Expand All @@ -1670,14 +1674,17 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
}

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 %= 200;

// call the mod with the fresh input data
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)
{
Expand Down
1 change: 0 additions & 1 deletion src/engine/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ class CServer : public IServer
int m_LastInputTick;
CSnapshotStorage m_Snapshots;

CInput m_LatestInput;
CInput m_aInputs[200]; // TODO: handle input better
int m_CurrentInput;

Expand Down

0 comments on commit 9e279d1

Please sign in to comment.