From 4b6a10624cae91276115ff4e17c82d98f057f5e7 Mon Sep 17 00:00:00 2001 From: Tater Date: Sat, 1 Jun 2024 21:51:49 -0500 Subject: [PATCH] Rename a couple confusing input functions, add comments --- src/engine/server/server.cpp | 2 +- src/game/server/gamecontext.cpp | 13 +++++++++---- src/game/server/player.cpp | 7 +++++-- src/game/server/player.h | 4 ++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 6a9fdde9f..f5b6bcf15 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -2901,7 +2901,7 @@ int CServer::Run() #ifdef CONF_DEBUG UpdateDebugDummies(false); #endif - + // Use DirectInput to apply any (and all) fires intended for the current tick to the gameworld for(int c = 0; c < MAX_CLIENTS; c++) { if(m_aClients[c].m_State != CClient::STATE_INGAME) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 70107c519..c5bb5e458 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1293,6 +1293,8 @@ static int PlayerFlags_SevenToSix(int Flags) } // Server hooks + +// Called on all incoming NETMSG_INPUT, reformats player flags for sixup compatibility void CGameContext::OnClientPrepareInput(int ClientId, void *pInput) { auto *pPlayerInput = (CNetObj_PlayerInput *)pInput; @@ -1300,10 +1302,11 @@ void CGameContext::OnClientPrepareInput(int ClientId, void *pInput) pPlayerInput->m_PlayerFlags = PlayerFlags_SevenToSix(pPlayerInput->m_PlayerFlags); } +// Called on all incoming NETMSG_INPUT, only sets player flags and tracks afk status. Does not perform a DirectInput void CGameContext::OnClientDirectInput(int ClientId, void *pInput) { if(!m_World.m_Paused) - m_apPlayers[ClientId]->OnDirectInput((CNetObj_PlayerInput *)pInput); + m_apPlayers[ClientId]->OnPlayerFreshInput((CNetObj_PlayerInput *)pInput); int Flags = ((CNetObj_PlayerInput *)pInput)->m_PlayerFlags; if((Flags & 256) || (Flags & 512)) @@ -1312,9 +1315,10 @@ void CGameContext::OnClientDirectInput(int ClientId, void *pInput) } } +// Called once per input that happens on this tick after OnClientPredictedEarlyInput is called. pInput is nullptr if the client did not send any fresh input this tick void CGameContext::OnClientPredictedInput(int ClientId, void *pInput) { - // early return if no input at all has been sent by a player + // early return if no input has ever been sent by the player if(pInput == nullptr && !m_aPlayerHasInput[ClientId]) return; @@ -1326,12 +1330,13 @@ void CGameContext::OnClientPredictedInput(int ClientId, void *pInput) } if(!m_World.m_Paused) - m_apPlayers[ClientId]->OnPredictedInput(pApplyInput); + m_apPlayers[ClientId]->OnPlayerInput(pApplyInput); } +// Called once per tick BEFORE OnClientPredictedInput. pInput is nullptr if the client did not send any fresh input this tick void CGameContext::OnClientPredictedEarlyInput(int ClientId, void *pInput) { - // early return if no input at all has been sent by a player + // early return if no input has ever been sent by the player if(pInput == nullptr && !m_aPlayerHasInput[ClientId]) return; diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index a6e33ccff..1ccddfd44 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -499,7 +499,8 @@ void CPlayer::OnDisconnect() m_Moderating = false; } -void CPlayer::OnPredictedInput(CNetObj_PlayerInput *pNewInput) +// Copy a input into the charecters active input to be used during the main phase of the game tick +void CPlayer::OnPlayerInput(CNetObj_PlayerInput *pNewInput) { // skip the input if chat is active if((m_PlayerFlags & PLAYERFLAG_CHATTING) && (pNewInput->m_PlayerFlags & PLAYERFLAG_CHATTING)) @@ -519,7 +520,8 @@ void CPlayer::OnPredictedInput(CNetObj_PlayerInput *pNewInput) GameServer()->SendBroadcast("This server uses an experimental translation from Teeworlds 0.7 to 0.6. Please report bugs on ddnet.org/discord", m_ClientId); } -void CPlayer::OnDirectInput(CNetObj_PlayerInput *pNewInput) +// Afk player tracking +void CPlayer::OnPlayerFreshInput(CNetObj_PlayerInput *pNewInput) { Server()->SetClientFlags(m_ClientId, pNewInput->m_PlayerFlags); @@ -540,6 +542,7 @@ void CPlayer::OnDirectInput(CNetObj_PlayerInput *pNewInput) } } +// Executes a DirectInput for the players character void CPlayer::OnPredictedEarlyInput(CNetObj_PlayerInput *pNewInput) { m_PlayerFlags = pNewInput->m_PlayerFlags; diff --git a/src/game/server/player.h b/src/game/server/player.h index ecda4fb99..74362950e 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -57,8 +57,8 @@ public: void Snap(int SnappingClient); void FakeSnap(); - void OnDirectInput(CNetObj_PlayerInput *pNewInput); - void OnPredictedInput(CNetObj_PlayerInput *pNewInput); + void OnPlayerFreshInput(CNetObj_PlayerInput *pNewInput); + void OnPlayerInput(CNetObj_PlayerInput *pNewInput); void OnPredictedEarlyInput(CNetObj_PlayerInput *pNewInput); void OnDisconnect();