mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Fix gun prediction (by p)
This commit is contained in:
parent
5fa57ed5ab
commit
ddbb9633a8
|
@ -100,49 +100,28 @@ 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);
|
||||
static int Average_Offset = -1;
|
||||
static float Offset_Count = 0;
|
||||
static float Offset_Sum = 0;
|
||||
|
||||
|
||||
// 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)
|
||||
{
|
||||
// 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)
|
||||
if (Average_Offset == -1)
|
||||
{
|
||||
int Offset = Client()->PredGameTick() - Client()->GameTick();
|
||||
m_pClient->m_Prediction_Offset_Summ += Offset;
|
||||
m_pClient->m_Prediction_Offset_Count++;
|
||||
Offset_Sum += Offset;
|
||||
Offset_Count++;
|
||||
|
||||
if (m_pClient->m_Prediction_Offset_Count >= 100)
|
||||
if (Offset_Count >= 100)
|
||||
{
|
||||
m_pClient->m_Average_Prediction_Offset =
|
||||
round((float)m_pClient->m_Prediction_Offset_Summ / m_pClient->m_Prediction_Offset_Count);
|
||||
Average_Offset = round(Offset_Sum / 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;
|
||||
int PredictedTick = Client()->PrevGameTick() + Average_Offset;
|
||||
float PredictedCt = (PredictedTick - pCurrent->m_StartTick)/(float)SERVER_TICK_SPEED + Client()->GameTickTime();
|
||||
|
||||
// printf("%d %d\n", Offset, PredictedTick);
|
||||
|
||||
// if (PredictedCt >= 0)
|
||||
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);
|
||||
|
@ -153,8 +132,6 @@ void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID)
|
|||
Graphics()->QuadsDraw(&QuadItem, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
Graphics()->QuadsDraw(&QuadItem, 1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue