Skip to content

Commit 0688fca

Browse files
committed
Update HUD using predicted client data
1 parent e760b9f commit 0688fca

File tree

17 files changed

+320
-141
lines changed

17 files changed

+320
-141
lines changed

cl_dll/ammo.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ WEAPON* gpLastSel; // Last weapon menu selection
3535

3636
client_sprite_t* GetSpriteList(client_sprite_t* pList, const char* psz, int iRes, int iCount);
3737

38+
void HUD_WeaponList(const int iId, const int iAmmoType, const int iAmmoType2);
39+
3840
WeaponsResource gWR;
3941

4042
int g_weaponselect = 0;
@@ -492,6 +494,11 @@ bool CHudAmmo::MsgFunc_AmmoX(const char* pszName, int iSize, void* pbuf)
492494
int iIndex = READ_BYTE();
493495
int iCount = READ_BYTE();
494496

497+
return Update_AmmoX(iIndex, iCount);
498+
}
499+
500+
bool CHudAmmo::Update_AmmoX(const int iIndex, const int iCount)
501+
{
495502
gWR.SetAmmo(iIndex, abs(iCount));
496503

497504
return true;
@@ -563,15 +570,20 @@ bool CHudAmmo::MsgFunc_HideWeapon(const char* pszName, int iSize, void* pbuf)
563570
//
564571
bool CHudAmmo::MsgFunc_CurWeapon(const char* pszName, int iSize, void* pbuf)
565572
{
566-
static Rect nullrc;
567-
bool fOnTarget = false;
568-
569573
BEGIN_READ(pbuf, iSize);
570574

571575
int iState = READ_BYTE();
572576
int iId = READ_CHAR();
573577
int iClip = READ_CHAR();
574578

579+
return Update_CurWeapon(iState, iId, iClip);
580+
}
581+
582+
bool CHudAmmo::Update_CurWeapon(const int iState, const int iId, const int iClip)
583+
{
584+
static Rect nullrc;
585+
bool fOnTarget = false;
586+
575587
// detect if we're also on target
576588
if (iState > 1)
577589
{
@@ -685,6 +697,9 @@ bool CHudAmmo::MsgFunc_WeaponList(const char* pszName, int iSize, void* pbuf)
685697

686698
gWR.AddWeapon(&Weapon);
687699

700+
// Tell the predicted weapons which ammo types to use
701+
HUD_WeaponList(Weapon.iId, Weapon.iAmmoType, Weapon.iAmmo2Type);
702+
688703
return true;
689704
}
690705

cl_dll/health.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,20 @@ bool CHudHealth::MsgFunc_Health(const char* pszName, int iSize, void* pbuf)
9999
{
100100
// TODO: update local health data
101101
BEGIN_READ(pbuf, iSize);
102-
int x = READ_SHORT();
102+
int iHealth = READ_SHORT();
103103

104+
return Update_Health(iHealth);
105+
}
106+
107+
bool CHudHealth::Update_Health(const int iHealth)
108+
{
104109
m_iFlags |= HUD_ACTIVE;
105110

106111
// Only update the fade if we've changed health
107-
if (x != m_iHealth)
112+
if (iHealth != m_iHealth)
108113
{
109114
m_fFade = FADE_TIME;
110-
m_iHealth = x;
115+
m_iHealth = iHealth;
111116
}
112117

113118
return true;

cl_dll/health.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class CHudHealth : public CHudBase
5252
void Reset() override;
5353
bool MsgFunc_Health(const char* pszName, int iSize, void* pbuf);
5454
bool MsgFunc_Damage(const char* pszName, int iSize, void* pbuf);
55+
bool Update_Health(const int iHealth);
5556
int m_iHealth;
5657
int m_HUD_dmg_bio;
5758
int m_HUD_cross;

cl_dll/hl/hl_baseentity.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ void CBasePlayer::ItemPreFrame() {}
271271
void CBasePlayer::ItemPostFrame() {}
272272
int CBasePlayer::AmmoInventory(int iAmmoIndex) { return -1; }
273273
int CBasePlayer::GetAmmoIndex(const char* psz) { return -1; }
274-
void CBasePlayer::SendAmmoUpdate() {}
275-
void CBasePlayer::UpdateClientData() {}
276274
bool CBasePlayer::FBecomeProne() { return true; }
277275
void CBasePlayer::BarnacleVictimBitten(entvars_t* pevBarnacle) {}
278276
void CBasePlayer::BarnacleVictimReleased() {}
@@ -321,7 +319,6 @@ void CBasePlayerItem::Holster() {}
321319
void CBasePlayerItem::AttachToPlayer(CBasePlayer* pPlayer) {}
322320
bool CBasePlayerWeapon::AddDuplicate(CBasePlayerItem* pOriginal) { return false; }
323321
void CBasePlayerWeapon::AddToPlayer(CBasePlayer* pPlayer) {}
324-
bool CBasePlayerWeapon::UpdateClientData(CBasePlayer* pPlayer) { return false; }
325322
bool CBasePlayerWeapon::IsUseable() { return true; }
326323
int CBasePlayerWeapon::PrimaryAmmoIndex() { return m_iPrimaryAmmoType; }
327324
int CBasePlayerWeapon::SecondaryAmmoIndex() { return m_iSecondaryAmmoType; }

0 commit comments

Comments
 (0)