Counter Strike : Global Offensive Source Code
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.

601 lines
23 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef BASEANIMATING_H
  7. #define BASEANIMATING_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "entityoutput.h"
  12. #include "studio.h"
  13. #include "bone_merge_cache.h"
  14. #include "datacache/idatacache.h"
  15. #include "tier0/threadtools.h"
  16. struct animevent_t;
  17. struct matrix3x4_t;
  18. class CIKContext;
  19. class KeyValues;
  20. class CAnimationLayer;
  21. FORWARD_DECLARE_HANDLE( memhandle_t );
  22. #define BCF_NO_ANIMATION_SKIP ( 1 << 0 ) // Do not allow PVS animation skipping (mostly for attachments being critical to an entity)
  23. #define BCF_IS_IN_SPAWN ( 1 << 1 ) // Is currently inside of spawn, always evaluate animations
  24. extern IDataCache *datacache;
  25. class CBaseAnimating : public CBaseEntity
  26. {
  27. public:
  28. DECLARE_CLASS( CBaseAnimating, CBaseEntity );
  29. CBaseAnimating();
  30. ~CBaseAnimating();
  31. DECLARE_PREDICTABLE();
  32. enum
  33. {
  34. NUM_POSEPAREMETERS = 24,
  35. NUM_BONECTRLS = 4
  36. };
  37. DECLARE_DATADESC();
  38. DECLARE_SERVERCLASS();
  39. DECLARE_ENT_SCRIPTDESC();
  40. virtual void SetModel( const char *szModelName );
  41. virtual void Activate();
  42. virtual void Spawn();
  43. virtual void Precache();
  44. virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
  45. virtual int Restore( IRestore &restore );
  46. virtual void OnRestore();
  47. CStudioHdr *GetModelPtr( void );
  48. virtual void InvalidateMdlCache() { UnlockStudioHdr(); delete m_pStudioHdr; m_pStudioHdr = NULL; }
  49. virtual CBaseAnimating* GetBaseAnimating() { return this; }
  50. // Cycle access
  51. void ForceCycle( float flCycle );
  52. void SetCycle( float flCycle );
  53. float GetCycle() const;
  54. float GetAnimTimeInterval( void ) const;
  55. // Call this in your constructor to tell it that you will not use animtime. Then the
  56. // interpolation will be done correctly on the client.
  57. // This defaults to off.
  58. void UseClientSideAnimation();
  59. // Tells whether or not we're using client-side animation. Used for controlling
  60. // the transmission of animtime.
  61. bool IsUsingClientSideAnimation() { return m_bClientSideAnimation; }
  62. // Basic NPC Animation functions
  63. virtual float GetIdealSpeed( ) const;
  64. virtual float GetIdealAccel( ) const;
  65. virtual void StudioFrameAdvance(); // advance animation frame to some time in the future
  66. void StudioFrameAdvanceManual( float flInterval );
  67. bool IsValidSequence( int iSequence );
  68. virtual void ReachedEndOfSequence() { return; }
  69. inline float GetPlaybackRate() const;
  70. inline void SetPlaybackRate( float rate );
  71. inline int GetSequence() { return m_nSequence; }
  72. // inline void SetSequence(int nSequence) { Assert( GetModelPtr( ) && nSequence >= 0 && nSequence < GetModelPtr( )->GetNumSeq() ); m_nSequence = nSequence; }
  73. void SetSequence(int nSequence);
  74. virtual void OnSequenceSet( int nOldSequence ) {}
  75. /* inline */ void ResetSequence(int nSequence);
  76. // FIXME: push transitions support down into CBaseAnimating?
  77. virtual bool IsActivityFinished( void ) { return m_bSequenceFinished; }
  78. inline bool IsSequenceFinished( void ) { return m_bSequenceFinished; }
  79. inline bool SequenceLoops( void ) { return m_bSequenceLoops; }
  80. bool IsSequenceLooping( CStudioHdr *pStudioHdr, int iSequence );
  81. inline bool IsSequenceLooping( int iSequence ) { return IsSequenceLooping(GetModelPtr(),iSequence); }
  82. inline float SequenceDuration( void ) { return SequenceDuration( m_nSequence ); }
  83. float SequenceDuration( CStudioHdr *pStudioHdr, int iSequence );
  84. inline float SequenceDuration( int iSequence ) { return SequenceDuration(GetModelPtr(), iSequence); }
  85. float GetSequenceCycleRate( CStudioHdr *pStudioHdr, int iSequence );
  86. inline float GetSequenceCycleRate( int iSequence ) { return GetSequenceCycleRate(GetModelPtr(),iSequence); }
  87. float GetLastVisibleCycle( CStudioHdr *pStudioHdr, int iSequence );
  88. virtual float GetSequenceGroundSpeed( CStudioHdr *pStudioHdr, int iSequence );
  89. inline float GetSequenceGroundSpeed( int iSequence ) { return GetSequenceGroundSpeed(GetModelPtr(), iSequence); }
  90. virtual float GetLayerSequenceCycleRate( CAnimationLayer *pLayer, int iSequence ) { return GetSequenceCycleRate(GetModelPtr(),iSequence); }
  91. void ResetActivityIndexes ( void );
  92. void ResetEventIndexes ( void );
  93. int SelectWeightedSequence ( Activity activity );
  94. int SelectWeightedSequence ( Activity activity, int curSequence );
  95. int SelectWeightedSequenceFromModifiers( Activity activity, CUtlSymbol *pActivityModifiers, int iModifierCount );
  96. int SelectHeaviestSequence ( Activity activity );
  97. int LookupActivity( const char *label );
  98. int LookupSequence ( const char *label );
  99. int LookupSequence ( CStudioHdr* pHdr, const char *label );
  100. float GetFirstSequenceAnimTag( int sequence, int nDesiredTag, float flStart = 0, float flEnd = 1 );
  101. float GetAnySequenceAnimTag( int sequence, int nDesiredTag, float flDefault );
  102. KeyValues *GetSequenceKeyValues( int iSequence );
  103. float GetSequenceMoveYaw( int iSequence );
  104. float GetSequenceMoveDist( CStudioHdr *pStudioHdr, int iSequence );
  105. inline float GetSequenceMoveDist( int iSequence ) { return GetSequenceMoveDist(GetModelPtr(),iSequence);}
  106. void GetSequenceLinearMotion( int iSequence, Vector *pVec );
  107. const char *GetSequenceName( int iSequence );
  108. const char *GetSequenceActivityName( int iSequence );
  109. Activity GetSequenceActivity( int iSequence );
  110. void ResetSequenceInfo ( );
  111. // This will stop animation until you call ResetSequenceInfo() at some point in the future
  112. inline void StopAnimation( void ) { m_flPlaybackRate = 0; }
  113. virtual void ClampRagdollForce( const Vector &vecForceIn, Vector *vecForceOut ) { *vecForceOut = vecForceIn; } // Base class does nothing.
  114. virtual bool BecomeRagdollOnClient( const Vector &force );
  115. virtual bool IsRagdoll();
  116. virtual bool CanBecomeRagdoll( void ); //Check if this entity will ragdoll when dead.
  117. virtual void GetSkeleton( CStudioHdr *pStudioHdr, BoneVector pos[], BoneQuaternionAligned q[], int boneMask );
  118. virtual void GetBoneTransform( int iBone, matrix3x4_t &pBoneToWorld );
  119. virtual void SetupBones( matrix3x4a_t *pBoneToWorld, int boneMask );
  120. virtual void CalculateIKLocks( float currentTime );
  121. virtual void Teleport( const Vector *newPosition, const QAngle *newAngles, const Vector *newVelocity, bool bUseSlowHighAccuracyContacts = true );
  122. bool HasAnimEvent( int nSequence, int nEvent );
  123. virtual void DispatchAnimEvents ( CBaseAnimating *eventHandler ); // Handle events that have happend since last time called up until X seconds into the future
  124. virtual void HandleAnimEvent( animevent_t *pEvent );
  125. virtual bool HandleScriptedAnimEvent( animevent_t *pEvent ) { return false; }
  126. virtual bool HandleBehaviorAnimEvent( animevent_t *pEvent ) { return false; }
  127. int LookupPoseParameter( CStudioHdr *pStudioHdr, const char *szName );
  128. inline int LookupPoseParameter( const char *szName ) { return LookupPoseParameter(GetModelPtr(), szName); }
  129. float SetPoseParameter( CStudioHdr *pStudioHdr, const char *szName, float flValue );
  130. inline float SetPoseParameter( const char *szName, float flValue ) { return SetPoseParameter( GetModelPtr(), szName, flValue ); }
  131. float SetPoseParameter( CStudioHdr *pStudioHdr, int iParameter, float flValue );
  132. inline float SetPoseParameter( int iParameter, float flValue ) { return SetPoseParameter( GetModelPtr(), iParameter, flValue ); }
  133. float GetPoseParameter( const char *szName );
  134. float GetPoseParameter( int iParameter );
  135. bool GetPoseParameterRange( int index, float &minValue, float &maxValue );
  136. bool HasPoseParameter( int iSequence, const char *szName );
  137. bool HasPoseParameter( int iSequence, int iParameter );
  138. float EdgeLimitPoseParameter( int iParameter, float flValue, float flBase = 0.0f );
  139. protected:
  140. // The modus operandi for pose parameters is that you should not use the const char * version of the functions
  141. // in general code -- it causes many many string comparisons, which is slower than you think. Better is to
  142. // save off your pose parameters in member variables in your derivation of this function:
  143. virtual void PopulatePoseParameters( void );
  144. private:
  145. CBoneMergeCache *m_pBoneMergeCache;
  146. public:
  147. CBaseAnimating* FindFollowedEntity();
  148. int LookupBone( const char *szName );
  149. void GetBonePosition( const char *szName, Vector &origin, QAngle &angles );
  150. void GetBonePosition( int iBone, Vector &origin, QAngle &angles );
  151. void GetHitboxBonePosition( int iBone, Vector &origin, QAngle &angles, QAngle hitboxOrientation );
  152. void GetHitboxBoneTransform( int iBone, QAngle hitboxOrientation, matrix3x4_t &pOut );
  153. int GetPhysicsBone( int boneIndex );
  154. int GetNumBones ( void );
  155. int FindTransitionSequence( int iCurrentSequence, int iGoalSequence, int *piDir );
  156. bool GotoSequence( int iCurrentSequence, float flCurrentCycle, float flCurrentRate, int iGoalSequence, int &iNextSequence, float &flCycle, int &iDir );
  157. int GetEntryNode( int iSequence );
  158. int GetExitNode( int iSequence );
  159. void GetEyeballs( Vector &origin, QAngle &angles ); // ?? remove ??
  160. int LookupAttachment( const char *szName );
  161. // These return the attachment in world space
  162. bool GetAttachment( const char *szName, Vector &absOrigin, QAngle &absAngles );
  163. bool GetAttachment( int iAttachment, Vector &absOrigin, QAngle &absAngles );
  164. int GetAttachmentBone( int iAttachment );
  165. virtual bool GetAttachment( int iAttachment, matrix3x4_t &attachmentToWorld );
  166. const Vector& ScriptGetAttachmentOrigin( int iAttachment );
  167. const Vector& ScriptGetAttachmentAngles( int iAttachment );
  168. // These return the attachment in the space of the entity
  169. bool GetAttachmentLocal( const char *szName, Vector &origin, QAngle &angles );
  170. bool GetAttachmentLocal( int iAttachment, Vector &origin, QAngle &angles );
  171. bool GetAttachmentLocal( int iAttachment, matrix3x4_t &attachmentToLocal );
  172. // Non-angle versions of the attachments in world space
  173. bool GetAttachment( const char *szName, Vector &absOrigin, Vector *forward = NULL, Vector *right = NULL, Vector *up = NULL );
  174. bool GetAttachment( int iAttachment, Vector &absOrigin, Vector *forward = NULL, Vector *right = NULL, Vector *up = NULL );
  175. void SetBodygroup( int iGroup, int iValue );
  176. int GetBodygroup( int iGroup );
  177. void SetBodygroupPreset( char const *szName );
  178. int GetSkin() { return m_nSkin; }
  179. const char *GetBodygroupName( int iGroup );
  180. int FindBodygroupByName( const char *name );
  181. const char *GetBodygroupPartName( int iGroup, int iPart );
  182. int GetBodygroupCount( int iGroup );
  183. int GetNumBodyGroups( void );
  184. int CountBodyGroupVariants( int group );
  185. int FindBodyGroupVariant( int group, int variant ); ///< Find undamaged bodygroup part index
  186. int FindDamagedBodyGroupVariant( int group ); ///< Find a damaged version of the current part for the given bodygroup
  187. void RandomizeBodygroups( CUtlVector< const char * >& groups );
  188. void SetHitboxSet( int setnum );
  189. void SetHitboxSetByName( const char *setname );
  190. int GetHitboxSet( void );
  191. char const *GetHitboxSetName( void );
  192. int GetHitboxSetCount( void );
  193. int GetHitboxBone( int hitboxIndex );
  194. bool LookupHitbox( const char *szName, int& outSet, int& outBox );
  195. // Computes a box that surrounds all hitboxes
  196. bool ComputeHitboxSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs );
  197. bool ComputeEntitySpaceHitboxSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs );
  198. // Computes a box that surrounds a single hitboxes
  199. bool ComputeHitboxSurroundingBox( int iHitbox, Vector *pVecWorldMins, Vector *pVecWorldMaxs );
  200. // Clone a CBaseAnimating from another (copies model & sequence data)
  201. void CopyAnimationDataFrom( CBaseAnimating *pSource );
  202. int ExtractBbox( int sequence, Vector& mins, Vector& maxs );
  203. void SetSequenceBox( void );
  204. int RegisterPrivateActivity( const char *pszActivityName );
  205. void ResetClientsideFrame( void );
  206. // Controllers.
  207. virtual void InitBoneControllers ( void );
  208. // Return's the controller's angle/position in bone space.
  209. float GetBoneController ( int iController );
  210. // Maps the angle/position value you specify into the bone's start/end and sets the specified controller to the value.
  211. float SetBoneController ( int iController, float flValue );
  212. void GetVelocity(Vector *vVelocity, AngularImpulse *vAngVelocity);
  213. // these two need to move somewhere else
  214. LocalFlexController_t GetNumFlexControllers( void );
  215. const char *GetFlexDescFacs( int iFlexDesc );
  216. const char *GetFlexControllerName( LocalFlexController_t iFlexController );
  217. const char *GetFlexControllerType( LocalFlexController_t iFlexController );
  218. virtual Vector GetGroundSpeedVelocity( void );
  219. bool GetIntervalMovement( float flIntervalUsed, bool &bMoveSeqFinished, Vector &newPosition, QAngle &newAngles );
  220. bool GetSequenceMovement( int nSequence, float fromCycle, float toCycle, Vector &deltaPosition, QAngle &deltaAngles );
  221. float GetInstantaneousVelocity( float flInterval = 0.0 );
  222. float GetEntryVelocity( int iSequence );
  223. float GetExitVelocity( int iSequence );
  224. float GetMovementFrame( float flDist );
  225. bool HasMovement( int iSequence );
  226. void ReportMissingActivity( int iActivity );
  227. virtual bool TestCollision( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  228. virtual bool TestHitboxes( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  229. class CBoneCache *GetBoneCache( void );
  230. virtual void InvalidateBoneCache( void );
  231. virtual int DrawDebugTextOverlays( void );
  232. virtual bool IsViewModel() const { return false; }
  233. // See note in code re: bandwidth usage!!!
  234. void DrawServerHitboxes( float duration = 0.0f, bool monocolor = false );
  235. void DrawRawSkeleton( matrix3x4_t boneToWorld[], int boneMask, bool noDepthTest = true, float duration = 0.0f, bool monocolor = false );
  236. void SetModelScale( float scale, float change_duration = 0.0f, ModelScaleType_t scaleType = HIERARCHICAL_MODEL_SCALE );
  237. float GetModelScale() const;
  238. float GetModelHierarchyScale(); // Get the overall scale of the entire hierarchy (model scale can be local, per-bone)
  239. ModelScaleType_t GetModelScaleType() const;
  240. void SetModelScaleType( ModelScaleType_t scaleType );
  241. void UpdateModelScale();
  242. // also calculate IK on server? (always done on client)
  243. void EnableServerIK();
  244. void DisableServerIK();
  245. // for ragdoll vs. car
  246. int GetHitboxesFrontside( int *boxList, int boxMax, const Vector &normal, float dist );
  247. virtual void ModifyOrAppendCriteria( AI_CriteriaSet& set );
  248. // Send a muzzle flash event to the client for this entity.
  249. void DoMuzzleFlash();
  250. // Fire
  251. virtual void Ignite( float flFlameLifetime, bool bNPCOnly = true, float flSize = 0.0f, bool bCalledByLevelDesigner = false );
  252. virtual void IgniteLifetime( float flFlameLifetime );
  253. virtual void IgniteUseCheapEffect( bool bUseCheapEffect );
  254. virtual void Extinguish() { RemoveFlag( FL_ONFIRE ); }
  255. bool IsOnFire() { return ( (GetFlags() & FL_ONFIRE) != 0 ); }
  256. void Scorch( int rate, int floor );
  257. void InputIgnite( inputdata_t &inputdata );
  258. void InputIgniteLifetime( inputdata_t &inputdata );
  259. void InputIgniteNumHitboxFires( inputdata_t &inputdata );
  260. void InputIgniteHitboxFireScale( inputdata_t &inputdata );
  261. void InputBecomeRagdoll( inputdata_t &inputdata );
  262. // Ice
  263. virtual bool IsFrozen( void ) { return m_flFrozen >= 1.0f; }
  264. float GetFrozenAmount( void ) const { return m_flFrozen; }
  265. float GetFrozenThawRate( void ) { return m_flFrozenThawRate; }
  266. void Thaw( float flThawAmount );
  267. void ToggleFreeze(void);
  268. virtual void Freeze( float flFreezeAmount = -1.0f, CBaseEntity *pFreezer = NULL, Ray_t *pFreezeRay = NULL );
  269. virtual void Unfreeze();
  270. // Dissolve, returns true if the ragdoll has been created
  271. virtual bool Dissolve( const char *pMaterialName, float flStartTime, bool bNPCOnly = true, int nDissolveType = 0, Vector vDissolverOrigin = vec3_origin, int iMagnitude = 0 );
  272. bool IsDissolving() { return ( (GetFlags() & FL_DISSOLVING) != 0 ); }
  273. void TransferDissolveFrom( CBaseAnimating *pAnim );
  274. // animation needs
  275. float m_flGroundSpeed; // computed linear movement rate for current sequence
  276. float m_flLastEventCheck; // cycle index of when events were last checked
  277. virtual void SetLightingOriginRelative( CBaseEntity *pLightingOriginRelative );
  278. void SetLightingOriginRelative( string_t strLightingOriginRelative );
  279. CBaseEntity *GetLightingOriginRelative();
  280. virtual void SetLightingOrigin( CBaseEntity *pLightingOrigin );
  281. void SetLightingOrigin( string_t strLightingOrigin );
  282. CBaseEntity *GetLightingOrigin();
  283. const float* GetPoseParameterArray() { return m_flPoseParameter.Base(); }
  284. const float* GetEncodedControllerArray() { return m_flEncodedController.Base(); }
  285. void SetFadeDistance( float minFadeDist, float maxFadeDist );
  286. int GetBoneCacheFlags( void ) { return m_fBoneCacheFlags; }
  287. inline void SetBoneCacheFlags( unsigned short fFlag ) { m_fBoneCacheFlags |= fFlag; }
  288. inline void ClearBoneCacheFlags( unsigned short fFlag ) { m_fBoneCacheFlags &= ~fFlag; }
  289. bool PrefetchSequence( int iSequence );
  290. #ifdef PORTAL2
  291. virtual void OnFizzled( void );
  292. #endif // PORTAL2
  293. private:
  294. void LockStudioHdr();
  295. void UnlockStudioHdr();
  296. void StudioFrameAdvanceInternal( CStudioHdr *pStudioHdr, float flInterval );
  297. void InputSetLightingOriginRelative( inputdata_t &inputdata );
  298. void InputSetLightingOrigin( inputdata_t &inputdata );
  299. public:
  300. bool CanSkipAnimation( void );
  301. #ifdef PORTAL2
  302. public:
  303. void SetObjectScaleLevel( int nScaleLevel ) { m_nObjectScaleLevel = nScaleLevel; }
  304. int GetObjectScaleLevel( void ) { return m_nObjectScaleLevel; }
  305. protected:
  306. int m_nObjectScaleLevel;
  307. bool m_bCanBeCaptured; // Set true this prop allows capture by weapon_camera
  308. #endif // PORTAL2
  309. public:
  310. CNetworkVar( int, m_nForceBone );
  311. CNetworkVector( m_vecForce );
  312. CNetworkVar( int, m_nSkin );
  313. CNetworkVar( int, m_nBody );
  314. CNetworkVar( int, m_nHitboxSet );
  315. // For making things thin during barnacle swallowing, e.g.
  316. CNetworkVar( float, m_flModelScale );
  317. // was pev->framerate
  318. CNetworkVar( float, m_flPlaybackRate );
  319. private:
  320. CNetworkVar( ModelScaleType_t, m_ScaleType );
  321. public:
  322. void InitStepHeightAdjust( void );
  323. void SetIKGroundContactInfo( float minHeight, float maxHeight );
  324. void UpdateStepOrigin( void );
  325. protected:
  326. float m_flIKGroundContactTime;
  327. float m_flIKGroundMinHeight;
  328. float m_flIKGroundMaxHeight;
  329. float m_flEstIkFloor; // debounced
  330. float m_flEstIkOffset;
  331. CIKContext *m_pIk;
  332. int m_iIKCounter;
  333. public:
  334. Vector GetStepOrigin( void ) const;
  335. QAngle GetStepAngles( void ) const;
  336. protected:
  337. bool m_bSequenceFinished;// flag set when StudioAdvanceFrame moves across a frame boundry
  338. bool m_bSequenceLoops; // true if the sequence loops
  339. float m_flDissolveStartTime;
  340. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_bClientSideRagdoll );
  341. // was pev->frame
  342. CNetworkVar( float, m_flCycle );
  343. CNetworkVar( int, m_nSequence );
  344. CNetworkArray( float, m_flPoseParameter, NUM_POSEPAREMETERS ); // must be private so manual mode works!
  345. CNetworkArray( float, m_flEncodedController, NUM_BONECTRLS ); // bone controller setting (0..1)
  346. // Client-side animation (useful for looping animation objects)
  347. CNetworkVar( bool, m_bClientSideAnimation );
  348. CNetworkVar( bool, m_bClientSideFrameReset );
  349. CNetworkVar( int, m_nNewSequenceParity );
  350. CNetworkVar( int, m_nResetEventsParity );
  351. CNetworkVar( bool, m_bSuppressAnimSounds );
  352. // Incremented each time the entity is told to do a muzzle flash.
  353. // The client picks up the change and draws the flash.
  354. CNetworkVar( unsigned char, m_nMuzzleFlashParity );
  355. CNetworkHandle( CBaseEntity, m_hLightingOrigin );
  356. CNetworkHandle( CBaseEntity, m_hLightingOriginRelative );
  357. string_t m_iszLightingOriginRelative; // for reading from the file only
  358. string_t m_iszLightingOrigin; // for reading from the file only
  359. memhandle_t m_boneCacheHandle;
  360. unsigned short m_fBoneCacheFlags; // Used for bone cache state on model
  361. CNetworkVar( float, m_flFrozen ); // 0 - 1 amount that the model is frozen
  362. float m_flMovementFrozen; // How frozen are the movement parts
  363. float m_flAttackFrozen; // How frozen are the attacking parts
  364. float m_flFrozenThawRate; // amount it unfreezes per second
  365. float m_flFrozenMax; // maximum amount this entitiy is allowed to freeze
  366. public:
  367. COutputEvent m_OnIgnite;
  368. #if defined ( PORTAL2 )
  369. COutputEvent m_OnFizzled; // Fizzled by a fizzler
  370. #endif // PORTAL2
  371. private:
  372. CStudioHdr *m_pStudioHdr;
  373. CThreadFastMutex m_StudioHdrInitLock;
  374. CThreadFastMutex m_BoneSetupMutex;
  375. // FIXME: necessary so that cyclers can hack m_bSequenceFinished
  376. friend class CBaseAnimatingOverlay;
  377. friend class CFlexCycler;
  378. friend class CCycler;
  379. friend class CBlendingCycler;
  380. };
  381. //-----------------------------------------------------------------------------
  382. // Purpose: return a pointer to an updated studiomdl cache cache
  383. //-----------------------------------------------------------------------------
  384. inline CStudioHdr *CBaseAnimating::GetModelPtr( void )
  385. {
  386. #ifdef _DEBUG
  387. #ifndef _GAMECONSOLE
  388. // Consoles don't need to lock the modeldata cache since it never flushes
  389. // GetModelPtr() is often called before OnNewModel() so go ahead and set it up first chance.
  390. static IDataCacheSection *pModelCache = g_pDataCache->FindSection( "ModelData" );
  391. AssertOnce( pModelCache->IsFrameLocking() );
  392. #endif
  393. #endif
  394. if ( !m_pStudioHdr && GetModel() )
  395. {
  396. LockStudioHdr();
  397. }
  398. return ( m_pStudioHdr && m_pStudioHdr->IsValid() ) ? m_pStudioHdr : NULL;
  399. }
  400. //-----------------------------------------------------------------------------
  401. // Purpose: Serves the 90% case of calling SetSequence / ResetSequenceInfo.
  402. //-----------------------------------------------------------------------------
  403. /*
  404. inline void CBaseAnimating::ResetSequence(int nSequence)
  405. {
  406. if ( nSequence != m_nSequence )
  407. {
  408. m_nSequence = nSequence;
  409. InvalidatePhysicsRecursive( SEQUENCE_CHANGED );
  410. }
  411. ResetSequenceInfo();
  412. }
  413. */
  414. inline float CBaseAnimating::GetPlaybackRate() const
  415. {
  416. #if defined( PORTAL2 )
  417. return m_flPlaybackRate * ( 1.0f / sqrt( GetModelScaleType() == HIERARCHICAL_MODEL_SCALE ? GetModelScale() : 1.0f ) );
  418. #endif // PORTAL2or INFESTED
  419. // Slow the animation while partially frozen
  420. return m_flPlaybackRate * clamp( 1.0f - m_flFrozen, 0.0f, 1.0f );
  421. }
  422. inline void CBaseAnimating::SetPlaybackRate( float rate )
  423. {
  424. // if we start going in a new direction, the current animation isn't finished anymore
  425. m_bSequenceFinished = false;
  426. m_flPlaybackRate = rate;
  427. }
  428. inline void CBaseAnimating::SetLightingOrigin( CBaseEntity *pLightingOrigin )
  429. {
  430. m_hLightingOrigin = pLightingOrigin;
  431. }
  432. inline CBaseEntity *CBaseAnimating::GetLightingOrigin()
  433. {
  434. return m_hLightingOrigin;
  435. }
  436. inline void CBaseAnimating::SetLightingOriginRelative( CBaseEntity *pLightingOriginRelative )
  437. {
  438. m_hLightingOriginRelative = pLightingOriginRelative;
  439. }
  440. inline CBaseEntity *CBaseAnimating::GetLightingOriginRelative()
  441. {
  442. return m_hLightingOriginRelative;
  443. }
  444. //-----------------------------------------------------------------------------
  445. // Cycle access
  446. //-----------------------------------------------------------------------------
  447. inline float CBaseAnimating::GetCycle() const
  448. {
  449. return m_flCycle;
  450. }
  451. inline void CBaseAnimating::SetCycle( float flCycle )
  452. {
  453. m_flCycle = flCycle;
  454. }
  455. inline void CBaseAnimating::ForceCycle( float flCycle )
  456. {
  457. SetCycle( flCycle );
  458. m_flLastEventCheck = flCycle;
  459. }
  460. EXTERN_SEND_TABLE(DT_BaseAnimating);
  461. #define ANIMATION_SEQUENCE_BITS 12 // 4096 sequences
  462. #define ANIMATION_SKIN_BITS 10 // 1024 body skin selections FIXME: this seems way high
  463. #define ANIMATION_BODY_BITS 32 // body combinations
  464. #define ANIMATION_HITBOXSET_BITS 2 // hit box sets
  465. #if defined( TF_DLL )
  466. #define ANIMATION_POSEPARAMETER_BITS 8 // pose parameter resolution
  467. #else
  468. #define ANIMATION_POSEPARAMETER_BITS 11 // pose parameter resolution
  469. #endif
  470. #define ANIMATION_PLAYBACKRATE_BITS 8 // default playback rate, only used on leading edge detect sequence changes
  471. #endif // BASEANIMATING_H