From b7579b0f0f1940a88b4bc3b1df32f482b92a3f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 2 Jun 2024 21:50:41 +0200 Subject: [PATCH] Ensure last input send time is reset when disconnecting Reset send time when disconnecting so input sending should always behave consistently like on the first connection. --- src/game/client/components/controls.cpp | 9 +++++---- src/game/client/components/controls.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/game/client/components/controls.cpp b/src/game/client/components/controls.cpp index 136e7496a..2bfb8b06e 100644 --- a/src/game/client/components/controls.cpp +++ b/src/game/client/components/controls.cpp @@ -35,6 +35,8 @@ void CControls::OnReset() for(int &AmmoCount : m_aAmmoCount) AmmoCount = 0; m_OldMouseX = m_OldMouseY = 0.0f; + + m_LastSendTime = 0; } void CControls::ResetInput(int Dummy) @@ -188,7 +190,6 @@ void CControls::OnMessage(int Msg, void *pRawMsg) int CControls::SnapInput(int *pData) { - static int64_t LastSendTime = 0; bool Send = false; // update player state @@ -224,7 +225,7 @@ int CControls::SnapInput(int *pData) m_aInputData[g_Config.m_ClDummy].m_TargetY = (int)m_aMousePos[g_Config.m_ClDummy].y; // send once a second just to be sure - if(time_get() > LastSendTime + time_freq()) + if(time_get() > m_LastSendTime + time_freq()) Send = true; } else @@ -328,7 +329,7 @@ int CControls::SnapInput(int *pData) Send = true; // send at at least 10hz - if(time_get() > LastSendTime + time_freq() / 25) + if(time_get() > m_LastSendTime + time_freq() / 25) Send = true; if(m_pClient->m_Snap.m_pLocalCharacter && m_pClient->m_Snap.m_pLocalCharacter->m_Weapon == WEAPON_NINJA && (m_aInputData[g_Config.m_ClDummy].m_Direction || m_aInputData[g_Config.m_ClDummy].m_Jump || m_aInputData[g_Config.m_ClDummy].m_Hook)) @@ -341,7 +342,7 @@ int CControls::SnapInput(int *pData) if(!Send) return 0; - LastSendTime = time_get(); + m_LastSendTime = time_get(); mem_copy(pData, &m_aInputData[g_Config.m_ClDummy], sizeof(m_aInputData[0])); return sizeof(m_aInputData[0]); } diff --git a/src/game/client/components/controls.h b/src/game/client/components/controls.h index 67323a12a..f8ce75d71 100644 --- a/src/game/client/components/controls.h +++ b/src/game/client/components/controls.h @@ -23,6 +23,7 @@ public: int m_aAmmoCount[NUM_WEAPONS]; + int64_t m_LastSendTime; CNetObj_PlayerInput m_aInputData[NUM_DUMMIES]; CNetObj_PlayerInput m_aLastData[NUM_DUMMIES]; int m_aInputDirectionLeft[NUM_DUMMIES];