diff --git a/src/game/client/components/items.cpp b/src/game/client/components/items.cpp index 4f57d9f9c..8d3f0f3a9 100644 --- a/src/game/client/components/items.cpp +++ b/src/game/client/components/items.cpp @@ -100,60 +100,37 @@ void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID) if (g_Config.m_ClAntiPing) { - // 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(pCurrent->m_Type == WEAPON_GRENADE && LocalPlayerInGame && !m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER) - if(LocalPlayerInGame && !m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER) + 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) { - // 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 (m_pClient->m_Average_Prediction_Offset == -1) + int Offset = Client()->PredGameTick() - Client()->GameTick(); + Offset_Sum += Offset; + Offset_Count++; + + if (Offset_Count >= 100) { - int Offset = Client()->PredGameTick() - Client()->GameTick(); - m_pClient->m_Prediction_Offset_Summ += Offset; - m_pClient->m_Prediction_Offset_Count++; - - if (m_pClient->m_Prediction_Offset_Count >= 100) - { - m_pClient->m_Average_Prediction_Offset = - round((float)m_pClient->m_Prediction_Offset_Summ / m_pClient->m_Prediction_Offset_Count); - } - } - */ - // 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()); - - // float d1 = distance(Pos, ServerPos); - // float d2 = distance(PrevPos, ServerPos); - // if (d1 < 0) d1 *= -1; - // if (d2 < 0) d2 *= -1; - - // if (m_pClient->m_Average_Prediction_Offset != -1 && GrenadeIsDirectedToLocalPlayer) - { - // int PredictedTick = Client()->PrevGameTick() + m_pClient->m_Average_Prediction_Offset; - int PredictedTick = Client()->PrevGameTick() + Offset; - float PredictedCt = (PredictedTick - pCurrent->m_StartTick)/(float)SERVER_TICK_SPEED + Client()->GameTickTime(); - - // printf("%d %d\n", Offset, PredictedTick); - - // if (PredictedCt >= 0) - { - 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); - } + 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) + { + 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);