From 051e8abd82d7b2fc42f9b2d1b6ead8eed7cd4d35 Mon Sep 17 00:00:00 2001 From: Kamay Xutax Date: Wed, 3 Apr 2024 00:50:54 +0200 Subject: [PATCH] various BuildTransformations fixes --- game/client/c_baseanimating.cpp | 19 +++++++++++++------ game/client/c_baseanimating.h | 2 +- game/client/c_baseflex.cpp | 4 ++-- game/client/c_baseflex.h | 2 +- game/client/cstrike/c_cs_player.cpp | 6 +++--- game/client/cstrike/c_cs_player.h | 2 +- game/client/episodic/c_npc_puppet.cpp | 4 ++-- game/client/hl2/c_basehlplayer.cpp | 4 ++-- game/client/ragdoll.cpp | 12 ++++++------ 9 files changed, 31 insertions(+), 24 deletions(-) diff --git a/game/client/c_baseanimating.cpp b/game/client/c_baseanimating.cpp index 8ae5f6a9e4..6c145f39dd 100644 --- a/game/client/c_baseanimating.cpp +++ b/game/client/c_baseanimating.cpp @@ -1458,7 +1458,7 @@ void C_BaseAnimating::GetCachedBoneMatrix( int boneIndex, matrix3x4_t &out ) //----------------------------------------------------------------------------- // Purpose: move position and rotation transforms into global matrices //----------------------------------------------------------------------------- -void C_BaseAnimating::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quaternion *q, const matrix3x4_t &cameraTransform, int boneMask, CBoneBitList &boneComputed ) +void C_BaseAnimating::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quaternion *q, const matrix3x4_t &cameraTransform, int boneMask, CBoneBitList &boneComputed, float flCurrentTime ) { VPROF_BUDGET( "C_BaseAnimating::BuildTransformations", VPROF_BUDGETGROUP_CLIENT_ANIMATION ); @@ -1574,7 +1574,7 @@ void C_BaseAnimating::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quater } // do jiggle physics - m_pJiggleBones->BuildJiggleTransformations( i, gpGlobals->realtime, jiggleInfo, goalMX, GetBoneForWrite( i ) ); + m_pJiggleBones->BuildJiggleTransformations( i, flCurrentTime, jiggleInfo, goalMX, GetBoneForWrite( i ) ); } else if (hdr->boneParent(i) == -1) @@ -1982,9 +1982,16 @@ void C_BaseAnimating::StandardBlendingRules( CStudioHdr *hdr, Vector pos[], Quat AccumulateLayers( boneSetup, pos, q, currentTime ); - CIKContext auto_ik; - auto_ik.Init( hdr, GetRenderAngles(), GetRenderOrigin(), currentTime, gpGlobals->framecount, boneMask ); - boneSetup.CalcAutoplaySequences( pos, q, currentTime, &auto_ik ); + if ( m_pIk ) + { + CIKContext auto_ik; + auto_ik.Init( hdr, GetRenderAngles(), GetRenderOrigin(), currentTime, gpGlobals->framecount, boneMask ); + boneSetup.CalcAutoplaySequences( pos, q, currentTime, &auto_ik ); + } + else + { + boneSetup.CalcAutoplaySequences( pos, q, currentTime, NULL ); + } if ( hdr->numbonecontrollers() ) { @@ -3024,7 +3031,7 @@ bool C_BaseAnimating::SetupBones( matrix3x4_t *pBoneToWorldOut, int nMaxBones, i m_pIk->SolveDependencies( pos, q, m_BoneAccessor.GetBoneArrayForWrite(), boneComputed ); } - BuildTransformations( hdr, pos, q, parentTransform, bonesMaskNeedRecalc, boneComputed ); + BuildTransformations( hdr, pos, q, parentTransform, bonesMaskNeedRecalc, boneComputed, currentTime ); RemoveFlag( EFL_SETTING_UP_BONES ); ControlMouth( hdr ); diff --git a/game/client/c_baseanimating.h b/game/client/c_baseanimating.h index b17762762e..4a4d19e177 100644 --- a/game/client/c_baseanimating.h +++ b/game/client/c_baseanimating.h @@ -139,7 +139,7 @@ public: // base model functionality float ClampCycle( float cycle, bool isLooping ); virtual void GetPoseParameters( CStudioHdr *pStudioHdr, float poseParameter[MAXSTUDIOPOSEPARAM] ); - virtual void BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed ); + virtual void BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed, float currentTime ); virtual void ApplyBoneMatrixTransform( matrix3x4_t& transform ); virtual int VPhysicsGetObjectList( IPhysicsObject **pList, int listMax ); diff --git a/game/client/c_baseflex.cpp b/game/client/c_baseflex.cpp index b18168401b..01a56ae673 100644 --- a/game/client/c_baseflex.cpp +++ b/game/client/c_baseflex.cpp @@ -1162,7 +1162,7 @@ void C_BaseFlex::SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightC // Purpose: Use the local bone positions to set flex control weights // via boneflexdrivers specified in the model //----------------------------------------------------------------------------- -void C_BaseFlex::BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed ) +void C_BaseFlex::BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed, float currentTime ) { const int nBoneFlexDriverCount = pStudioHdr->BoneFlexDriverCount(); @@ -1181,7 +1181,7 @@ void C_BaseFlex::BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quat } } - BaseClass::BuildTransformations( pStudioHdr, pos, q, cameraTransform, boneMask, boneComputed ); + BaseClass::BuildTransformations( pStudioHdr, pos, q, cameraTransform, boneMask, boneComputed, currentTime ); } diff --git a/game/client/c_baseflex.h b/game/client/c_baseflex.h index 56c86cb321..3aac18a5fa 100644 --- a/game/client/c_baseflex.h +++ b/game/client/c_baseflex.h @@ -147,7 +147,7 @@ public: virtual void OnThreadedDrawSetup(); // model specific - virtual void BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed ); + virtual void BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed, float currentTime ); static void LinkToGlobalFlexControllers( CStudioHdr *hdr ); virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights ); virtual bool SetupGlobalWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights ); diff --git a/game/client/cstrike/c_cs_player.cpp b/game/client/cstrike/c_cs_player.cpp index ab78b50da2..46b49133a2 100644 --- a/game/client/cstrike/c_cs_player.cpp +++ b/game/client/cstrike/c_cs_player.cpp @@ -1956,10 +1956,10 @@ void GetCorrectionMatrices( } -void C_CSPlayer::BuildTransformations( CStudioHdr *pHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed ) +void C_CSPlayer::BuildTransformations( CStudioHdr *pHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed, float currentTime ) { // First, setup our model's transformations like normal. - BaseClass::BuildTransformations( pHdr, pos, q, cameraTransform, boneMask, boneComputed ); + BaseClass::BuildTransformations( pHdr, pos, q, cameraTransform, boneMask, boneComputed, currentTime ); if ( IsLocalPlayer() && !C_BasePlayer::ShouldDrawLocalPlayer() ) return; @@ -1975,7 +1975,7 @@ void C_CSPlayer::BuildTransformations( CStudioHdr *pHdr, Vector *pos, Quaternion return; // Have the weapon setup its bones. - pWeapon->SetupBones( NULL, 0, BONE_USED_BY_ANYTHING, gpGlobals->curtime ); + pWeapon->SetupBones( NULL, 0, BONE_USED_BY_ANYTHING, currentTime ); int iWeaponBone = 0; if ( FindWeaponAttachmentBone( pWeapon, iWeaponBone ) ) diff --git a/game/client/cstrike/c_cs_player.h b/game/client/cstrike/c_cs_player.h index ba65608e20..acfbba014e 100644 --- a/game/client/cstrike/c_cs_player.h +++ b/game/client/cstrike/c_cs_player.h @@ -110,7 +110,7 @@ public: CUtlVector< C_BaseParticleEntity* > m_SmokeGrenades; virtual bool ShouldDraw( void ); - virtual void BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed ); + virtual void BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed, float currentTime ); virtual C_BaseAnimating * BecomeRagdollOnClient(); virtual IRagdoll* GetRepresentativeRagdoll() const; diff --git a/game/client/episodic/c_npc_puppet.cpp b/game/client/episodic/c_npc_puppet.cpp index 193b1da219..5a3b5e1dd4 100644 --- a/game/client/episodic/c_npc_puppet.cpp +++ b/game/client/episodic/c_npc_puppet.cpp @@ -51,7 +51,7 @@ void C_NPC_Puppet::OnDataChanged( DataUpdateType_t updateType ) //----------------------------------------------------------------------------- // Purpose: We need to slam our position! //----------------------------------------------------------------------------- -void C_NPC_Puppet::BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed ) +void C_NPC_Puppet::BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed, float currentTime ) { if ( m_hAnimationTarget && m_nTargetAttachment != -1 ) { @@ -68,7 +68,7 @@ void C_NPC_Puppet::BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Qu } // Call the baseclass - BaseClass::BuildTransformations( pStudioHdr, pos, q, cameraTransform, boneMask, boneComputed ); + BaseClass::BuildTransformations( pStudioHdr, pos, q, cameraTransform, boneMask, boneComputed, currentTime ); } //----------------------------------------------------------------------------- diff --git a/game/client/hl2/c_basehlplayer.cpp b/game/client/hl2/c_basehlplayer.cpp index fbc40eb2f9..cb231747b9 100644 --- a/game/client/hl2/c_basehlplayer.cpp +++ b/game/client/hl2/c_basehlplayer.cpp @@ -641,9 +641,9 @@ bool C_BaseHLPlayer::CreateMove( float flInputSampleTime, CUserCmd *pCmd ) //----------------------------------------------------------------------------- // Purpose: Input handling //----------------------------------------------------------------------------- -void C_BaseHLPlayer::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed ) +void C_BaseHLPlayer::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed, float currentTIme ) { - BaseClass::BuildTransformations( hdr, pos, q, cameraTransform, boneMask, boneComputed ); + BaseClass::BuildTransformations( hdr, pos, q, cameraTransform, boneMask, boneComputed, currentTIme ); BuildFirstPersonMeathookTransformations( hdr, pos, q, cameraTransform, boneMask, boneComputed, "ValveBiped.Bip01_Head1" ); } diff --git a/game/client/ragdoll.cpp b/game/client/ragdoll.cpp index 3457b05420..010d6799ff 100644 --- a/game/client/ragdoll.cpp +++ b/game/client/ragdoll.cpp @@ -389,7 +389,7 @@ public: void GetRenderBounds( Vector& theMins, Vector& theMaxs ); virtual void AddEntity( void ); virtual void AccumulateLayers( IBoneSetup &boneSetup, Vector pos[], Quaternion q[], float currentTime ); - virtual void BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t &cameraTransform, int boneMask, CBoneBitList &boneComputed ); + virtual void BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t &cameraTransform, int boneMask, CBoneBitList &boneComputed, float currentTime ); IPhysicsObject *GetElement( int elementNum ); virtual void UpdateOnRemove(); virtual float LastBoneChangedTime(); @@ -565,7 +565,7 @@ void C_ServerRagdoll::AccumulateLayers( IBoneSetup &boneSetup, Vector pos[], Qua } } -void C_ServerRagdoll::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quaternion q[], const matrix3x4_t &cameraTransform, int boneMask, CBoneBitList &boneComputed ) +void C_ServerRagdoll::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quaternion q[], const matrix3x4_t &cameraTransform, int boneMask, CBoneBitList &boneComputed, float currentTime ) { if ( !hdr ) return; @@ -714,14 +714,14 @@ public: return BaseClass::SetupBones( pBoneToWorldOut, nMaxBones, boneMask, currentTime ); } - virtual void BuildTransformations( CStudioHdr *hdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed ) + virtual void BuildTransformations( CStudioHdr *hdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed, float currentTime ) { VPROF_BUDGET( "C_ServerRagdollAttached::SetupBones", VPROF_BUDGETGROUP_CLIENT_ANIMATION ); if ( !hdr ) return; - float frac = RemapVal( gpGlobals->curtime, m_parentTime, m_parentTime+ATTACH_INTERP_TIME, 0, 1 ); + float frac = RemapVal( currentTime, m_parentTime, m_parentTime+ATTACH_INTERP_TIME, 0, 1 ); frac = clamp( frac, 0.f, 1.f ); // interpolate offset over some time Vector offset = m_vecOffset * (1-frac); @@ -734,13 +734,13 @@ public: if ( parent ) { Assert( parent != this ); - parent->SetupBones( NULL, -1, BONE_USED_BY_ANYTHING, gpGlobals->curtime ); + parent->SetupBones( NULL, -1, BONE_USED_BY_ANYTHING, currentTime ); matrix3x4_t boneToWorld; parent->GetCachedBoneMatrix( m_boneIndexAttached, boneToWorld ); VectorTransform( m_attachmentPointBoneSpace, boneToWorld, worldOrigin ); } - BaseClass::BuildTransformations( hdr, pos, q, cameraTransform, boneMask, boneComputed ); + BaseClass::BuildTransformations( hdr, pos, q, cameraTransform, boneMask, boneComputed, currentTime ); if ( parent ) {