Skip to content

Commit

Permalink
player movement bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
luttje committed Aug 19, 2024
1 parent 2b53e7a commit 4406b09
Show file tree
Hide file tree
Showing 19 changed files with 1,211 additions and 951 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@ PLAYER_META.AnimSetGestureWeight = PLAYER_META.AnimationSetGestureWeight
PLAYER_META.GetName = PLAYER_META.GetPlayerName
PLAYER_META.Name = PLAYER_META.GetPlayerName
PLAYER_META.Nick = PLAYER_META.GetPlayerName
PLAYER_META.SetSlowWalkSpeed = PLAYER_META.SetWalkSpeed
PLAYER_META.GetSlowWalkSpeed = PLAYER_META.GetWalkSpeed
PLAYER_META.SetWalkSpeed = PLAYER_META.SetNormalSpeed
PLAYER_META.GetWalkSpeed = PLAYER_META.GetNormalSpeed
PLAYER_META.GetCrouchedWalkSpeed = PLAYER_META.GetCrouchWalkFraction
PLAYER_META.SetCrouchedWalkSpeed = PLAYER_META.SetCrouchWalkFraction

function PLAYER_META:GetInfo(consoleVariableName)
return engine.GetClientConsoleVariableValue(self, consoleVariableName)
Expand Down
16 changes: 13 additions & 3 deletions src/game/client/c_baseplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,13 @@ RecvPropDataTable( "localdata", 0, 0, &REFERENCE_RECV_TABLE( DT_LocalPlayerExclu
RecvPropInt( RECVINFO( m_iBonusProgress ) ),
RecvPropInt( RECVINFO( m_iBonusChallenge ) ),

RecvPropFloat( RECVINFO( m_flMaxspeed ) ), RecvPropInt( RECVINFO( m_fFlags ) ),
RecvPropFloat( RECVINFO( m_flMaxspeed ) ),
RecvPropFloat( RECVINFO( m_flWalkSpeed ) ),
RecvPropFloat( RECVINFO( m_flNormalSpeed ) ),
RecvPropFloat( RECVINFO( m_flRunSpeed ) ),
RecvPropFloat( RECVINFO( m_flCrouchWalkFraction ) ),

RecvPropInt( RECVINFO( m_fFlags ) ),

RecvPropInt( RECVINFO( m_iObserverMode ), 0, RecvProxy_ObserverMode ),
RecvPropEHandle( RECVINFO( m_hObserverTarget ), RecvProxy_ObserverTarget ),
Expand Down Expand Up @@ -411,9 +417,9 @@ RecvPropDataTable( "localdata", 0, 0, &REFERENCE_RECV_TABLE( DT_LocalPlayerExclu

END_PREDICTION_DATA()

BEGIN_PREDICTION_DATA( C_BasePlayer )
BEGIN_PREDICTION_DATA( C_BasePlayer )

DEFINE_PRED_TYPEDESCRIPTION( m_Local, CPlayerLocalData ),
DEFINE_PRED_TYPEDESCRIPTION( m_Local, CPlayerLocalData ),
DEFINE_PRED_TYPEDESCRIPTION( pl, CPlayerState ),

DEFINE_PRED_FIELD( m_iFOV, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
Expand All @@ -423,6 +429,10 @@ RecvPropDataTable( "localdata", 0, 0, &REFERENCE_RECV_TABLE( DT_LocalPlayerExclu

DEFINE_PRED_FIELD( m_hVehicle, FIELD_EHANDLE, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD_TOL( m_flMaxspeed, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ),
DEFINE_PRED_FIELD_TOL( m_flWalkSpeed, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ),
DEFINE_PRED_FIELD_TOL( m_flNormalSpeed, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ),
DEFINE_PRED_FIELD_TOL( m_flRunSpeed, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ),
DEFINE_PRED_FIELD_TOL( m_flCrouchWalkFraction, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ),
DEFINE_PRED_FIELD( m_iHealth, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_iBonusProgress, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_iBonusChallenge, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
Expand Down
43 changes: 41 additions & 2 deletions src/game/client/c_baseplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,44 @@ class C_BasePlayer : public C_BaseCombatCharacter, public CGameEventListener
{
m_flMaxspeed = flMaxSpeed;
}
float MaxSpeed() const
float GetMaxSpeed() const
{
return m_flMaxspeed;
}

void SetWalkSpeed( float flSpeed )
{
m_flWalkSpeed = flSpeed;
}
float GetWalkSpeed( void )
{
return m_flWalkSpeed;
}
void SetNormalSpeed( float flSpeed )
{
m_flNormalSpeed = flSpeed;
}
float GetNormalSpeed( void )
{
return m_flNormalSpeed;
}
void SetRunSpeed( float flSpeed )
{
m_flRunSpeed = flSpeed;
}
float GetRunSpeed( void )
{
return m_flRunSpeed;
}
void SetCrouchWalkFraction( float flSpeed )
{
m_flCrouchWalkFraction = flSpeed;
}
float GetCrouchWalkFraction( void )
{
return m_flCrouchWalkFraction;
}

// Should this object cast shadows?
virtual ShadowType_t ShadowCastType()
{
Expand Down Expand Up @@ -623,7 +656,13 @@ class C_BasePlayer : public C_BaseCombatCharacter, public CGameEventListener
EHANDLE m_hOldVehicle;
EHANDLE m_hUseEntity;

float m_flMaxspeed;
float m_flMaxspeed; // Current maximum speed

// Values to set m_flMaxspeed to when walking slowly, normally, and running.
float m_flWalkSpeed;
float m_flNormalSpeed;
float m_flRunSpeed;
float m_flCrouchWalkFraction;

int m_iBonusProgress;
int m_iBonusChallenge;
Expand Down
30 changes: 25 additions & 5 deletions src/game/client/experiment/c_experiment_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ RecvPropVector( RECVINFO_NAME( m_vecNetworkOrigin, m_vecOrigin ) ),
DEFINE_PRED_FIELD( m_nNewSequenceParity, FIELD_INTEGER, FTYPEDESC_OVERRIDE | FTYPEDESC_PRIVATE | FTYPEDESC_NOERRORCHECK ),
END_PREDICTION_DATA()

#define HL2_WALK_SPEED 150
#define HL2_NORM_SPEED 190
#define HL2_SPRINT_SPEED 320

static ConVar
cl_playermodel( "cl_playermodel", "none", FCVAR_USERINFO | FCVAR_ARCHIVE | FCVAR_SERVER_CAN_EXECUTE, "Default Player Model" );
static ConVar cl_defaultweapon( "cl_defaultweapon", "weapon_physcannon", FCVAR_USERINFO | FCVAR_ARCHIVE, "Default Spawn Weapon" );
Expand Down Expand Up @@ -662,15 +658,27 @@ void C_Experiment_Player::StartSprinting( void )
filter.UsePredictionRules();
EmitSound( filter, entindex(), "HL2Player.SprintStart" );

#if defined( EXPERIMENT_SOURCE )
SetMaxSpeed( GetRunSpeed() );
#elif defined( HL2MP )
SetMaxSpeed( HL2_SPRINT_SPEED );
#else
SetMaxSpeed( hl2_sprintspeed.GetFloat() );
#endif
m_fIsSprinting = true;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void C_Experiment_Player::StopSprinting( void )
{
#if defined( EXPERIMENT_SOURCE )
SetMaxSpeed( GetNormalSpeed() );
#elif defined( HL2MP )
SetMaxSpeed( HL2_NORM_SPEED );
#else
SetMaxSpeed( hl2_normspeed.GetFloat() );
#endif
m_fIsSprinting = false;
}

Expand Down Expand Up @@ -728,15 +736,27 @@ void C_Experiment_Player::HandleSpeedChanges( void )
//-----------------------------------------------------------------------------
void C_Experiment_Player::StartWalking( void )
{
#if defined( EXPERIMENT_SOURCE )
SetMaxSpeed( GetWalkSpeed() );
#elif defined( HL2MP )
SetMaxSpeed( HL2_WALK_SPEED );
#else
SetMaxSpeed( hl2_walkspeed.GetFloat() );
#endif
m_fIsWalking = true;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void C_Experiment_Player::StopWalking( void )
{
SetMaxSpeed( HL2_NORM_SPEED );
#if defined( EXPERIMENT_SOURCE )
SetMaxSpeed( GetRunSpeed() );
#elif defined( HL2MP )
SetMaxSpeed( HL2_SPRINT_SPEED );
#else
SetMaxSpeed( hl2_sprintspeed.GetFloat() );
#endif
m_fIsWalking = false;
}

Expand Down
4 changes: 1 addition & 3 deletions src/game/server/experiment/experiment_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ bool CExperiment_Player::WantsLagCompensationOnEntity(
// get max distance player could have moved within max lag compensation
// time, multiply by 1.5 to to avoid "dead zones" (sqrt(2) would be the
// exact value)
float maxDistance = 1.5 * pPlayer->MaxSpeed() * sv_maxunlag.GetFloat();
float maxDistance = 1.5 * pPlayer->GetMaxSpeed() * sv_maxunlag.GetFloat();

// If the player is within this distance, lag compensate them in case
// they're running past us.
Expand Down Expand Up @@ -788,8 +788,6 @@ Activity CExperiment_Player::TranslateTeamActivity( Activity ActToTranslate )
return ActToTranslate;
}

extern ConVar hl2_normspeed;

extern int gEvilImpulse101;
//-----------------------------------------------------------------------------
// Purpose: Player reacts to bumping a weapon.
Expand Down
41 changes: 31 additions & 10 deletions src/game/server/hl2/hl2_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ ConVar hl2_sprintspeed( "hl2_sprintspeed", "320" );

ConVar hl2_darkness_flashlight_factor( "hl2_darkness_flashlight_factor", "1" );

#if defined( HL2MP ) || defined( EXPERIMENT_SOURCE )
#define HL2_WALK_SPEED 150
#define HL2_NORM_SPEED 190
#define HL2_SPRINT_SPEED 320
#else
#define HL2_WALK_SPEED hl2_walkspeed.GetFloat()
#define HL2_NORM_SPEED hl2_normspeed.GetFloat()
#define HL2_SPRINT_SPEED hl2_sprintspeed.GetFloat()
#endif

ConVar player_showpredictedposition( "player_showpredictedposition", "0" );
ConVar player_showpredictedposition_timestep( "player_showpredictedposition_timestep", "1.0" );

Expand Down Expand Up @@ -1207,7 +1197,14 @@ void CHL2_Player::StartSprinting( void )
filter.UsePredictionRules();
EmitSound( filter, entindex(), "HL2Player.SprintStart" );

#if defined( EXPERIMENT_SOURCE )
SetMaxSpeed( GetRunSpeed() );
#elif defined( HL2MP )
SetMaxSpeed( HL2_SPRINT_SPEED );
#else
SetMaxSpeed( hl2_sprintspeed.GetFloat() );
#endif

m_fIsSprinting = true;
}

Expand All @@ -1222,11 +1219,23 @@ void CHL2_Player::StopSprinting( void )

if ( IsSuitEquipped() )
{
#if defined( EXPERIMENT_SOURCE )
SetMaxSpeed( GetNormalSpeed() );
#elif defined( HL2MP )
SetMaxSpeed( HL2_NORM_SPEED );
#else
SetMaxSpeed( hl2_normspeed.GetFloat() );
#endif
}
else
{
#if defined( EXPERIMENT_SOURCE )
SetMaxSpeed( GetWalkSpeed() );
#elif defined( HL2MP )
SetMaxSpeed( HL2_WALK_SPEED );
#else
SetMaxSpeed( hl2_walkspeed.GetFloat() );
#endif
}

m_fIsSprinting = false;
Expand Down Expand Up @@ -1256,15 +1265,27 @@ void CHL2_Player::EnableSprint( bool bEnable )
//-----------------------------------------------------------------------------
void CHL2_Player::StartWalking( void )
{
#if defined( EXPERIMENT_SOURCE )
SetMaxSpeed( GetWalkSpeed() );
#elif defined( HL2MP )
SetMaxSpeed( HL2_WALK_SPEED );
#else
SetMaxSpeed( hl2_walkspeed.GetFloat() );
#endif
m_fIsWalking = true;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CHL2_Player::StopWalking( void )
{
#if defined( EXPERIMENT_SOURCE )
SetMaxSpeed( GetNormalSpeed() );
#elif defined( HL2MP )
SetMaxSpeed( HL2_NORM_SPEED );
#else
SetMaxSpeed( hl2_normspeed.GetFloat() );
#endif
m_fIsWalking = false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/server/physics_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@ void CBaseEntity::PhysicsStep()
{
float maxAngular;
VPhysicsGetObject()->GetShadowController()->GetMaxSpeed( NULL, &maxAngular );
VPhysicsGetObject()->GetShadowController()->MaxSpeed( pUpdate->savedShadowControllerMaxSpeed, maxAngular );
VPhysicsGetObject()->GetShadowController()->MaxSpeed( pUpdate->savedShadowControllerMaxSpeed, maxAngular );
DestroyDataObject(VPHYSICSUPDATEAI);
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/game/server/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ DEFINE_FIELD( v_angle, FIELD_VECTOR ),
DEFINE_AUTO_ARRAY( m_hViewModel, FIELD_EHANDLE ),

DEFINE_FIELD( m_flMaxspeed, FIELD_FLOAT ),
DEFINE_FIELD( m_flWalkSpeed, FIELD_FLOAT ),
DEFINE_FIELD( m_flNormalSpeed, FIELD_FLOAT ),
DEFINE_FIELD( m_flRunSpeed, FIELD_FLOAT ),
DEFINE_FIELD( m_flCrouchWalkFraction, FIELD_FLOAT ),

DEFINE_FIELD( m_flWaterJumpTime, FIELD_TIME ),
DEFINE_FIELD( m_vecWaterJumpVel, FIELD_VECTOR ),
DEFINE_FIELD( m_nImpulse, FIELD_INTEGER ),
Expand Down Expand Up @@ -758,7 +763,7 @@ bool CBasePlayer::WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, cons

// get max distance player could have moved within max lag compensation time,
// multiply by 1.5 to to avoid "dead zones" (sqrt(2) would be the exact value)
float maxDistance = 1.5 * pPlayer->MaxSpeed() * sv_maxunlag.GetFloat();
float maxDistance = 1.5 * pPlayer->GetMaxSpeed() * sv_maxunlag.GetFloat();

// If the player is within this distance, lag compensate them in case they're running past us.
if ( vHisOrigin.DistTo( vMyOrigin ) < maxDistance )
Expand Down Expand Up @@ -8016,6 +8021,11 @@ SendPropDataTable( SENDINFO_DT( m_AttributeList ), &REFERENCE_SEND_TABLE( DT_Att
SendPropInt( SENDINFO( m_iBonusProgress ), 15 ),
SendPropInt( SENDINFO( m_iBonusChallenge ), 4 ),
SendPropFloat( SENDINFO( m_flMaxspeed ), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ), // CL
SendPropFloat( SENDINFO( m_flWalkSpeed ), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ), // CL
SendPropFloat( SENDINFO( m_flNormalSpeed ), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ), // CL
SendPropFloat( SENDINFO( m_flRunSpeed ), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ), // CL
SendPropFloat( SENDINFO( m_flCrouchWalkFraction ), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ), // CL

SendPropInt( SENDINFO( m_fFlags ), PLAYER_FLAG_BITS, SPROP_UNSIGNED | SPROP_CHANGES_OFTEN, SendProxy_CropFlagsToPlayerFlagBitsLength ),
SendPropInt( SENDINFO( m_iObserverMode ), 3, SPROP_UNSIGNED ),
SendPropEHandle( SENDINFO( m_hObserverTarget ) ),
Expand Down
49 changes: 44 additions & 5 deletions src/game/server/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,6 @@ class CBasePlayer : public CBaseCombatCharacter
{
return m_fInitHUD;
}
float MaxSpeed() const
{
return m_flMaxspeed;
}
Activity GetActivity() const
{
return m_Activity;
Expand Down Expand Up @@ -929,10 +925,47 @@ class CBasePlayer : public CBaseCombatCharacter
}
virtual void EquipSuit( bool bPlayEffects = true );
virtual void RemoveSuit( void );

void SetMaxSpeed( float flMaxSpeed )
{
m_flMaxspeed = flMaxSpeed;
}
float GetMaxSpeed() const
{
return m_flMaxspeed;
}
void SetWalkSpeed( float flSpeed )
{
m_flWalkSpeed = flSpeed;
}
float GetWalkSpeed( void )
{
return m_flWalkSpeed;
}
void SetNormalSpeed( float flSpeed )
{
m_flNormalSpeed = flSpeed;
}
float GetNormalSpeed( void )
{
return m_flNormalSpeed;
}
void SetRunSpeed( float flSpeed )
{
m_flRunSpeed = flSpeed;
}
float GetRunSpeed( void )
{
return m_flRunSpeed;
}
void SetCrouchWalkFraction( float flSpeed )
{
m_flCrouchWalkFraction = flSpeed;
}
float GetCrouchWalkFraction( void )
{
return m_flCrouchWalkFraction;
}

void NotifyNearbyRadiationSource( float flRange );

Expand Down Expand Up @@ -1364,7 +1397,13 @@ class CBasePlayer : public CBaseCombatCharacter

private:
// Replicated to all clients
CNetworkVar( float, m_flMaxspeed );
CNetworkVar( float, m_flMaxspeed ); // Current maximum speed

// Values to set m_flMaxspeed to when walking slowly, normally, and running.
CNetworkVar( float, m_flWalkSpeed );
CNetworkVar( float, m_flNormalSpeed );
CNetworkVar( float, m_flRunSpeed );
CNetworkVar( float, m_flCrouchWalkFraction );

// Not transmitted
float m_flWaterJumpTime; // used to be called teleport_time
Expand Down
Loading

0 comments on commit 4406b09

Please sign in to comment.