From 53561ff88170c7833c1dc95a85a1f4082a179a49 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Sep 2024 23:54:10 +0200 Subject: [PATCH] TODO: figure out why we need to do this --- game/client/cstrike/c_cs_player.cpp | 28 +++++++-------------- game/client/cstrike/c_cs_player.h | 3 +++ game/client/in_main.cpp | 2 +- game/server/BaseAnimatingOverlay.cpp | 2 +- game/server/baseanimating.cpp | 14 +++++------ game/server/baseentity.h | 5 ++++ game/server/cstrike/cs_player.cpp | 3 ++- game/server/cstrike/cs_player.h | 3 +++ game/server/player_lagcompensation.cpp | 32 ++++++++++++++++++++++++ game/shared/cstrike/cs_player_shared.cpp | 18 ++++++++++++- game/shared/cstrike/fx_cs_shared.cpp | 2 +- 11 files changed, 81 insertions(+), 31 deletions(-) diff --git a/game/client/cstrike/c_cs_player.cpp b/game/client/cstrike/c_cs_player.cpp index 13604e873a..e1825ad34d 100644 --- a/game/client/cstrike/c_cs_player.cpp +++ b/game/client/cstrike/c_cs_player.cpp @@ -690,6 +690,7 @@ IMPLEMENT_CLIENTCLASS_DT( C_CSPlayer, DT_CSPlayer, CCSPlayer ) RecvPropInt( RECVINFO( m_iClass ) ), RecvPropInt( RECVINFO( m_ArmorValue ) ), RecvPropQAngles( RECVINFO( m_angEyeAngles ) ), + RecvPropQAngles( RECVINFO( m_angRenderAngles ) ), RecvPropFloat( RECVINFO( m_flStamina ) ), RecvPropInt( RECVINFO( m_bHasDefuser ), 0, RecvProxy_HasDefuser ), RecvPropInt( RECVINFO( m_bNightVisionOn), 0, RecvProxy_NightVision ), @@ -738,6 +739,8 @@ C_CSPlayer::C_CSPlayer() : AddVar( &m_angEyeAngles, &m_iv_angEyeAngles, LATCH_SIMULATION_VAR ); + // interpolation on m_angRenderAngles later + m_iLastAddonBits = m_iAddonBits = 0; m_iLastPrimaryAddon = m_iLastSecondaryAddon = WEAPON_NONE; m_iProgressBarDuration = 0; @@ -879,19 +882,6 @@ int C_CSPlayer::GetCurrentAssaultSuitPrice() } } -const QAngle& C_CSPlayer::GetRenderAngles() -{ - if ( IsRagdoll() ) - { - return vec3_angle; - } - else - { - return BaseClass::GetRenderAngles(); - } -} - - float g_flFattenAmt = 4; void C_CSPlayer::GetShadowRenderBounds( Vector &mins, Vector &maxs, ShadowType_t shadowType ) { @@ -2180,7 +2170,7 @@ void C_CSPlayer::FireGameEvent( IGameEvent* event ) C_AnimationLayer backupAnimLayers[C_BaseAnimatingOverlay::MAX_OVERLAYS]; Vector vecBackupPosition = player->GetAbsOrigin(); - QAngle angBackupAngles = player->GetAbsAngles(); + QAngle angBackupAngles = player->GetRenderAngles(); auto flOldCycle = player->GetCycle(); auto iOldSequence = player->GetSequence(); @@ -2205,9 +2195,9 @@ void C_CSPlayer::FireGameEvent( IGameEvent* event ) event->GetFloat( "position_y" ), event->GetFloat( "position_z" ) ) ); - player->SetAbsAngles( QAngle( event->GetFloat( "angle_x" ), - event->GetFloat( "angle_y" ), - event->GetFloat( "angle_z" ) ) ); + player->m_angRenderAngles = QAngle( event->GetFloat( "angle_x" ), + event->GetFloat( "angle_y" ), + event->GetFloat( "angle_z" ) ); const auto numposeparams = event->GetInt( "num_poseparams" ); Assert( numposeparams == player->GetModelPtr()->GetNumPoseParameters() ); @@ -2311,7 +2301,7 @@ void C_CSPlayer::FireGameEvent( IGameEvent* event ) pos++; } - auto angles = player->GetAbsAngles(); + auto angles = player->GetRenderAngles(); if ( pRecord->m_angAbsRotation != angles ) { @@ -2440,7 +2430,7 @@ void C_CSPlayer::FireGameEvent( IGameEvent* event ) player->m_nSequence = iOldSequence; player->m_flCycle = flOldCycle; player->SetAbsOrigin( vecBackupPosition ); - player->SetAbsAngles( angBackupAngles ); + player->m_angRenderAngles = angBackupAngles; for ( int i = 0; i < MAXSTUDIOPOSEPARAM; i++ ) { diff --git a/game/client/cstrike/c_cs_player.h b/game/client/cstrike/c_cs_player.h index 7ea2c6c0c8..8c9f725ebf 100644 --- a/game/client/cstrike/c_cs_player.h +++ b/game/client/cstrike/c_cs_player.h @@ -6,6 +6,7 @@ #ifndef C_CS_PLAYER_H #define C_CS_PLAYER_H +#include "mathlib/vector.h" #ifdef _WIN32 #pragma once #endif @@ -420,6 +421,8 @@ private: }; CUtlCircularBuffer< HitboxRecord, MAX_HISTORY_HITBOX_RECORDS > m_HitboxTrack[MAX_PLAYERS + 1]; + + QAngle m_angRenderAngles; }; C_CSPlayer* GetLocalOrInEyeCSPlayer( void ); diff --git a/game/client/in_main.cpp b/game/client/in_main.cpp index c2b0e6a750..f12aeee0ff 100644 --- a/game/client/in_main.cpp +++ b/game/client/in_main.cpp @@ -1321,7 +1321,7 @@ void CInput::CreateMove ( int sequence_number, float input_sample_frametime, boo } cmd->simulationdata[i].sim_time = pEntity->m_flInterpolatedSimulationTime; - cmd->simulationdata[i].anim_time = pEntity->m_flInterpolatedAnimTime; + cmd->simulationdata[i].anim_time = pEntity->m_flAnimTime; } #ifdef CSTRIKE_DLL diff --git a/game/server/BaseAnimatingOverlay.cpp b/game/server/BaseAnimatingOverlay.cpp index d0490c028e..6ebfa65780 100644 --- a/game/server/BaseAnimatingOverlay.cpp +++ b/game/server/BaseAnimatingOverlay.cpp @@ -480,7 +480,7 @@ void CBaseAnimatingOverlay::GetSkeleton( CStudioHdr *pStudioHdr, Vector pos[], Q if ( m_pIk ) { CIKContext auto_ik; - auto_ik.Init( pStudioHdr, GetAbsAngles(), GetAbsOrigin(), gpGlobals->curtime, m_iIKCounter, boneMask ); + auto_ik.Init( pStudioHdr, GetRenderAngles(), GetAbsOrigin(), gpGlobals->curtime, m_iIKCounter, boneMask ); boneSetup.CalcAutoplaySequences( pos, q, gpGlobals->curtime, &auto_ik ); } else diff --git a/game/server/baseanimating.cpp b/game/server/baseanimating.cpp index 3eecf9a0fc..6d2e871434 100644 --- a/game/server/baseanimating.cpp +++ b/game/server/baseanimating.cpp @@ -1670,7 +1670,7 @@ void CBaseAnimating::CalculateIKLocks( float currentTime ) // FIXME: trace based on gravity or trace based on angles? Vector up; - AngleVectors( GetAbsAngles(), NULL, NULL, &up ); + AngleVectors( GetRenderAngles(), NULL, NULL, &up ); // FIXME: check number of slots? float minHeight = FLT_MAX; @@ -1781,7 +1781,7 @@ void CBaseAnimating::CalculateIKLocks( float currentTime ) else if (trace.DidHitNonWorldEntity()) { pTarget->SetPos( trace.endpos ); - pTarget->SetAngles( GetAbsAngles() ); + pTarget->SetAngles( GetRenderAngles() ); // only do this on forward tracking or commited IK ground rules if (pTarget->est.release < 0.1) @@ -1815,7 +1815,7 @@ void CBaseAnimating::CalculateIKLocks( float currentTime ) else { pTarget->SetPos( trace.endpos ); - pTarget->SetAngles( GetAbsAngles() ); + pTarget->SetAngles( GetRenderAngles() ); pTarget->SetOnWorld( true ); } } @@ -2031,7 +2031,7 @@ void CBaseAnimating::SetupBones( matrix3x4_t *pBoneToWorld, int boneMask ) // FIXME: pass this into Studio_BuildMatrices to skip transforms CBoneBitList boneComputed; m_iIKCounter++; - m_pIk->Init( pStudioHdr, GetAbsAngles(), adjOrigin, gpGlobals->curtime, m_iIKCounter, boneMask ); + m_pIk->Init( pStudioHdr, GetRenderAngles(), adjOrigin, gpGlobals->curtime, m_iIKCounter, boneMask ); GetSkeleton( pStudioHdr, pos, q, boneMask ); UpdateIKLocks( gpGlobals->curtime ); @@ -2055,7 +2055,7 @@ void CBaseAnimating::SetupBones( matrix3x4_t *pBoneToWorld, int boneMask ) { BuildMatricesWithBoneMerge( pStudioHdr, - GetAbsAngles(), + GetRenderAngles(), adjOrigin, pos, q, @@ -2074,7 +2074,7 @@ void CBaseAnimating::SetupBones( matrix3x4_t *pBoneToWorld, int boneMask ) Studio_BuildMatrices( pStudioHdr, - GetAbsAngles(), + GetRenderAngles(), adjOrigin, pos, q, @@ -3036,7 +3036,7 @@ void CBaseAnimating::GetSkeleton( CStudioHdr *pStudioHdr, Vector pos[], Quaterni if ( m_pIk ) { CIKContext auto_ik; - auto_ik.Init( pStudioHdr, GetAbsAngles(), GetAbsOrigin(), gpGlobals->curtime, m_iIKCounter, boneMask ); + auto_ik.Init( pStudioHdr, GetRenderAngles(), GetAbsOrigin(), gpGlobals->curtime, m_iIKCounter, boneMask ); boneSetup.CalcAutoplaySequences( pos, q, gpGlobals->curtime, &auto_ik ); } else diff --git a/game/server/baseentity.h b/game/server/baseentity.h index 04d3861077..f7050fa5ed 100644 --- a/game/server/baseentity.h +++ b/game/server/baseentity.h @@ -427,6 +427,11 @@ public: const Vector& GetAbsOrigin( void ) const; const QAngle& GetAbsAngles( void ) const; + virtual const QAngle& GetRenderAngles( void ) + { + return GetAbsAngles(); + } + SolidType_t GetSolid() const; int GetSolidFlags( void ) const; diff --git a/game/server/cstrike/cs_player.cpp b/game/server/cstrike/cs_player.cpp index e9adf4777d..ee6cb787b1 100644 --- a/game/server/cstrike/cs_player.cpp +++ b/game/server/cstrike/cs_player.cpp @@ -302,6 +302,7 @@ IMPLEMENT_SERVERCLASS_ST( CCSPlayer, DT_CSPlayer ) SendPropInt( SENDINFO( m_iClass ), Q_log2( CS_NUM_CLASSES )+1, SPROP_UNSIGNED ), SendPropInt( SENDINFO( m_ArmorValue ), 8 ), SendPropQAngles(SENDINFO(m_angEyeAngles)), + SendPropQAngles(SENDINFO(m_angRenderAngles)), SendPropBool( SENDINFO( m_bHasDefuser ) ), SendPropBool( SENDINFO( m_bNightVisionOn ) ), //send as int so we can use a RecvProxy on the client SendPropBool( SENDINFO( m_bHasNightVision ) ), @@ -1584,7 +1585,7 @@ void CCSPlayer::PostThink() m_PlayerAnimState->Update( m_angEyeAngles[YAW], m_angEyeAngles[PITCH] ); // Use the m_angRotation instead. - SetAbsAngles( m_PlayerAnimState->GetRenderAngles() ); + m_angRenderAngles = m_PlayerAnimState->GetRenderAngles(); // check if we need to apply a deafness DSP effect. if ((m_applyDeafnessTime != 0.0f) && (m_applyDeafnessTime <= gpGlobals->curtime)) diff --git a/game/server/cstrike/cs_player.h b/game/server/cstrike/cs_player.h index 617c9548b1..e0e7bb2d9c 100644 --- a/game/server/cstrike/cs_player.h +++ b/game/server/cstrike/cs_player.h @@ -245,6 +245,8 @@ public: static CCSPlayer *CreatePlayer( const char *className, edict_t *ed ); static CCSPlayer* Instance( int iEnt ); + virtual const QAngle& GetRenderAngles( void ); + virtual void Precache(); virtual void Spawn(); virtual void InitialSpawn( void ); @@ -814,6 +816,7 @@ public: // Copyed from EyeAngles() so we can send it to the client. CNetworkQAngle( m_angEyeAngles ); + CNetworkQAngle( m_angRenderAngles ); bool m_bVCollisionInitted; diff --git a/game/server/player_lagcompensation.cpp b/game/server/player_lagcompensation.cpp index d516526e47..b0fdc91daa 100644 --- a/game/server/player_lagcompensation.cpp +++ b/game/server/player_lagcompensation.cpp @@ -17,6 +17,9 @@ #include "util.h" #include "utllinkedlist.h" #include "BaseAnimatingOverlay.h" +#ifdef CSTRIKE_DLL +#include "cs_player.h" +#endif #include "tier0/vprof.h" // memdbgon must be the last include file in a .cpp file!!! @@ -74,6 +77,9 @@ struct LagRecord float m_masterCycle; float m_poseParameters[MAXSTUDIOPOSEPARAM]; float m_encodedControllers[MAXSTUDIOBONECTRLS]; +#ifdef CSTRIKE_DLL + QAngle m_angRenderAngles; +#endif }; // @@ -220,6 +226,15 @@ void CLagCompensationManager::TrackEntities() } } +#ifdef CSTRIKE_DLL + auto csPlayer = dynamic_cast(pEntity); + + if (csPlayer) + { + record.m_angRenderAngles = csPlayer->GetRenderAngles(); + } +#endif + track->Push( record ); } } @@ -555,6 +570,16 @@ inline void CLagCompensationManager::BacktrackEntity( CBaseEntity* pEntity, int flags |= LC_ANIM_OVERS_CHANGED; } +#ifdef CSTRIKE_DLL + auto csPlayer = dynamic_cast(pEntity); + + if (csPlayer && foundAnim) + { + restore->m_angRenderAngles = csPlayer->GetRenderAngles(); + csPlayer->m_angRenderAngles = recordAnim->m_angRenderAngles; + } +#endif + Finish(); } @@ -653,6 +678,13 @@ void CLagCompensationManager::FinishLagCompensation( CBasePlayer* player ) } } + auto csPlayer = dynamic_cast(pEntity); + + if (csPlayer) + { + csPlayer->m_angRenderAngles = restore->m_angRenderAngles; + } + pEntity->SetSimulationTime( restore->m_flSimulationTime ); pEntity->SetAnimTime( restore->m_flAnimTime ); } diff --git a/game/shared/cstrike/cs_player_shared.cpp b/game/shared/cstrike/cs_player_shared.cpp index aa6d53963a..8343332d7b 100644 --- a/game/shared/cstrike/cs_player_shared.cpp +++ b/game/shared/cstrike/cs_player_shared.cpp @@ -44,6 +44,22 @@ ConVar weapon_accuracy_nospread( "weapon_accuracy_nospread", "0", FCVAR_REPLICATED ); #define CS_MASK_SHOOT (MASK_SOLID|CONTENTS_DEBRIS) +const QAngle& CCSPlayer::GetRenderAngles() +{ +#ifdef CLIENT_DLL + if ( IsRagdoll() ) + { + return vec3_angle; + } + else + { + return m_angRenderAngles; + } +#else + return m_angRenderAngles; +#endif +} + void DispatchEffect( const char *pName, const CEffectData &data ); #ifdef _DEBUG @@ -541,7 +557,7 @@ void CCSPlayer::FireBullet( QAngle angles[MAXSTUDIOBONES]; int indexes[MAXSTUDIOBONES]; - auto angle = lagPlayer->GetAbsAngles(); + auto angle = lagPlayer->GetRenderAngles(); auto position = lagPlayer->GetAbsOrigin(); event->SetFloat( "position_x", position.x ); diff --git a/game/shared/cstrike/fx_cs_shared.cpp b/game/shared/cstrike/fx_cs_shared.cpp index 4da366f6d0..b3d0b92ebc 100644 --- a/game/shared/cstrike/fx_cs_shared.cpp +++ b/game/shared/cstrike/fx_cs_shared.cpp @@ -336,7 +336,7 @@ void FX_FireBullets( C_CSPlayer::HitboxRecord record; record.m_vecAbsOrigin = lagPlayer->GetAbsOrigin(); - record.m_angAbsRotation = lagPlayer->GetAbsAngles(); + record.m_angAbsRotation = lagPlayer->GetRenderAngles(); record.m_nAttackerTickBase = pPlayer->m_nTickBase; record.m_flSimulationTime = lagPlayer->m_flInterpolatedSimulationTime;