MCPcopy Create free account
hub / github.com/ddnet/ddnet / RenderProjectile

Method RenderProjectile

src/game/client/components/items.cpp:22–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20#include <game/mapitems.h>
21
22void CItems::RenderProjectile(const CProjectileData *pCurrent, int ItemId)
23{
24 int CurWeapon = std::clamp(pCurrent->m_Type, 0, NUM_WEAPONS - 1);
25
26 // get positions
27 float Curvature = 0;
28 float Speed = 0;
29 const CTuningParams *pTuning = GameClient()->GetTuning(pCurrent->m_TuneZone);
30 if(CurWeapon == WEAPON_GRENADE)
31 {
32 Curvature = pTuning->m_GrenadeCurvature;
33 Speed = pTuning->m_GrenadeSpeed;
34 }
35 else if(CurWeapon == WEAPON_SHOTGUN)
36 {
37 Curvature = pTuning->m_ShotgunCurvature;
38 Speed = pTuning->m_ShotgunSpeed;
39 }
40 else if(CurWeapon == WEAPON_GUN)
41 {
42 Curvature = pTuning->m_GunCurvature;
43 Speed = pTuning->m_GunSpeed;
44 }
45
46 bool LocalPlayerInGame = false;
47
48 if(GameClient()->m_Snap.m_pLocalInfo)
49 LocalPlayerInGame = GameClient()->m_aClients[GameClient()->m_Snap.m_pLocalInfo->m_ClientId].m_Team != TEAM_SPECTATORS;
50
51 static float s_LastGameTickTime = Client()->GameTickTime(g_Config.m_ClDummy);
52 if(GameClient()->m_Snap.m_pGameInfoObj && !(GameClient()->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED))
53 s_LastGameTickTime = Client()->GameTickTime(g_Config.m_ClDummy);
54
55 bool IsOtherTeam = (pCurrent->m_ExtraInfo && pCurrent->m_Owner >= 0 && GameClient()->IsOtherTeam(pCurrent->m_Owner));
56
57 int PredictionTick = Client()->GetPredictionTick();
58
59 float Ct;
60 if(GameClient()->Predict() && GameClient()->AntiPingGrenade() && LocalPlayerInGame && !IsOtherTeam)
61 Ct = ((float)(PredictionTick - 1 - pCurrent->m_StartTick) + Client()->PredIntraGameTick(g_Config.m_ClDummy)) / (float)Client()->GameTickSpeed();
62 else
63 Ct = (Client()->PrevGameTick(g_Config.m_ClDummy) - pCurrent->m_StartTick) / (float)Client()->GameTickSpeed() + s_LastGameTickTime;
64 if(Ct < 0)
65 {
66 if(Ct > -s_LastGameTickTime / 2)
67 {
68 // Fixup the timing which might be screwed during demo playback because
69 // s_LastGameTickTime depends on the system timer, while the other part
70 // (Client()->PrevGameTick(g_Config.m_ClDummy) - pCurrent->m_StartTick) / (float)Client()->GameTickSpeed()
71 // is virtually constant (for projectiles fired on the current game tick):
72 // (x - (x+2)) / 50 = -0.04
73 //
74 // We have a strict comparison for the passed time being more than the time between ticks
75 // if(CurtickStart > m_Info.m_CurrentTime) in CDemoPlayer::Update()
76 // so on the practice the typical value of s_LastGameTickTime varies from 0.02386 to 0.03999
77 // which leads to Ct from -0.00001 to -0.01614.
78 // Round up those to 0.0 to fix missing rendering of the projectile.
79 Ct = 0;

Callers

nothing calls this directly

Calls 15

CalcPosFunction · 0.85
GraphicsFunction · 0.85
lengthFunction · 0.85
angleFunction · 0.85
GameTickTimeMethod · 0.80
IsOtherTeamMethod · 0.80
GetPredictionTickMethod · 0.80
PredictMethod · 0.80
AntiPingGrenadeMethod · 0.80
PredIntraGameTickMethod · 0.80
PrevGameTickMethod · 0.80
SmokeTrailMethod · 0.80

Tested by

no test coverage detected