Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

818 lines
29 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #ifndef C_BASEANIMATING_H
  9. #define C_BASEANIMATING_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "c_baseentity.h"
  14. #include "studio.h"
  15. #include "utlvector.h"
  16. #include "ragdoll.h"
  17. #include "mouthinfo.h"
  18. // Shared activities
  19. #include "ai_activity.h"
  20. #include "animationlayer.h"
  21. #include "sequence_Transitioner.h"
  22. #include "bone_accessor.h"
  23. #include "bone_merge_cache.h"
  24. #include "ragdoll_shared.h"
  25. #include "tier0/threadtools.h"
  26. #include "datacache/idatacache.h"
  27. #define LIPSYNC_POSEPARAM_NAME "mouth"
  28. #define NUM_HITBOX_FIRES 10
  29. /*
  30. class C_BaseClientShader
  31. {
  32. virtual void RenderMaterial( C_BaseEntity *pEntity, int count, const vec4_t *verts, const vec4_t *normals, const vec2_t *texcoords, vec4_t *lightvalues );
  33. };
  34. */
  35. class IRagdoll;
  36. class CIKContext;
  37. class CIKState;
  38. class ConVar;
  39. class C_RopeKeyframe;
  40. class CBoneBitList;
  41. class CBoneList;
  42. class KeyValues;
  43. class CJiggleBones;
  44. class IBoneSetup;
  45. FORWARD_DECLARE_HANDLE( memhandle_t );
  46. typedef unsigned short MDLHandle_t;
  47. extern ConVar vcollide_wireframe;
  48. struct ClientModelRenderInfo_t : public ModelRenderInfo_t
  49. {
  50. // Added space for lighting origin override. Just allocated space, need to set base pointer
  51. matrix3x4_t lightingOffset;
  52. // Added space for model to world matrix. Just allocated space, need to set base pointer
  53. matrix3x4_t modelToWorld;
  54. };
  55. struct RagdollInfo_t
  56. {
  57. bool m_bActive;
  58. float m_flSaveTime;
  59. int m_nNumBones;
  60. Vector m_rgBonePos[MAXSTUDIOBONES];
  61. Quaternion m_rgBoneQuaternion[MAXSTUDIOBONES];
  62. };
  63. class CAttachmentData
  64. {
  65. public:
  66. matrix3x4_t m_AttachmentToWorld;
  67. QAngle m_angRotation;
  68. Vector m_vOriginVelocity;
  69. int m_nLastFramecount : 31;
  70. int m_bAnglesComputed : 1;
  71. };
  72. typedef unsigned int ClientSideAnimationListHandle_t;
  73. #define INVALID_CLIENTSIDEANIMATION_LIST_HANDLE (ClientSideAnimationListHandle_t)~0
  74. class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback
  75. {
  76. public:
  77. DECLARE_CLASS( C_BaseAnimating, C_BaseEntity );
  78. DECLARE_CLIENTCLASS();
  79. DECLARE_PREDICTABLE();
  80. DECLARE_INTERPOLATION();
  81. enum
  82. {
  83. NUM_POSEPAREMETERS = 24,
  84. NUM_BONECTRLS = 4
  85. };
  86. C_BaseAnimating();
  87. ~C_BaseAnimating();
  88. virtual C_BaseAnimating* GetBaseAnimating() { return this; }
  89. bool UsesPowerOfTwoFrameBufferTexture( void );
  90. virtual bool Interpolate( float currentTime );
  91. virtual void Simulate();
  92. virtual void Release();
  93. float GetAnimTimeInterval( void ) const;
  94. virtual unsigned char GetClientSideFade( void );
  95. // Get bone controller values.
  96. virtual void GetBoneControllers(float controllers[MAXSTUDIOBONECTRLS]);
  97. virtual float SetBoneController ( int iController, float flValue );
  98. LocalFlexController_t GetNumFlexControllers( void );
  99. const char *GetFlexDescFacs( int iFlexDesc );
  100. const char *GetFlexControllerName( LocalFlexController_t iFlexController );
  101. const char *GetFlexControllerType( LocalFlexController_t iFlexController );
  102. virtual void GetAimEntOrigin( IClientEntity *pAttachedTo, Vector *pAbsOrigin, QAngle *pAbsAngles );
  103. // Computes a box that surrounds all hitboxes
  104. bool ComputeHitboxSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs );
  105. bool ComputeEntitySpaceHitboxSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs );
  106. // Gets the hitbox-to-world transforms, returns false if there was a problem
  107. bool HitboxToWorldTransforms( matrix3x4_t *pHitboxToWorld[MAXSTUDIOBONES] );
  108. // base model functionality
  109. float ClampCycle( float cycle, bool isLooping );
  110. virtual void GetPoseParameters( CStudioHdr *pStudioHdr, float poseParameter[MAXSTUDIOPOSEPARAM] );
  111. virtual void BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed );
  112. virtual void ApplyBoneMatrixTransform( matrix3x4_t& transform );
  113. virtual int VPhysicsGetObjectList( IPhysicsObject **pList, int listMax );
  114. // model specific
  115. virtual bool SetupBones( matrix3x4_t *pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime );
  116. virtual void UpdateIKLocks( float currentTime );
  117. virtual void CalculateIKLocks( float currentTime );
  118. virtual bool ShouldDraw();
  119. virtual void UpdateVisibility() OVERRIDE;
  120. virtual int DrawModel( int flags );
  121. virtual int InternalDrawModel( int flags );
  122. virtual bool OnInternalDrawModel( ClientModelRenderInfo_t *pInfo );
  123. virtual bool OnPostInternalDrawModel( ClientModelRenderInfo_t *pInfo );
  124. void DoInternalDrawModel( ClientModelRenderInfo_t *pInfo, DrawModelState_t *pState, matrix3x4_t *pBoneToWorldArray = NULL );
  125. virtual IMaterial* GetEconWeaponMaterialOverride( int iTeam ) { return NULL; }
  126. //
  127. virtual CMouthInfo *GetMouth();
  128. virtual void ControlMouth( CStudioHdr *pStudioHdr );
  129. // override in sub-classes
  130. virtual void DoAnimationEvents( CStudioHdr *pStudio );
  131. virtual void FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options );
  132. virtual void FireObsoleteEvent( const Vector& origin, const QAngle& angles, int event, const char *options );
  133. virtual const char* ModifyEventParticles( const char* token ) { return token; }
  134. // Parses and distributes muzzle flash events
  135. virtual bool DispatchMuzzleEffect( const char *options, bool isFirstPerson );
  136. // virtual void AllocateMaterials( void );
  137. // virtual void FreeMaterials( void );
  138. virtual void ValidateModelIndex( void );
  139. virtual CStudioHdr *OnNewModel( void );
  140. CStudioHdr *GetModelPtr() const;
  141. void InvalidateMdlCache();
  142. virtual void SetPredictable( bool state );
  143. void UseClientSideAnimation();
  144. // C_BaseClientShader **p_ClientShaders;
  145. virtual void StandardBlendingRules( CStudioHdr *pStudioHdr, Vector pos[], Quaternion q[], float currentTime, int boneMask );
  146. void UnragdollBlend( CStudioHdr *hdr, Vector pos[], Quaternion q[], float currentTime );
  147. void MaintainSequenceTransitions( IBoneSetup &boneSetup, float flCycle, Vector pos[], Quaternion q[] );
  148. virtual void AccumulateLayers( IBoneSetup &boneSetup, Vector pos[], Quaternion q[], float currentTime );
  149. virtual void ChildLayerBlend( Vector pos[], Quaternion q[], float currentTime, int boneMask );
  150. // Attachments
  151. int LookupAttachment( const char *pAttachmentName );
  152. int LookupRandomAttachment( const char *pAttachmentNameSubstring );
  153. int LookupPoseParameter( CStudioHdr *pStudioHdr, const char *szName );
  154. inline int LookupPoseParameter( const char *szName ) { return LookupPoseParameter(GetModelPtr(), szName); }
  155. float SetPoseParameter( CStudioHdr *pStudioHdr, const char *szName, float flValue );
  156. inline float SetPoseParameter( const char *szName, float flValue ) { return SetPoseParameter( GetModelPtr(), szName, flValue ); }
  157. float SetPoseParameter( CStudioHdr *pStudioHdr, int iParameter, float flValue );
  158. inline float SetPoseParameter( int iParameter, float flValue ) { return SetPoseParameter( GetModelPtr(), iParameter, flValue ); }
  159. float GetPoseParameter( int iPoseParameter );
  160. bool GetPoseParameterRange( int iPoseParameter, float &minValue, float &maxValue );
  161. int LookupBone( const char *szName );
  162. void GetBonePosition( int iBone, Vector &origin, QAngle &angles );
  163. void GetBoneTransform( int iBone, matrix3x4_t &pBoneToWorld );
  164. //=============================================================================
  165. // HPE_BEGIN:
  166. // [menglish] Finds the bone associated with the given hitbox
  167. //=============================================================================
  168. int GetHitboxBone( int hitboxIndex );
  169. //=============================================================================
  170. // HPE_END
  171. //=============================================================================
  172. // Bone attachments
  173. virtual void AttachEntityToBone( C_BaseAnimating* attachTarget, int boneIndexAttached=-1, Vector bonePosition=Vector(0,0,0), QAngle boneAngles=QAngle(0,0,0) );
  174. void AddBoneAttachment( C_BaseAnimating* newBoneAttachment );
  175. void RemoveBoneAttachment( C_BaseAnimating* boneAttachment );
  176. void RemoveBoneAttachments();
  177. void DestroyBoneAttachments();
  178. void MoveBoneAttachments( C_BaseAnimating* attachTarget );
  179. int GetNumBoneAttachments();
  180. C_BaseAnimating* GetBoneAttachment( int i );
  181. virtual void NotifyBoneAttached( C_BaseAnimating* attachTarget );
  182. virtual void UpdateBoneAttachments( void );
  183. //bool solveIK(float a, float b, const Vector &Foot, const Vector &Knee1, Vector &Knee2);
  184. //void DebugIK( mstudioikchain_t *pikchain );
  185. virtual void PreDataUpdate( DataUpdateType_t updateType );
  186. virtual void PostDataUpdate( DataUpdateType_t updateType );
  187. virtual int RestoreData( const char *context, int slot, int type );
  188. virtual void NotifyShouldTransmit( ShouldTransmitState_t state );
  189. virtual void OnPreDataChanged( DataUpdateType_t updateType );
  190. virtual void OnDataChanged( DataUpdateType_t updateType );
  191. virtual void AddEntity( void );
  192. // This can be used to force client side animation to be on. Only use if you know what you're doing!
  193. // Normally, the server entity should set this.
  194. void ForceClientSideAnimationOn();
  195. void AddToClientSideAnimationList();
  196. void RemoveFromClientSideAnimationList( bool bBeingDestroyed = false );
  197. virtual bool IsSelfAnimating();
  198. virtual void ResetLatched();
  199. // implements these so ragdolls can handle frustum culling & leaf visibility
  200. virtual void GetRenderBounds( Vector& theMins, Vector& theMaxs );
  201. virtual const Vector& GetRenderOrigin( void );
  202. virtual const QAngle& GetRenderAngles( void );
  203. virtual bool GetSoundSpatialization( SpatializationInfo_t& info );
  204. // Attachments.
  205. bool GetAttachment( const char *szName, Vector &absOrigin );
  206. bool GetAttachment( const char *szName, Vector &absOrigin, QAngle &absAngles );
  207. // Inherited from C_BaseEntity
  208. virtual bool GetAttachment( int number, Vector &origin );
  209. virtual bool GetAttachment( int number, Vector &origin, QAngle &angles );
  210. virtual bool GetAttachment( int number, matrix3x4_t &matrix );
  211. virtual bool GetAttachmentVelocity( int number, Vector &originVel, Quaternion &angleVel );
  212. // Returns the attachment in local space
  213. bool GetAttachmentLocal( int iAttachment, matrix3x4_t &attachmentToLocal );
  214. bool GetAttachmentLocal( int iAttachment, Vector &origin, QAngle &angles );
  215. bool GetAttachmentLocal( int iAttachment, Vector &origin );
  216. bool GetRootBone( matrix3x4_t &rootBone );
  217. // Should this object cast render-to-texture shadows?
  218. virtual ShadowType_t ShadowCastType();
  219. // Should we collide?
  220. virtual CollideType_t GetCollideType( void );
  221. virtual bool TestCollision( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  222. virtual bool TestHitboxes( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  223. // returns true if we're currently being ragdolled
  224. bool IsRagdoll() const;
  225. bool IsAboutToRagdoll() const;
  226. virtual C_BaseAnimating *BecomeRagdollOnClient();
  227. C_BaseAnimating *CreateRagdollCopy();
  228. bool InitAsClientRagdoll( const matrix3x4_t *pDeltaBones0, const matrix3x4_t *pDeltaBones1, const matrix3x4_t *pCurrentBonePosition, float boneDt, bool bFixedConstraints=false );
  229. void IgniteRagdoll( C_BaseAnimating *pSource );
  230. void TransferDissolveFrom( C_BaseAnimating *pSource );
  231. virtual void SaveRagdollInfo( int numbones, const matrix3x4_t &cameraTransform, CBoneAccessor &pBoneToWorld );
  232. virtual bool RetrieveRagdollInfo( Vector *pos, Quaternion *q );
  233. virtual void Clear( void );
  234. void ClearRagdoll();
  235. void CreateUnragdollInfo( C_BaseAnimating *pRagdoll );
  236. bool ForceSetupBonesAtTime( matrix3x4_t *pBonesOut, float flTime );
  237. virtual bool GetRagdollInitBoneArrays( matrix3x4_t *pDeltaBones0, matrix3x4_t *pDeltaBones1, matrix3x4_t *pCurrentBones, float boneDt );
  238. // For shadows rendering the correct body + sequence...
  239. virtual int GetBody() { return m_nBody; }
  240. virtual int GetSkin() { return m_nSkin; }
  241. bool IsOnFire() { return ( (GetFlags() & FL_ONFIRE) != 0 ); }
  242. inline float GetPlaybackRate();
  243. inline void SetPlaybackRate( float rate );
  244. void SetModelScale( float scale, float change_duration = 0.0f );
  245. float GetModelScale() const { return m_flModelScale; }
  246. inline bool IsModelScaleFractional() const; /// very fast way to ask if the model scale is < 1.0f (faster than if (GetModelScale() < 1.0f) )
  247. inline bool IsModelScaled() const;
  248. void UpdateModelScale( void );
  249. virtual void RefreshCollisionBounds( void );
  250. int GetSequence();
  251. virtual void SetSequence(int nSequence);
  252. inline void ResetSequence(int nSequence);
  253. float GetSequenceGroundSpeed( CStudioHdr *pStudioHdr, int iSequence );
  254. inline float GetSequenceGroundSpeed( int iSequence ) { return GetSequenceGroundSpeed(GetModelPtr(), iSequence); }
  255. bool IsSequenceLooping( CStudioHdr *pStudioHdr, int iSequence );
  256. inline bool IsSequenceLooping( int iSequence ) { return IsSequenceLooping(GetModelPtr(),iSequence); }
  257. float GetSequenceMoveDist( CStudioHdr *pStudioHdr, int iSequence );
  258. void GetSequenceLinearMotion( int iSequence, Vector *pVec );
  259. void GetBlendedLinearVelocity( Vector *pVec );
  260. int LookupSequence ( const char *label );
  261. int LookupActivity( const char *label );
  262. char const *GetSequenceName( int iSequence );
  263. char const *GetSequenceActivityName( int iSequence );
  264. Activity GetSequenceActivity( int iSequence );
  265. KeyValues *GetSequenceKeyValues( int iSequence );
  266. virtual void StudioFrameAdvance(); // advance animation frame to some time in the future
  267. // Clientside animation
  268. virtual float FrameAdvance( float flInterval = 0.0f );
  269. virtual float GetSequenceCycleRate( CStudioHdr *pStudioHdr, int iSequence );
  270. virtual void UpdateClientSideAnimation();
  271. void ClientSideAnimationChanged();
  272. virtual unsigned int ComputeClientSideAnimationFlags();
  273. virtual void ResetClientsideFrame( void ) { SetCycle( 0 ); }
  274. void SetCycle( float flCycle );
  275. float GetCycle() const;
  276. void SetBodygroup( int iGroup, int iValue );
  277. int GetBodygroup( int iGroup );
  278. const char *GetBodygroupName( int iGroup );
  279. int FindBodygroupByName( const char *name );
  280. int GetBodygroupCount( int iGroup );
  281. int GetNumBodyGroups( void );
  282. class CBoneCache *GetBoneCache( CStudioHdr *pStudioHdr );
  283. void SetHitboxSet( int setnum );
  284. void SetHitboxSetByName( const char *setname );
  285. int GetHitboxSet( void );
  286. char const *GetHitboxSetName( void );
  287. int GetHitboxSetCount( void );
  288. void DrawClientHitboxes( float duration = 0.0f, bool monocolor = false );
  289. C_BaseAnimating* FindFollowedEntity();
  290. virtual bool IsActivityFinished( void ) { return m_bSequenceFinished; }
  291. inline bool IsSequenceFinished( void );
  292. inline bool SequenceLoops( void ) { return m_bSequenceLoops; }
  293. // All view model attachments origins are stretched so you can place entities at them and
  294. // they will match up with where the attachment winds up being drawn on the view model, since
  295. // the view models are drawn with a different FOV.
  296. //
  297. // If you're drawing something inside of a view model's DrawModel() function, then you want the
  298. // original attachment origin instead of the adjusted one. To get that, call this on the
  299. // adjusted attachment origin.
  300. virtual void UncorrectViewModelAttachment( Vector &vOrigin ) {}
  301. // Call this if SetupBones() has already been called this frame but you need to move the
  302. // entity and rerender.
  303. void InvalidateBoneCache();
  304. bool IsBoneCacheValid() const; // Returns true if the bone cache is considered good for this frame.
  305. void GetCachedBoneMatrix( int boneIndex, matrix3x4_t &out );
  306. // Wrappers for CBoneAccessor.
  307. const matrix3x4_t& GetBone( int iBone ) const;
  308. matrix3x4_t& GetBoneForWrite( int iBone );
  309. // Used for debugging. Will produce asserts if someone tries to setup bones or
  310. // attachments before it's allowed.
  311. // Use the "AutoAllowBoneAccess" class to auto push/pop bone access.
  312. // Use a distinct "tag" when pushing/popping - asserts when push/pop tags do not match.
  313. struct AutoAllowBoneAccess
  314. {
  315. AutoAllowBoneAccess( bool bAllowForNormalModels, bool bAllowForViewModels );
  316. ~AutoAllowBoneAccess( void );
  317. };
  318. static void PushAllowBoneAccess( bool bAllowForNormalModels, bool bAllowForViewModels, char const *tagPush );
  319. static void PopBoneAccess( char const *tagPop );
  320. static void ThreadedBoneSetup();
  321. static void InitBoneSetupThreadPool();
  322. static void ShutdownBoneSetupThreadPool();
  323. // Invalidate bone caches so all SetupBones() calls force bone transforms to be regenerated.
  324. static void InvalidateBoneCaches();
  325. // Purpose: My physics object has been updated, react or extract data
  326. virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );
  327. void DisableMuzzleFlash(); // Turn off the muzzle flash (ie: signal that we handled the server's event).
  328. virtual void DoMuzzleFlash(); // Force a muzzle flash event. Note: this only QUEUES an event, so
  329. // ProcessMuzzleFlashEvent will get called later.
  330. bool ShouldMuzzleFlash() const; // Is the muzzle flash event on?
  331. // This is called to do the actual muzzle flash effect.
  332. virtual void ProcessMuzzleFlashEvent();
  333. // Update client side animations
  334. static void UpdateClientSideAnimations();
  335. // Load the model's keyvalues section and create effects listed inside it
  336. void InitModelEffects( void );
  337. // Sometimes the server wants to update the client's cycle to get the two to run in sync (for proper hit detection)
  338. virtual void SetServerIntendedCycle( float intended ) { (void)intended; }
  339. virtual float GetServerIntendedCycle( void ) { return -1.0f; }
  340. // For prediction
  341. int SelectWeightedSequence ( int activity );
  342. int SelectWeightedSequenceFromModifiers( Activity activity, CUtlSymbol *pActivityModifiers, int iModifierCount );
  343. void ResetSequenceInfo( void );
  344. float SequenceDuration( void );
  345. float SequenceDuration( CStudioHdr *pStudioHdr, int iSequence );
  346. inline float SequenceDuration( int iSequence ) { return SequenceDuration(GetModelPtr(), iSequence); }
  347. int FindTransitionSequence( int iCurrentSequence, int iGoalSequence, int *piDir );
  348. void RagdollMoved( void );
  349. virtual void GetToolRecordingState( KeyValues *msg );
  350. virtual void CleanupToolRecordingState( KeyValues *msg );
  351. void SetReceivedSequence( void );
  352. virtual bool ShouldResetSequenceOnNewModel( void );
  353. virtual bool IsViewModel() const;
  354. virtual void UpdateOnRemove( void );
  355. protected:
  356. // View models scale their attachment positions to account for FOV. To get the unmodified
  357. // attachment position (like if you're rendering something else during the view model's DrawModel call),
  358. // use TransformViewModelAttachmentToWorld.
  359. virtual void FormatViewModelAttachment( int nAttachment, matrix3x4_t &attachmentToWorld ) {}
  360. // View models say yes to this.
  361. bool IsBoneAccessAllowed() const;
  362. CMouthInfo& MouthInfo();
  363. // Models used in a ModelPanel say yes to this
  364. virtual bool IsMenuModel() const;
  365. // Allow studio models to tell C_BaseEntity what their m_nBody value is
  366. virtual int GetStudioBody( void ) { return m_nBody; }
  367. virtual bool CalcAttachments();
  368. private:
  369. // This method should return true if the bones have changed + SetupBones needs to be called
  370. virtual float LastBoneChangedTime() { return FLT_MAX; }
  371. CBoneList* RecordBones( CStudioHdr *hdr, matrix3x4_t *pBoneState );
  372. bool PutAttachment( int number, const matrix3x4_t &attachmentToWorld );
  373. void TermRopes();
  374. void DelayedInitModelEffects( void );
  375. void UpdateRelevantInterpolatedVars();
  376. void AddBaseAnimatingInterpolatedVars();
  377. void RemoveBaseAnimatingInterpolatedVars();
  378. public:
  379. CRagdoll *m_pRagdoll;
  380. // Texture group to use
  381. int m_nSkin;
  382. // Object bodygroup
  383. int m_nBody;
  384. // Hitbox set to use (default 0)
  385. int m_nHitboxSet;
  386. CSequenceTransitioner m_SequenceTransitioner;
  387. protected:
  388. CIKContext *m_pIk;
  389. int m_iEyeAttachment;
  390. // Animation playback framerate
  391. float m_flPlaybackRate;
  392. // Decomposed ragdoll info
  393. bool m_bStoreRagdollInfo;
  394. RagdollInfo_t *m_pRagdollInfo;
  395. Vector m_vecForce;
  396. int m_nForceBone;
  397. // Is bone cache valid
  398. // bone transformation matrix
  399. unsigned long m_iMostRecentModelBoneCounter;
  400. unsigned long m_iMostRecentBoneSetupRequest;
  401. int m_iPrevBoneMask;
  402. int m_iAccumulatedBoneMask;
  403. CBoneAccessor m_BoneAccessor;
  404. CThreadFastMutex m_BoneSetupLock;
  405. ClientSideAnimationListHandle_t m_ClientSideAnimationListHandle;
  406. // Client-side animation
  407. bool m_bClientSideFrameReset;
  408. // Bone attachments. Used for attaching one BaseAnimating to another's bones.
  409. // Client side only.
  410. CUtlVector<CHandle<C_BaseAnimating> > m_BoneAttachments;
  411. int m_boneIndexAttached;
  412. Vector m_bonePosition;
  413. QAngle m_boneAngles;
  414. CHandle<C_BaseAnimating> m_pAttachedTo;
  415. protected:
  416. float m_fadeMinDist;
  417. float m_fadeMaxDist;
  418. float m_flFadeScale;
  419. private:
  420. float m_flGroundSpeed; // computed linear movement rate for current sequence
  421. float m_flLastEventCheck; // cycle index of when events were last checked
  422. bool m_bSequenceFinished;// flag set when StudioAdvanceFrame moves across a frame boundry
  423. bool m_bSequenceLoops; // true if the sequence loops
  424. // Mouth lipsync/envelope following values
  425. CMouthInfo m_mouth;
  426. CNetworkVar( float, m_flModelScale );
  427. // Animation blending factors
  428. float m_flPoseParameter[MAXSTUDIOPOSEPARAM];
  429. CInterpolatedVarArray< float, MAXSTUDIOPOSEPARAM > m_iv_flPoseParameter;
  430. float m_flOldPoseParameters[MAXSTUDIOPOSEPARAM];
  431. int m_nPrevSequence;
  432. int m_nRestoreSequence;
  433. // Ropes that got spawned when the model was created.
  434. CUtlLinkedList<C_RopeKeyframe*,unsigned short> m_Ropes;
  435. // event processing info
  436. float m_flPrevEventCycle;
  437. int m_nEventSequence;
  438. float m_flEncodedController[MAXSTUDIOBONECTRLS];
  439. CInterpolatedVarArray< float, MAXSTUDIOBONECTRLS > m_iv_flEncodedController;
  440. float m_flOldEncodedController[MAXSTUDIOBONECTRLS];
  441. // Clientside animation
  442. bool m_bClientSideAnimation;
  443. bool m_bLastClientSideFrameReset;
  444. int m_nNewSequenceParity;
  445. int m_nResetEventsParity;
  446. int m_nPrevNewSequenceParity;
  447. int m_nPrevResetEventsParity;
  448. bool m_builtRagdoll;
  449. Vector m_vecPreRagdollMins;
  450. Vector m_vecPreRagdollMaxs;
  451. // Current animation sequence
  452. int m_nSequence;
  453. bool m_bReceivedSequence;
  454. // Current cycle location from server
  455. protected:
  456. float m_flCycle;
  457. CInterpolatedVar< float > m_iv_flCycle;
  458. float m_flOldCycle;
  459. bool m_bNoModelParticles;
  460. private:
  461. float m_flOldModelScale;
  462. int m_nOldSequence;
  463. CBoneMergeCache *m_pBoneMergeCache; // This caches the strcmp lookups that it has to do
  464. // when merg
  465. CUtlVector< matrix3x4_t > m_CachedBoneData; // never access this directly. Use m_BoneAccessor.
  466. memhandle_t m_hitboxBoneCacheHandle;
  467. float m_flLastBoneSetupTime;
  468. CJiggleBones *m_pJiggleBones;
  469. // Calculated attachment points
  470. CUtlVector<CAttachmentData> m_Attachments;
  471. bool SetupBones_AttachmentHelper( CStudioHdr *pStudioHdr );
  472. EHANDLE m_hLightingOrigin;
  473. EHANDLE m_hLightingOriginRelative;
  474. // These are compared against each other to determine if the entity should muzzle flash.
  475. CNetworkVar( unsigned char, m_nMuzzleFlashParity );
  476. unsigned char m_nOldMuzzleFlashParity;
  477. bool m_bInitModelEffects;
  478. bool m_bDelayInitModelEffects;
  479. // Dynamic models
  480. bool m_bDynamicModelAllowed;
  481. bool m_bDynamicModelPending;
  482. bool m_bResetSequenceInfoOnLoad;
  483. CRefCountedModelIndex m_AutoRefModelIndex;
  484. public:
  485. void EnableDynamicModels() { m_bDynamicModelAllowed = true; }
  486. bool IsDynamicModelLoading() const { return m_bDynamicModelPending; }
  487. private:
  488. virtual void OnModelLoadComplete( const model_t* pModel );
  489. private:
  490. void LockStudioHdr();
  491. void UnlockStudioHdr();
  492. mutable CStudioHdr *m_pStudioHdr;
  493. mutable MDLHandle_t m_hStudioHdr;
  494. CThreadFastMutex m_StudioHdrInitLock;
  495. bool m_bHasAttachedParticles;
  496. };
  497. enum
  498. {
  499. RAGDOLL_FRICTION_OFF = -2,
  500. RAGDOLL_FRICTION_NONE,
  501. RAGDOLL_FRICTION_IN,
  502. RAGDOLL_FRICTION_HOLD,
  503. RAGDOLL_FRICTION_OUT,
  504. };
  505. class C_ClientRagdoll : public C_BaseAnimating, public IPVSNotify
  506. {
  507. public:
  508. C_ClientRagdoll( bool bRestoring = true );
  509. DECLARE_CLASS( C_ClientRagdoll, C_BaseAnimating );
  510. DECLARE_DATADESC();
  511. // inherited from IPVSNotify
  512. virtual void OnPVSStatusChanged( bool bInPVS );
  513. virtual void Release( void );
  514. virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights );
  515. virtual void ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName );
  516. void ClientThink( void );
  517. void ReleaseRagdoll( void ) { m_bReleaseRagdoll = true; }
  518. bool ShouldSavePhysics( void ) { return true; }
  519. virtual void OnSave();
  520. virtual void OnRestore();
  521. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() | FCAP_SAVE_NON_NETWORKABLE; }
  522. virtual IPVSNotify* GetPVSNotifyInterface() { return this; }
  523. void HandleAnimatedFriction( void );
  524. virtual void SUB_Remove( void );
  525. void FadeOut( void );
  526. virtual float LastBoneChangedTime();
  527. bool m_bFadeOut;
  528. bool m_bImportant;
  529. float m_flEffectTime;
  530. private:
  531. int m_iCurrentFriction;
  532. int m_iMinFriction;
  533. int m_iMaxFriction;
  534. float m_flFrictionModTime;
  535. float m_flFrictionTime;
  536. int m_iFrictionAnimState;
  537. bool m_bReleaseRagdoll;
  538. bool m_bFadingOut;
  539. float m_flScaleEnd[NUM_HITBOX_FIRES];
  540. float m_flScaleTimeStart[NUM_HITBOX_FIRES];
  541. float m_flScaleTimeEnd[NUM_HITBOX_FIRES];
  542. };
  543. //-----------------------------------------------------------------------------
  544. // Purpose: Serves the 90% case of calling SetSequence / ResetSequenceInfo.
  545. //-----------------------------------------------------------------------------
  546. inline void C_BaseAnimating::ResetSequence(int nSequence)
  547. {
  548. SetSequence( nSequence );
  549. ResetSequenceInfo();
  550. }
  551. inline float C_BaseAnimating::GetPlaybackRate()
  552. {
  553. return m_flPlaybackRate;
  554. }
  555. inline void C_BaseAnimating::SetPlaybackRate( float rate )
  556. {
  557. m_flPlaybackRate = rate;
  558. }
  559. inline const matrix3x4_t& C_BaseAnimating::GetBone( int iBone ) const
  560. {
  561. return m_BoneAccessor.GetBone( iBone );
  562. }
  563. inline matrix3x4_t& C_BaseAnimating::GetBoneForWrite( int iBone )
  564. {
  565. return m_BoneAccessor.GetBoneForWrite( iBone );
  566. }
  567. inline bool C_BaseAnimating::ShouldMuzzleFlash() const
  568. {
  569. return m_nOldMuzzleFlashParity != m_nMuzzleFlashParity;
  570. }
  571. inline float C_BaseAnimating::GetCycle() const
  572. {
  573. return m_flCycle;
  574. }
  575. //-----------------------------------------------------------------------------
  576. // Purpose: return a pointer to an updated studiomdl cache cache
  577. //-----------------------------------------------------------------------------
  578. inline CStudioHdr *C_BaseAnimating::GetModelPtr() const
  579. {
  580. if ( IsDynamicModelLoading() )
  581. return NULL;
  582. #ifdef _DEBUG
  583. // GetModelPtr() is often called before OnNewModel() so go ahead and set it up first chance.
  584. // static IDataCacheSection *pModelCache = datacache->FindSection( "ModelData" );
  585. // AssertOnce( pModelCache->IsFrameLocking() );
  586. #endif
  587. if ( !m_pStudioHdr )
  588. {
  589. const_cast<C_BaseAnimating *>(this)->LockStudioHdr();
  590. }
  591. Assert( m_pStudioHdr ? m_pStudioHdr->GetRenderHdr() == mdlcache->GetStudioHdr(m_hStudioHdr) : m_hStudioHdr == MDLHANDLE_INVALID );
  592. return m_pStudioHdr;
  593. }
  594. inline void C_BaseAnimating::InvalidateMdlCache()
  595. {
  596. UnlockStudioHdr();
  597. }
  598. inline bool C_BaseAnimating::IsModelScaleFractional() const
  599. {
  600. return ( m_flModelScale < 1.0f );
  601. }
  602. inline bool C_BaseAnimating::IsModelScaled() const
  603. {
  604. return ( m_flModelScale > 1.0f+FLT_EPSILON || m_flModelScale < 1.0f-FLT_EPSILON );
  605. }
  606. //-----------------------------------------------------------------------------
  607. // Sequence access
  608. //-----------------------------------------------------------------------------
  609. inline int C_BaseAnimating::GetSequence()
  610. {
  611. return m_nSequence;
  612. }
  613. inline bool C_BaseAnimating::IsSequenceFinished( void )
  614. {
  615. return m_bSequenceFinished;
  616. }
  617. inline float C_BaseAnimating::SequenceDuration( void )
  618. {
  619. return SequenceDuration( GetSequence() );
  620. }
  621. //-----------------------------------------------------------------------------
  622. // Mouth
  623. //-----------------------------------------------------------------------------
  624. inline CMouthInfo& C_BaseAnimating::MouthInfo()
  625. {
  626. return m_mouth;
  627. }
  628. // FIXME: move these to somewhere that makes sense
  629. void GetColumn( matrix3x4_t& src, int column, Vector &dest );
  630. void SetColumn( Vector &src, int column, matrix3x4_t& dest );
  631. EXTERN_RECV_TABLE(DT_BaseAnimating);
  632. extern void DevMsgRT( PRINTF_FORMAT_STRING char const* pMsg, ... );
  633. #endif // C_BASEANIMATING_H