From 3f9d30af0fe5679a2dfaf5cf11aa68228481bd03 Mon Sep 17 00:00:00 2001 From: trml Date: Tue, 29 Jan 2019 20:32:11 +0100 Subject: [PATCH 1/2] Sync weapon input with other inputs --- src/engine/server.h | 1 + src/engine/server/server.cpp | 6 ++++++ src/game/server/gamecontext.cpp | 6 ++++++ src/game/server/gamecontext.h | 1 + src/game/server/player.cpp | 14 +++++++++++--- src/game/server/player.h | 1 + 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/engine/server.h b/src/engine/server.h index 3f4125478..0c58c85eb 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -217,6 +217,7 @@ public: virtual void OnClientDrop(int ClientID, const char *pReason) = 0; virtual void OnClientDirectInput(int ClientID, void *pInput) = 0; virtual void OnClientPredictedInput(int ClientID, void *pInput) = 0; + virtual void OnClientPredictedEarlyInput(int ClientID, void *pInput) = 0; virtual bool IsClientReady(int ClientID) = 0; virtual bool IsClientPlayer(int ClientID) = 0; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index f8567aa5c..0c4f952f7 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1959,6 +1959,12 @@ int CServer::Run() while(t > TickStartTime(m_CurrentGameTick+1)) { + for(int c = 0; c < MAX_CLIENTS; c++) + if(m_aClients[c].m_State == CClient::STATE_INGAME) + for(int i = 0; i < 200; i++) + if(m_aClients[c].m_aInputs[i].m_GameTick == Tick() + 1) + GameServer()->OnClientPredictedEarlyInput(c, m_aClients[c].m_aInputs[i].m_aData); + m_CurrentGameTick++; NewTicks++; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 76a90b611..c4b9e7ed8 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -961,6 +961,12 @@ void CGameContext::OnClientPredictedInput(int ClientID, void *pInput) m_apPlayers[ClientID]->OnPredictedInput((CNetObj_PlayerInput *)pInput); } +void CGameContext::OnClientPredictedEarlyInput(int ClientID, void *pInput) +{ + if(!m_World.m_Paused) + m_apPlayers[ClientID]->OnPredictedEarlyInput((CNetObj_PlayerInput *)pInput); +} + struct CVoteOptionServer *CGameContext::GetVoteOption(int Index) { CVoteOptionServer *pCurrent; diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index bc6a1b639..edb4f4ba0 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -234,6 +234,7 @@ public: virtual void OnClientDrop(int ClientID, const char *pReason); virtual void OnClientDirectInput(int ClientID, void *pInput); virtual void OnClientPredictedInput(int ClientID, void *pInput); + virtual void OnClientPredictedEarlyInput(int ClientID, void *pInput); virtual void OnClientEngineJoin(int ClientID); virtual void OnClientEngineDrop(int ClientID, const char *pReason); diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 8c087e4b3..849ec879c 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -448,9 +448,7 @@ void CPlayer::OnDirectInput(CNetObj_PlayerInput *NewInput) if(m_pCharacter) { - if(!m_Paused) - m_pCharacter->OnDirectInput(NewInput); - else + if(m_Paused) m_pCharacter->ResetInput(); } @@ -468,6 +466,16 @@ void CPlayer::OnDirectInput(CNetObj_PlayerInput *NewInput) } } +void CPlayer::OnPredictedEarlyInput(CNetObj_PlayerInput *NewInput) +{ + // skip the input if chat is active + if((m_PlayerFlags&PLAYERFLAG_CHATTING) && (NewInput->m_PlayerFlags&PLAYERFLAG_CHATTING)) + return; + + if(m_pCharacter && !m_Paused) + m_pCharacter->OnDirectInput(NewInput); +} + CCharacter *CPlayer::GetCharacter() { if(m_pCharacter && m_pCharacter->IsAlive()) diff --git a/src/game/server/player.h b/src/game/server/player.h index d2d73c1e8..07fb769e9 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -37,6 +37,7 @@ public: void OnDirectInput(CNetObj_PlayerInput *NewInput); void OnPredictedInput(CNetObj_PlayerInput *NewInput); + void OnPredictedEarlyInput(CNetObj_PlayerInput *NewInput); void OnDisconnect(const char *pReason); void ThreadKillCharacter(int Weapon = WEAPON_GAME); From b9f301018fdb3a2be05d9a26ac04bfd3dda7e2ef Mon Sep 17 00:00:00 2001 From: trml Date: Mon, 11 Feb 2019 22:25:51 +0100 Subject: [PATCH 2/2] Remove nesting --- src/game/server/player.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 849ec879c..d18024c29 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -446,11 +446,8 @@ void CPlayer::OnDirectInput(CNetObj_PlayerInput *NewInput) m_PlayerFlags = NewInput->m_PlayerFlags; - if(m_pCharacter) - { - if(m_Paused) - m_pCharacter->ResetInput(); - } + if(m_pCharacter && m_Paused) + m_pCharacter->ResetInput(); if(!m_pCharacter && m_Team != TEAM_SPECTATORS && (NewInput->m_Fire&1)) m_Spawning = true;