Game: add method for calculating zoom FOV interp

This commit is contained in:
Kawe Mazidjatari 2024-08-04 17:25:38 +02:00
parent bfdf601d0d
commit f9eb989b3b
6 changed files with 42 additions and 1 deletions

View File

@ -153,6 +153,7 @@ add_sources( SOURCE_GROUP "Player"
)
add_sources( SOURCE_GROUP "Weapon"
"server/r1/weapon_x.cpp"
"server/r1/weapon_x.h"
)
@ -219,6 +220,7 @@ add_sources( SOURCE_GROUP "Player"
)
add_sources( SOURCE_GROUP "Weapon"
"client/r1/c_weapon_x.cpp"
"client/r1/c_weapon_x.h"
)

View File

@ -0,0 +1,6 @@
#include "c_weapon_x.h"
float C_WeaponX::GetZoomFOVInterpAmount(const float curTime) const
{
return m_playerData.GetZoomFOVInterpAmount(curTime);
}

View File

@ -8,6 +8,11 @@
class C_WeaponX : C_BaseAnimating
{
public:
float GetZoomFOVInterpAmount(const float curTime) const;
inline bool HasTargetZoomFOV() { return m_playerData.GetTargetZoomFOV() == *(float*)&m_modVars[3120]; }
private:
EHANDLE m_weaponOwner;
float m_lastPrimaryAttack;
float m_nextReadyTime;

View File

@ -0,0 +1,6 @@
#include "weapon_x.h"
float CWeaponX::GetZoomFOVInterpAmount(const float curTime) const
{
return m_playerData.GetZoomFOVInterpAmount(curTime);
}

View File

@ -14,6 +14,10 @@
class CWeaponX : CBaseAnimating
{
public:
float GetZoomFOVInterpAmount(const float curTime) const;
private:
EHANDLE m_weaponOwner;
float m_lastPrimaryAttack;
float m_nextReadyTime;

View File

@ -3,6 +3,11 @@
class WeaponPlayerData
{
public:
inline float GetZoomFOVInterpAmount(const float curTime) const;
inline float GetTargetZoomFOV() const { return m_targetZoomFOV; }
private:
void* __vftable;
float m_moveSpread;
float m_spreadStartTime;
@ -70,8 +75,21 @@ class WeaponPlayerData
int m_charmAttachment;
int m_charmScriptIndex;
};
// Client's class is identical.
typedef WeaponPlayerData WeaponPlayerData_Client;
float WeaponPlayerData::GetZoomFOVInterpAmount(const float curTime) const
{
const float zoomLerpTime = m_zoomFOVLerpTime;
if (zoomLerpTime <= 0.0f)
return 1.0f;
const float endLerptime = m_zoomFOVLerpEndTime;
const float finalLerpTime = Min(Max((curTime - (endLerptime - zoomLerpTime)) / zoomLerpTime, 0.0f), 1.0f);
return (3.0f - (finalLerpTime + finalLerpTime)) * (finalLerpTime * finalLerpTime);
}
#endif // SHARED_WEAPON_PLAYERDATA_H