Made the singleplayer anim state able to apply render angles from the server

This commit is contained in:
Blixibon 2021-11-16 10:27:01 -06:00
parent 777f45a323
commit 3a3d9a45b6
4 changed files with 64 additions and 19 deletions

View File

@ -31,6 +31,9 @@ ConVar cl_npc_speedmod_outtime( "cl_npc_speedmod_outtime", "1.5", FCVAR_CLIENTDL
IMPLEMENT_CLIENTCLASS_DT(C_BaseHLPlayer, DT_HL2_Player, CHL2_Player)
RecvPropDataTable( RECVINFO_DT(m_HL2Local),0, &REFERENCE_RECV_TABLE(DT_HL2Local) ),
RecvPropBool( RECVINFO( m_fIsSprinting ) ),
#ifdef SP_ANIM_STATE
RecvPropFloat( RECVINFO( m_flAnimRenderYaw ) ),
#endif
END_RECV_TABLE()
BEGIN_PREDICTION_DATA( C_BaseHLPlayer )
@ -90,6 +93,13 @@ void C_BaseHLPlayer::OnDataChanged( DataUpdateType_t updateType )
SetNextClientThink( CLIENT_THINK_ALWAYS );
}
#ifdef SP_ANIM_STATE
if (m_flAnimRenderYaw != FLT_MAX)
{
m_angAnimRender = QAngle( 0, m_flAnimRenderYaw, 0 );
}
#endif
BaseClass::OnDataChanged( updateType );
}
@ -657,3 +667,21 @@ void C_BaseHLPlayer::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quatern
BuildFirstPersonMeathookTransformations( hdr, pos, q, cameraTransform, boneMask, boneComputed, "ValveBiped.Bip01_Head1" );
}
#ifdef SP_ANIM_STATE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const QAngle& C_BaseHLPlayer::GetRenderAngles( void )
{
if ( m_flAnimRenderYaw != FLT_MAX )
{
return m_angAnimRender;
}
else
{
return BaseClass::GetRenderAngles();
}
}
#endif

View File

@ -15,6 +15,10 @@
#include "c_baseplayer.h"
#include "c_hl2_playerlocaldata.h"
#if !defined( HL2MP ) && defined ( MAPBASE )
#include "mapbase/singleplayer_animstate.h"
#endif
class C_BaseHLPlayer : public C_BasePlayer
{
public:
@ -58,6 +62,10 @@ public:
bool IsWeaponLowered( void ) { return m_HL2Local.m_bWeaponLowered; }
#ifdef SP_ANIM_STATE
virtual const QAngle& GetRenderAngles( void );
#endif
public:
C_HL2PlayerLocalData m_HL2Local;
@ -79,6 +87,12 @@ private:
float m_flSpeedMod;
float m_flExitSpeedMod;
#ifdef SP_ANIM_STATE
// At the moment, we network the render angles since almost none of the player anim stuff is done on the client in SP.
// If any of this is ever adapted for MP, this method should be replaced with replicating/moving the anim state to the client.
float m_flAnimRenderYaw;
QAngle m_angAnimRender;
#endif
friend class CHL2GameMovement;
};

View File

@ -630,10 +630,6 @@ END_SCRIPTDESC();
CHL2_Player::CHL2_Player()
{
#ifdef SP_ANIM_STATE
m_angEyeAngles.Init();
#endif
m_nNumMissPositions = 0;
m_pPlayerAISquad = 0;
m_bSprintEnabled = true;
@ -674,6 +670,9 @@ CSuitPowerDevice SuitDeviceCustom[] =
IMPLEMENT_SERVERCLASS_ST(CHL2_Player, DT_HL2_Player)
SendPropDataTable(SENDINFO_DT(m_HL2Local), &REFERENCE_SEND_TABLE(DT_HL2Local), SendProxy_SendLocalDataTable),
SendPropBool( SENDINFO(m_fIsSprinting) ),
#ifdef SP_ANIM_STATE
SendPropFloat( SENDINFO(m_flAnimRenderYaw), 0, SPROP_NOSCALE ),
#endif
END_SEND_TABLE()
@ -1161,13 +1160,10 @@ void CHL2_Player::PostThink( void )
#ifdef SP_ANIM_STATE
if (m_pPlayerAnimState)
{
m_angEyeAngles = EyeAngles();
QAngle angEyeAngles = EyeAngles();
m_pPlayerAnimState->Update( angEyeAngles.y, angEyeAngles.x );
QAngle angles = GetLocalAngles();
angles[PITCH] = 0;
SetLocalAngles(angles);
m_pPlayerAnimState->Update( m_angEyeAngles.y, m_angEyeAngles.x );
m_flAnimRenderYaw.Set( m_pPlayerAnimState->GetRenderAngles().y );
}
#endif
}
@ -1409,8 +1405,6 @@ CStudioHdr *CHL2_Player::OnNewModel()
CStudioHdr *hdr = BaseClass::OnNewModel();
#ifdef SP_ANIM_STATE
if ( hdr && hdr->HaveSequenceForActivity(ACT_HL2MP_IDLE) && hl2_use_sp_animstate.GetBool() )
{
// Clears the animation state if we already have one.
if ( m_pPlayerAnimState != NULL )
{
@ -1418,9 +1412,15 @@ CStudioHdr *CHL2_Player::OnNewModel()
m_pPlayerAnimState = NULL;
}
if ( hdr && hdr->HaveSequenceForActivity(ACT_HL2MP_IDLE) && hl2_use_sp_animstate.GetBool() )
{
// Here we create and init the player animation state.
m_pPlayerAnimState = CreatePlayerAnimationState(this);
}
else
{
m_flAnimRenderYaw = FLT_MAX;
}
#endif
return hdr;

View File

@ -442,7 +442,10 @@ private:
#ifdef SP_ANIM_STATE
CSinglePlayerAnimState* m_pPlayerAnimState;
QAngle m_angEyeAngles;
// At the moment, we network the render angles since almost none of the player anim stuff is done on the client in SP.
// If any of this is ever adapted for MP, this method should be replaced with replicating/moving the anim state to the client.
CNetworkVar( float, m_flAnimRenderYaw );
#endif
};