Add weapon_accuracy_nospread & posparam lagcomp

This commit is contained in:
Kamay Xutax 2024-01-23 14:32:02 +01:00
parent a72e160350
commit 2c2cbf4f03
2 changed files with 54 additions and 0 deletions

View file

@ -24,6 +24,7 @@
#define LC_ANGLES_CHANGED (1<<9)
#define LC_SIZE_CHANGED (1<<10)
#define LC_ANIMATION_CHANGED (1<<11)
#define LC_POSE_PARAMS_CHANGED (1<<12)
static ConVar sv_lagcompensation_teleport_dist( "sv_lagcompensation_teleport_dist", "64", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, "How far a player got moved by game code before we can't lag compensate their position back" );
#define LAG_COMPENSATION_EPS_SQR ( 0.1f * 0.1f )
@ -41,6 +42,7 @@ ConVar sv_unlag_fixstuck( "sv_unlag_fixstuck", "0", FCVAR_DEVELOPMENTONLY, "Disa
// Purpose:
//-----------------------------------------------------------------------------
#define MAX_LAYER_RECORDS (CBaseAnimatingOverlay::MAX_OVERLAYS)
#define MAX_POSE_PARAMETERS (CBaseAnimating::NUM_POSEPAREMETERS)
struct LayerRecord
{
@ -112,6 +114,7 @@ public:
LayerRecord m_layerRecords[MAX_LAYER_RECORDS];
int m_masterSequence;
float m_masterCycle;
float m_poseParameters[MAX_POSE_PARAMETERS];
};
@ -313,6 +316,15 @@ void CLagCompensationManager::FrameUpdatePostEntityThink()
}
record.m_masterSequence = pPlayer->GetSequence();
record.m_masterCycle = pPlayer->GetCycle();
CStudioHdr *hdr = pPlayer->GetModelPtr();
if( hdr )
{
for( int paramIndex = 0; paramIndex < hdr->GetNumPoseParameters(); paramIndex++ )
{
record.m_poseParameters[paramIndex] = pPlayer->GetPoseParameter( paramIndex );
}
}
}
//Clear the current player.
@ -704,6 +716,27 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, float flTar
}
}
// Now do pose parameters
CStudioHdr *hdr = pPlayer->GetModelPtr();
if( hdr )
{
for( int paramIndex = 0; paramIndex < hdr->GetNumPoseParameters(); paramIndex++ )
{
float poseParameter = record->m_poseParameters[paramIndex];
if( (frac > 0.0f) && interpolationAllowed )
{
// These could wrap like cycles, but there's no way to know. In the most common case
// (move_x/move_y) it's correct to just lerp. Interpolation almost never happens anyways.
float prevPoseParameter = prevRecord->m_poseParameters[paramIndex];
pPlayer->SetPoseParameter( paramIndex, Lerp( frac, poseParameter, prevPoseParameter ) );
}
else
{
pPlayer->SetPoseParameter( paramIndex, poseParameter );
}
}
}
if ( !flags )
return; // we didn't change anything
@ -823,6 +856,20 @@ void CLagCompensationManager::FinishLagCompensation( CBasePlayer *player )
}
}
if( restore->m_fFlags & LC_POSE_PARAMS_CHANGED )
{
restoreSimulationTime = true;
CStudioHdr *hdr = pPlayer->GetModelPtr();
if( hdr )
{
for( int paramIndex = 0; paramIndex < hdr->GetNumPoseParameters(); paramIndex++ )
{
pPlayer->SetPoseParameter( paramIndex, restore->m_poseParameters[paramIndex] );
}
}
}
if ( restoreSimulationTime )
{
pPlayer->SetSimulationTime( restore->m_flSimulationTime );

View file

@ -34,6 +34,7 @@
ConVar sv_showimpacts("sv_showimpacts", "0", FCVAR_REPLICATED, "Shows client (red) and server (blue) bullet impact point (1=both, 2=client-only, 3=server-only)" );
ConVar sv_showplayerhitboxes( "sv_showplayerhitboxes", "0", FCVAR_REPLICATED, "Show lag compensated hitboxes for the specified player index whenever a player fires." );
ConVar weapon_accuracy_nospread( "weapon_accuracy_nospread", "0", FCVAR_REPLICATED );
#define CS_MASK_SHOOT (MASK_SOLID|CONTENTS_DEBRIS)
@ -354,6 +355,12 @@ void CCSPlayer::FireBullet(
if ( !pevAttacker )
pevAttacker = this; // the default attacker is ourselves
if ( weapon_accuracy_nospread.GetBool() )
{
xSpread = 0.0f;
ySpread = 0.0f;
}
// add the spray
Vector vecDir = vecDirShooting + xSpread * vecRight + ySpread * vecUp;