Skip to content

Commit e9908d2

Browse files
committed
Add support for Mapbase anim state to HL2MP
1 parent b09d162 commit e9908d2

File tree

11 files changed

+140
-7
lines changed

11 files changed

+140
-7
lines changed

src/game/client/hl2/c_basehlplayer.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,30 @@ void C_BaseHLPlayer::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quatern
713713

714714

715715
#ifdef SP_ANIM_STATE
716+
// Set the activity based on an event or current state
717+
void C_BaseHLPlayer::SetAnimation( PLAYER_ANIM playerAnim )
718+
{
719+
#ifdef MAPBASE_MP
720+
if (!m_pPlayerAnimState)
721+
{
722+
BaseClass::SetAnimation( playerAnim );
723+
return;
724+
}
725+
726+
m_pPlayerAnimState->SetPlayerAnimation( playerAnim );
727+
#endif
728+
}
729+
730+
void C_BaseHLPlayer::AddAnimStateLayer( int iSequence, float flBlendIn, float flBlendOut, float flPlaybackRate, bool bHoldAtEnd, bool bOnlyWhenStill )
731+
{
732+
#ifdef MAPBASE_MP
733+
if (!m_pPlayerAnimState)
734+
return;
735+
736+
m_pPlayerAnimState->AddMiscSequence( iSequence, flBlendIn, flBlendOut, flPlaybackRate, bHoldAtEnd, bOnlyWhenStill );
737+
#endif
738+
}
739+
716740
//-----------------------------------------------------------------------------
717741
// Purpose:
718742
//-----------------------------------------------------------------------------
@@ -737,7 +761,7 @@ const Vector &C_BaseHLPlayer::GetRenderOrigin()
737761
const QAngle& C_BaseHLPlayer::GetRenderAngles( void )
738762
{
739763
#ifdef MAPBASE_MP
740-
if ( m_pPlayerAnimState )
764+
if ( m_pPlayerAnimState && !IsRagdoll() )
741765
{
742766
return m_pPlayerAnimState->GetRenderAngles();
743767
}

src/game/client/hl2/c_basehlplayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class C_BaseHLPlayer : public C_BasePlayer
7171
#endif
7272

7373
#ifdef SP_ANIM_STATE
74+
void SetAnimation( PLAYER_ANIM playerAnim );
75+
void AddAnimStateLayer( int iSequence, float flBlendIn, float flBlendOut, float flPlaybackRate, bool bHoldAtEnd, bool bOnlyWhenStill );
76+
7477
virtual const Vector& GetRenderOrigin();
7578
virtual const QAngle& GetRenderAngles( void );
7679
virtual CStudioHdr *OnNewModel();

src/game/client/hl2mp/c_hl2mp_player.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ void SpawnBlood (Vector vecSpot, const Vector &vecDir, int bloodColor, float flD
100100
#endif
101101
CSuitPowerDevice SuitDeviceBreather( bits_SUIT_DEVICE_BREATHER, 6.7f ); // 100 units in 15 seconds (plus three padded seconds)
102102

103-
C_HL2MP_Player::C_HL2MP_Player() : m_PlayerAnimState( this ), m_iv_angEyeAngles( "C_HL2MP_Player::m_iv_angEyeAngles" )
103+
C_HL2MP_Player::C_HL2MP_Player() :
104+
#ifndef SP_ANIM_STATE
105+
m_PlayerAnimState( this ),
106+
#endif
107+
m_iv_angEyeAngles( "C_HL2MP_Player::m_iv_angEyeAngles" )
104108
{
105109
m_iIDEntIndex = 0;
106110
m_iSpawnInterpCounterCache = 0;
@@ -582,7 +586,9 @@ void C_HL2MP_Player::AddEntity( void )
582586

583587
SetLocalAngles( vTempAngles );
584588

589+
#ifndef SP_ANIM_STATE
585590
m_PlayerAnimState.Update();
591+
#endif
586592

587593
// Zero out model pitch, blending takes care of all of it.
588594
SetLocalAnglesDim( X_INDEX, 0 );
@@ -671,6 +677,7 @@ ShadowType_t C_HL2MP_Player::ShadowCastType( void )
671677
}
672678

673679

680+
#ifndef SP_ANIM_STATE
674681
const QAngle& C_HL2MP_Player::GetRenderAngles()
675682
{
676683
if ( IsRagdoll() )
@@ -682,6 +689,7 @@ const QAngle& C_HL2MP_Player::GetRenderAngles()
682689
return m_PlayerAnimState.GetRenderAngles();
683690
}
684691
}
692+
#endif
685693

686694
bool C_HL2MP_Player::ShouldDraw( void )
687695
{

src/game/client/hl2mp/c_hl2mp_player.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ class C_HL2MP_Player : public C_BaseHLPlayer
6767
// Should this object cast shadows?
6868
virtual ShadowType_t ShadowCastType( void );
6969
virtual C_BaseAnimating *BecomeRagdollOnClient();
70+
#ifndef SP_ANIM_STATE
7071
virtual const QAngle& GetRenderAngles();
72+
#endif
7173
virtual bool ShouldDraw( void );
7274
virtual void OnDataChanged( DataUpdateType_t type );
7375
virtual float GetFOV( void );
@@ -118,13 +120,19 @@ class C_HL2MP_Player : public C_BaseHLPlayer
118120
void StopWalking( void );
119121
bool IsWalking( void ) { return m_fIsWalking; }
120122

123+
#ifdef SP_ANIM_STATE
124+
Activity Weapon_TranslateActivity( Activity baseAct, bool *pRequired = NULL );
125+
#endif
126+
121127
virtual void PostThink( void );
122128

123129
private:
124130

125131
C_HL2MP_Player( const C_HL2MP_Player & );
126132

133+
#ifndef SP_ANIM_STATE
127134
CPlayerAnimState m_PlayerAnimState;
135+
#endif
128136

129137
QAngle m_angEyeAngles;
130138

src/game/client/movehelper_client.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ bool CMoveHelperClient::PlayerFallingDamage(void)
310310
void CMoveHelperClient::PlayerSetAnimation( PLAYER_ANIM eAnim )
311311
{
312312
// Do nothing on the client. Animations are set on the server.
313+
#ifdef MAPBASE_MP
314+
// The Mapbase anim state uses clientside anims as well
315+
if ( m_pHost )
316+
m_pHost->SetAnimation( eAnim );
317+
#endif
313318
}
314319

315320
bool CMoveHelperClient::IsWorldEntity( const CBaseHandle &handle )

src/game/server/hl2/hl2_player.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ void CHL2_Player::SpawnedAtPoint( CBaseEntity *pSpawnPoint )
14801480

14811481
//-----------------------------------------------------------------------------
14821482

1483+
#ifndef MAPBASE_MP // See hl2mp_player_shared.cpp
14831484
ConVar player_use_anim_enabled( "player_use_anim_enabled", "1" );
14841485
ConVar player_use_anim_heavy_mass( "player_use_anim_heavy_mass", "20.0" );
14851486

@@ -1529,6 +1530,7 @@ Activity CHL2_Player::Weapon_TranslateActivity( Activity baseAct, bool *pRequire
15291530

15301531
return weaponTranslation;
15311532
}
1533+
#endif
15321534

15331535
#ifdef SP_ANIM_STATE
15341536
// Set the activity based on an event or current state

src/game/server/hl2/hl2_player.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ class CHL2_Player : public CBasePlayer
132132
// For the logic_playerproxy output
133133
void SpawnedAtPoint( CBaseEntity *pSpawnPoint );
134134

135+
#ifndef MAPBASE_MP
135136
Activity Weapon_TranslateActivity( Activity baseAct, bool *pRequired = NULL );
137+
#endif
136138

137139
#ifdef SP_ANIM_STATE
138140
void SetAnimation( PLAYER_ANIM playerAnim );

src/game/server/hl2mp/hl2mp_player.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ const char *g_ppszRandomCombineModels[] =
143143

144144
#pragma warning( disable : 4355 )
145145

146-
CHL2MP_Player::CHL2MP_Player() : m_PlayerAnimState( this )
146+
CHL2MP_Player::CHL2MP_Player()
147+
#ifndef SP_ANIM_STATE
148+
: m_PlayerAnimState( this )
149+
#endif
147150
{
148151
m_angEyeAngles.Init();
149152

@@ -643,7 +646,9 @@ void CHL2MP_Player::PostThink( void )
643646
SetCollisionBounds( VEC_CROUCH_TRACE_MIN, VEC_CROUCH_TRACE_MAX );
644647
}
645648

649+
#ifndef SP_ANIM_STATE
646650
m_PlayerAnimState.Update();
651+
#endif
647652

648653
// Store the eye angles pitch so the client can compute its animation state correctly.
649654
m_angEyeAngles = EyeAngles();
@@ -762,6 +767,11 @@ extern ConVar hl2_normspeed;
762767
// Set the activity based on an event or current state
763768
void CHL2MP_Player::SetAnimation( PLAYER_ANIM playerAnim )
764769
{
770+
#ifdef SP_ANIM_STATE
771+
BaseClass::SetAnimation( playerAnim );
772+
return;
773+
#endif
774+
765775
int animDesired;
766776

767777
float speed;
@@ -1332,9 +1342,14 @@ void CHL2MP_Player::Event_Killed( const CTakeDamageInfo &info )
13321342

13331343
SetNumAnimOverlays( 0 );
13341344

1335-
// Note: since we're dead, it won't draw us on the client, but we don't set EF_NODRAW
1336-
// because we still want to transmit to the clients in our PVS.
1337-
CreateRagdollEntity();
1345+
#ifdef MAPBASE_MP
1346+
if ( !m_bForceServerRagdoll )
1347+
#endif
1348+
{
1349+
// Note: since we're dead, it won't draw us on the client, but we don't set EF_NODRAW
1350+
// because we still want to transmit to the clients in our PVS.
1351+
CreateRagdollEntity();
1352+
}
13381353

13391354
DetonateTripmines();
13401355

src/game/server/hl2mp/hl2mp_player.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ class CHL2MP_Player : public CHL2_Player
9999
void SetPlayerModel( void );
100100
void SetPlayerTeamModel( void );
101101
Activity TranslateTeamActivity( Activity ActToTranslate );
102+
103+
#ifdef SP_ANIM_STATE
104+
Activity Weapon_TranslateActivity( Activity baseAct, bool *pRequired = NULL );
105+
#endif
102106

103107
float GetNextModelChangeTime( void ) { return m_flNextModelChangeTime; }
104108
float GetNextTeamChangeTime( void ) { return m_flNextTeamChangeTime; }
@@ -159,7 +163,9 @@ class CHL2MP_Player : public CHL2_Player
159163
private:
160164

161165
CNetworkQAngle( m_angEyeAngles );
166+
#ifndef SP_ANIM_STATE
162167
CPlayerAnimState m_PlayerAnimState;
168+
#endif
163169

164170
int m_iLastWeaponFireUsercmd;
165171
int m_iModelType;

src/game/shared/hl2mp/hl2mp_player_shared.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#else
1515
#include "hl2mp_player.h"
1616
#endif
17+
#ifdef MAPBASE
18+
#include "weapon_physcannon.h"
19+
#include "hl2mp_gamerules.h"
20+
#endif
1721

1822
#include "engine/IEngineSound.h"
1923
#include "SoundEmitterSystem/isoundemittersystembase.h"
@@ -126,7 +130,57 @@ void CHL2MP_Player::PlayStepSound( Vector &vecOrigin, surfacedata_t *psurface, f
126130
// ANIMATION CODE
127131
//==========================
128132

133+
#ifdef SP_ANIM_STATE
134+
ConVar player_use_anim_enabled( "player_use_anim_enabled", "1", FCVAR_REPLICATED );
135+
136+
const float PLAYER_USE_ANIM_HEAVY_MASS = 20.0f;
137+
138+
//-----------------------------------------------------------------------------
139+
// Purpose:
140+
//-----------------------------------------------------------------------------
141+
Activity CHL2MP_Player::Weapon_TranslateActivity( Activity baseAct, bool *pRequired )
142+
{
143+
Activity weaponTranslation = BaseClass::Weapon_TranslateActivity( baseAct, pRequired );
144+
145+
#if EXPANDED_HL2DM_ACTIVITIES
146+
// +USE activities
147+
if ( GetUseEntity() && player_use_anim_enabled.GetBool())
148+
{
149+
CBaseEntity* pHeldEnt = GetPlayerHeldEntity( this );
150+
float flMass = pHeldEnt ?
151+
(pHeldEnt->VPhysicsGetObject() ? PlayerPickupGetHeldObjectMass( GetUseEntity(), pHeldEnt->VPhysicsGetObject() ) : PLAYER_USE_ANIM_HEAVY_MASS) :
152+
(GetUseEntity()->VPhysicsGetObject() ? GetUseEntity()->VPhysicsGetObject()->GetMass() : PLAYER_USE_ANIM_HEAVY_MASS);
153+
if ( flMass >= PLAYER_USE_ANIM_HEAVY_MASS)
154+
{
155+
// Heavy versions
156+
switch (baseAct)
157+
{
158+
case ACT_HL2MP_IDLE: weaponTranslation = ACT_HL2MP_IDLE_USE_HEAVY; break;
159+
case ACT_HL2MP_RUN: weaponTranslation = ACT_HL2MP_RUN_USE_HEAVY; break;
160+
case ACT_HL2MP_WALK: weaponTranslation = ACT_HL2MP_WALK_USE_HEAVY; break;
161+
case ACT_HL2MP_IDLE_CROUCH: weaponTranslation = ACT_HL2MP_IDLE_CROUCH_USE_HEAVY; break;
162+
case ACT_HL2MP_WALK_CROUCH: weaponTranslation = ACT_HL2MP_WALK_CROUCH_USE_HEAVY; break;
163+
case ACT_HL2MP_JUMP: weaponTranslation = ACT_HL2MP_JUMP_USE_HEAVY; break;
164+
}
165+
}
166+
else
167+
{
168+
switch (baseAct)
169+
{
170+
case ACT_HL2MP_IDLE: weaponTranslation = ACT_HL2MP_IDLE_USE; break;
171+
case ACT_HL2MP_RUN: weaponTranslation = ACT_HL2MP_RUN_USE; break;
172+
case ACT_HL2MP_WALK: weaponTranslation = ACT_HL2MP_WALK_USE; break;
173+
case ACT_HL2MP_IDLE_CROUCH: weaponTranslation = ACT_HL2MP_IDLE_CROUCH_USE; break;
174+
case ACT_HL2MP_WALK_CROUCH: weaponTranslation = ACT_HL2MP_WALK_CROUCH_USE; break;
175+
case ACT_HL2MP_JUMP: weaponTranslation = ACT_HL2MP_JUMP_USE; break;
176+
}
177+
}
178+
}
179+
#endif
129180

181+
return weaponTranslation;
182+
}
183+
#else
130184
// Below this many degrees, slow down turning rate linearly
131185
#define FADE_TURN_DEGREES 45.0f
132186
// After this, need to start turning feet
@@ -574,4 +628,5 @@ void CPlayerAnimState::GetOuterAbsVelocity( Vector& vel )
574628
#else
575629
vel = GetOuter()->GetAbsVelocity();
576630
#endif
577-
}
631+
}
632+
#endif

0 commit comments

Comments
 (0)