From 9f453682258f4e89bb00595a87af459a7d9c8713 Mon Sep 17 00:00:00 2001 From: def Date: Tue, 15 Oct 2013 18:08:06 +0200 Subject: [PATCH] Add antiping_grenade --- src/game/client/components/items.cpp | 42 ++++++++----------- src/game/client/components/menus_settings.cpp | 8 +++- src/game/variables.h | 3 +- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/game/client/components/items.cpp b/src/game/client/components/items.cpp index 8d3f0f3a9..b1074d61e 100644 --- a/src/game/client/components/items.cpp +++ b/src/game/client/components/items.cpp @@ -98,36 +98,28 @@ void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID) IGraphics::CQuadItem QuadItem(Pos.x, Pos.y, 32, 32); - if (g_Config.m_ClAntiPing) + if (g_Config.m_ClAntiPingGrenade) { - static int Average_Offset = -1; - static float Offset_Count = 0; - static float Offset_Sum = 0; - - // Calculate average prediction offset, because client_predtick() gets varial values :((( - // Must be there is a normal way to realize it, but I'm too lazy to find it. ^) - if (Average_Offset == -1) - { - int Offset = Client()->PredGameTick() - Client()->GameTick(); - Offset_Sum += Offset; - Offset_Count++; - - if (Offset_Count >= 100) - { - Average_Offset = round(Offset_Sum / Offset_Count); - } - } - - int PredictedTick = Client()->PrevGameTick() + Average_Offset; - float PredictedCt = (PredictedTick - pCurrent->m_StartTick)/(float)SERVER_TICK_SPEED + Client()->GameTickTime(); - - if (PredictedCt >= 0) + // Draw shadows of grenades + bool LocalPlayerInGame = m_pClient->m_aClients[m_pClient->m_Snap.m_pLocalInfo->m_ClientID].m_Team != -1; + static float Offset = 1; + Offset = mix(Offset, (float)(Client()->PredGameTick() - Client()->GameTick()), 0.05); + + if(LocalPlayerInGame && !m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER) { + // Draw shadow only if grenade directed to local player + CNetObj_CharacterCore& CurChar = m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_pLocalInfo->m_ClientID].m_Cur; + CNetObj_CharacterCore& PrevChar = m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_pLocalInfo->m_ClientID].m_Prev; + vec2 ServerPos = mix(vec2(PrevChar.m_X, PrevChar.m_Y), vec2(CurChar.m_X, CurChar.m_Y), Client()->IntraGameTick()); + + 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); } diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 15aacc480..079e4e47d 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -1084,11 +1084,17 @@ void CMenus::RenderSettingsDDRace(CUIRect MainView) } MainView.HSplitTop(20.0f, &Button, &MainView); - if(DoButton_CheckBox(&g_Config.m_ClAntiPing, Localize("AntiPing (predict grenades and other players)"), g_Config.m_ClAntiPing, &Button)) + if(DoButton_CheckBox(&g_Config.m_ClAntiPing, Localize("AntiPing (predict other players)"), g_Config.m_ClAntiPing, &Button)) { g_Config.m_ClAntiPing ^= 1; } + MainView.HSplitTop(20.0f, &Button, &MainView); + if(DoButton_CheckBox(&g_Config.m_ClAntiPingGrenade, Localize("AntiPing (predict grenades)"), g_Config.m_ClAntiPingGrenade, &Button)) + { + g_Config.m_ClAntiPingGrenade ^= 1; + } + CUIRect aRects[2]; CUIRect Label; MainView.HSplitTop(5.0f, 0, &MainView); diff --git a/src/game/variables.h b/src/game/variables.h index ae16e020e..ffd9c6377 100644 --- a/src/game/variables.h +++ b/src/game/variables.h @@ -7,7 +7,8 @@ // client MACRO_CONFIG_INT(ClPredict, cl_predict, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Predict client movements") -MACRO_CONFIG_INT(ClAntiPing, cl_antiping, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Antiping (predict other players' movements") +MACRO_CONFIG_INT(ClAntiPing, cl_antiping, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Antiping (predict other players' movements)") +MACRO_CONFIG_INT(ClAntiPingGrenade, cl_antiping_grenade, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Antiping (predict grenades)") MACRO_CONFIG_INT(ClNameplates, cl_nameplates, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show name plates") MACRO_CONFIG_INT(ClNameplatesAlways, cl_nameplates_always, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Always show name plates disregarding of distance") MACRO_CONFIG_INT(ClNameplatesTeamcolors, cl_nameplates_teamcolors, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Use team colors for name plates")