From 39869257615093523e9fdc1fb927d94f0c88bea9 Mon Sep 17 00:00:00 2001 From: trml Date: Sat, 9 Nov 2019 22:49:53 +0100 Subject: [PATCH] Optimize character evolve --- src/game/client/gameclient.cpp | 18 ++++++++++++++++++ src/game/client/gameclient.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 6aab55a78..716eb73de 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1214,10 +1214,26 @@ void CGameClient::OnNewSnapshot() m_Snap.m_aCharacters[Item.m_ID].m_Active = true; m_Snap.m_aCharacters[Item.m_ID].m_Prev = *((const CNetObj_Character *)pOld); + // reuse the result from the previous evolve if the snapped character didn't change since the previous snapshot + if(m_aClients[Item.m_ID].m_Evolved.m_Tick == Client()->PrevGameTick()) + { + if(mem_comp(&m_Snap.m_aCharacters[Item.m_ID].m_Prev, &m_aClients[Item.m_ID].m_Snapped, sizeof(CNetObj_Character)) == 0) + m_Snap.m_aCharacters[Item.m_ID].m_Prev = m_aClients[Item.m_ID].m_Evolved; + if(mem_comp(&m_Snap.m_aCharacters[Item.m_ID].m_Cur, &m_aClients[Item.m_ID].m_Snapped, sizeof(CNetObj_Character)) == 0) + m_Snap.m_aCharacters[Item.m_ID].m_Cur = m_aClients[Item.m_ID].m_Evolved; + } + if(m_Snap.m_aCharacters[Item.m_ID].m_Prev.m_Tick) Evolve(&m_Snap.m_aCharacters[Item.m_ID].m_Prev, Client()->PrevGameTick()); if(m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_Tick) Evolve(&m_Snap.m_aCharacters[Item.m_ID].m_Cur, Client()->GameTick()); + + m_aClients[Item.m_ID].m_Snapped = *((const CNetObj_Character *)pData); + m_aClients[Item.m_ID].m_Evolved = m_Snap.m_aCharacters[Item.m_ID].m_Cur; + } + else + { + m_aClients[Item.m_ID].m_Evolved.m_Tick = -1; } } else if(Item.m_Type == NETOBJTYPE_DDNETCHARACTER) @@ -1798,6 +1814,8 @@ void CGameClient::CClientData::Reset() m_FreezeEnd = 0; m_DeepFrozen = false; + m_Evolved.m_Tick = -1; + UpdateRenderInfo(); } diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index c86228f15..bfeecdfb7 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -310,6 +310,9 @@ public: bool m_Paused; bool m_Spec; + CNetObj_Character m_Snapped; + CNetObj_Character m_Evolved; + void UpdateRenderInfo(); void Reset();