client side weapon reload prediction update

This commit is contained in:
pierow 2021-02-24 15:14:31 -05:00
parent aa5c09d4ff
commit 96f1cf2f28
2 changed files with 38 additions and 32 deletions

View file

@ -473,28 +473,34 @@ Handles weapon firing, reloading, etc.
*/ */
void CBasePlayerWeapon::ItemPostFrame( void ) void CBasePlayerWeapon::ItemPostFrame( void )
{ {
// Get item info necessary for various checks here. Adapted from Solokiller's halflife-updated. HL SDK has broken checks that always return false.
ItemInfo ii;
memset(&ii, 0, sizeof(ii));
GetItemInfo(&ii);
// Hack initialization // Hack initialization
if (this->m_flLastAnimationPlayed >= 3.0f * BALANCE_VAR(kLeapROF) + gpGlobals->time) if (this->m_flLastAnimationPlayed >= 3.0f * BALANCE_VAR(kLeapROF) + gpGlobals->time)
this->m_flLastAnimationPlayed = 0.0f; this->m_flLastAnimationPlayed = 0.0f;
// if ((m_fInReload) && (m_pPlayer->m_flNextAttack <= 0.0)) if ((m_fInReload) && (m_pPlayer->m_flNextAttack <= 0.0))
// { {
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Put code in here to predict reloads (ie, have the ammo on screen update before we get a response) // //// Put code in here to predict reloads (ie, have the ammo on screen update before we get a response) //
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
////#if 0 // FIXME, need ammo on client to make this work right #if 1
//// // complete the reload. // complete the reload.
//// int j = min( iMaxClip() - m_iClip, m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]);
//// int j = min(ii.iMaxClip - m_iClip, m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]);
//// // Add them to the clip
//// m_iClip += j; // Add them to the clip
//// m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= j; m_iClip += j;
//// ALERT(at_console, "hlweappredictreload\n"); m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= j;
////#else //ALERT(at_console, "hlweap predict reload\n");
//// m_iClip += 10; #else
////#endif m_iClip += 10;
// m_fInReload = FALSE; #endif
// } m_fInReload = FALSE;
}
// Properly propagate the end animation // Properly propagate the end animation
if (this->PrevAttack2Status == true && !(m_pPlayer->pev->button & IN_ATTACK2)) if (this->PrevAttack2Status == true && !(m_pPlayer->pev->button & IN_ATTACK2))
@ -528,8 +534,8 @@ void CBasePlayerWeapon::ItemPostFrame( void )
} }
else if (GetCanUseWeapon() && (m_flNextPrimaryAttack <= 0.0)) else if (GetCanUseWeapon() && (m_flNextPrimaryAttack <= 0.0))
{ {
if ( (m_iClip == 0 && pszAmmo1()) || if ( (m_iClip == 0 && ii.pszAmmo1) ||
(iMaxClip() == -1 && !m_pPlayer->m_rgAmmo[PrimaryAmmoIndex()] ) ) (ii.iMaxClip == -1 && !m_pPlayer->m_rgAmmo[PrimaryAmmoIndex()] ) )
{ {
m_fFireOnEmpty = TRUE; m_fFireOnEmpty = TRUE;
} }
@ -650,7 +656,7 @@ void CBasePlayerWeapon::ItemPostFrame( void )
// PrimaryAttack(); // PrimaryAttack();
// } // }
} }
else if ( m_pPlayer->pev->button & IN_RELOAD && iMaxClip() != WEAPON_NOCLIP && !m_fInReload ) else if ( m_pPlayer->pev->button & IN_RELOAD && ii.iMaxClip != WEAPON_NOCLIP && !m_fInReload )
{ {
if (GetCanUseWeapon()) if (GetCanUseWeapon())
{ {
@ -669,11 +675,10 @@ void CBasePlayerWeapon::ItemPostFrame( void )
m_fFireOnEmpty = FALSE; m_fFireOnEmpty = FALSE;
// weapon is useable. Reload if empty and weapon has waited as long as it has to after firing // weapon is useable. Reload if empty and weapon has waited as long as it has to after firing
if ( m_iClip == 0 && !(iFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < 0.0 ) if (m_iClip == 0 && !(ii.iFlags & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < 0.0)
{ {
// << CGC >> Only reload if we have more ammo to reload with // << CGC >> Only reload if we have more ammo to reload with
// Client doesn't know autoreload flag and knife ammo is infinite with networked ammo. Check if knife to prevent reload. if(m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0)
if(m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0 && !(gHUD.GetCurrentWeaponID() == AVH_WEAPON_KNIFE))
{ {
Reload(); Reload();
return; return;

View file

@ -266,14 +266,14 @@ BOOL AvHBasePlayerWeapon::DefaultReload( int iClipSize, int iAnim, float fDelay,
return TRUE; return TRUE;
// : // :
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iId == AVH_WEAPON_KNIFE) if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
return FALSE; return FALSE;
// Don't reload while we're resupplying // Don't reload while we're resupplying
if(this->mTimeOfLastResupply > 0) // if(this->mTimeOfLastResupply > 0)
{ // {
return FALSE; // return FALSE;
} // }
int j = min(iClipSize - m_iClip, m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]); int j = min(iClipSize - m_iClip, m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]);
@ -283,14 +283,15 @@ BOOL AvHBasePlayerWeapon::DefaultReload( int iClipSize, int iAnim, float fDelay,
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + fDelay; m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + fDelay;
//!!UNDONE -- reload sound goes here !!! //!!UNDONE -- reload sound goes here !!!
//SendWeaponAnim( iAnim, UseDecrement() ? 1 : 0 ); // 2021 Ammo networking. Uncommented to not send animations to the client that initiated the reload. This is HL SDK code.
SendWeaponAnim( iAnim, UseDecrement() ? 1 : 0 );
//// 2021 Ammo networking. Commented below - client was getting sent extra reload animations causing visual stutter. //// 2021 Ammo networking. Commented below - client was getting sent extra reload animations causing visual stutter.
//this->SendWeaponAnim(iAnim); //this->SendWeaponAnim(iAnim);
// Send reload to all players. Reloads are initiated server-side, so send down to local client as well
//// 2021 Ammo networking. Commented below - client was getting sent extra reload animations causing visual stutter. //// 2021 Ammo networking. Commented below - client was getting sent extra reload animations causing visual stutter.
// Send reload to all players. Reloads are initiated server-side, so send down to local client as well
//this->m_pPlayer->pev->weaponanim = iAnim; //this->m_pPlayer->pev->weaponanim = iAnim;
this->PlaybackEvent(this->mWeaponAnimationEvent, iAnim, FEV_RELIABLE); //this->PlaybackEvent(this->mWeaponAnimationEvent, iAnim, FEV_RELIABLE);
//ALERT(at_console, "defaultreload nextattack:%g\n", m_pPlayer->m_flNextAttack); //ALERT(at_console, "defaultreload nextattack:%g\n", m_pPlayer->m_flNextAttack);
// Player model reload animation // Player model reload animation