From cd32f6d79afe83f8e77709d58ea49e0f5bf44aa9 Mon Sep 17 00:00:00 2001 From: BeaR Date: Mon, 8 Dec 2014 19:14:44 +0100 Subject: [PATCH] Cleanup grenade prediction, now also correctly shows smoke trails --- src/game/client/components/items.cpp | 47 +++++++++++++--------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/game/client/components/items.cpp b/src/game/client/components/items.cpp index 517a73198..8068d18d0 100644 --- a/src/game/client/components/items.cpp +++ b/src/game/client/components/items.cpp @@ -44,10 +44,29 @@ void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID) Speed = m_pClient->m_Tuning[g_Config.m_ClDummy].m_GunSpeed; } + // + bool LocalPlayerInGame = false; + + if(m_pClient->m_Snap.m_pLocalInfo) + LocalPlayerInGame = m_pClient->m_aClients[m_pClient->m_Snap.m_pLocalInfo->m_ClientID].m_Team != -1; + + // static float s_LastGameTickTime = Client()->GameTickTime(); if(m_pClient->m_Snap.m_pGameInfoObj && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED)) s_LastGameTickTime = Client()->GameTickTime(); - float Ct = (Client()->PrevGameTick()-pCurrent->m_StartTick)/(float)SERVER_TICK_SPEED + s_LastGameTickTime; + + int PrevTick = Client()->PrevGameTick(); + + if (g_Config.m_ClAntiPingGrenade && LocalPlayerInGame && !(Client()->State() == IClient::STATE_DEMOPLAYBACK)) + { + // calc predicted game tick + static int Offset = 0; + Offset = (int)(0.8f * (float)Offset + 0.2f * (float)(Client()->PredGameTick() - Client()->GameTick())); + + PrevTick += Offset; + } + + float Ct = (PrevTick-pCurrent->m_StartTick)/(float)SERVER_TICK_SPEED + s_LastGameTickTime; if(Ct < 0) return; // projectile havn't been shot yet @@ -105,31 +124,7 @@ void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID) } IGraphics::CQuadItem QuadItem(Pos.x, Pos.y, 32, 32); - - bool LocalPlayerInGame = false; - - if(m_pClient->m_Snap.m_pLocalInfo) - LocalPlayerInGame = m_pClient->m_aClients[m_pClient->m_Snap.m_pLocalInfo->m_ClientID].m_Team != -1; - - if (g_Config.m_ClAntiPingGrenade && LocalPlayerInGame && !(Client()->State() == IClient::STATE_DEMOPLAYBACK)) - { - // Draw shadows of grenades - static int Offset = 0; - Offset = (int)(0.8f * (float)Offset + 0.2f * (float)(Client()->PredGameTick() - Client()->GameTick())); - - int PredictedTick = Client()->PrevGameTick() + Offset; - float PredictedCt = (PredictedTick - pCurrent->m_StartTick)/(float)SERVER_TICK_SPEED + Client()->GameTickTime(); - - int shadow_type = pCurrent->m_Type; - RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[clamp(shadow_type, 0, NUM_WEAPONS-1)].m_pSpriteProj); - - vec2 PredictedPos = CalcPos(StartPos, StartVel, Curvature, Speed, PredictedCt); - - IGraphics::CQuadItem QuadItem(PredictedPos.x, PredictedPos.y, 32, 32); - Graphics()->QuadsDraw(&QuadItem, 1); - } - else - Graphics()->QuadsDraw(&QuadItem, 1); + Graphics()->QuadsDraw(&QuadItem, 1); Graphics()->QuadsSetRotation(0); Graphics()->QuadsEnd();