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.

320 lines
8.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // #include "BaseAnimating.h"
  9. #ifndef BASE_ANIMATING_OVERLAY_H
  10. #define BASE_ANIMATING_OVERLAY_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. class CBaseAnimatingOverlay;
  15. class IBoneSetup;
  16. class CAnimationLayer : public CMemZeroOnNew
  17. {
  18. public:
  19. DECLARE_CLASS_NOBASE( CAnimationLayer );
  20. CAnimationLayer( void );
  21. void Init( CBaseAnimatingOverlay *pOverlay );
  22. // float SetBlending( int iBlender, float flValue, CBaseAnimating *pOwner );
  23. void StudioFrameAdvance( float flInterval, CBaseAnimating *pOwner );
  24. void DispatchAnimEvents( CBaseAnimating *eventHandler, CBaseAnimating *pOwner );
  25. void SetOrder( int nOrder );
  26. float GetFadeout( float flCurTime );
  27. // For CNetworkVars.
  28. void NetworkStateChanged();
  29. void NetworkStateChanged( void *pVar );
  30. public:
  31. #define ANIM_LAYER_ACTIVE 0x0001
  32. #define ANIM_LAYER_AUTOKILL 0x0002
  33. #define ANIM_LAYER_KILLME 0x0004
  34. #define ANIM_LAYER_DONTRESTORE 0x0008
  35. #define ANIM_LAYER_CHECKACCESS 0x0010
  36. #define ANIM_LAYER_DYING 0x0020
  37. #define ANIM_LAYER_NOEVENTS 0x0040
  38. int m_fFlags;
  39. bool m_bSequenceFinished;
  40. bool m_bLooping;
  41. CNetworkVar( int, m_nSequence );
  42. CNetworkVar( float, m_flCycle );
  43. CNetworkVar( float, m_flPlaybackRate );
  44. CNetworkVar( float, m_flPrevCycle );
  45. CNetworkVar( float, m_flWeight );
  46. CNetworkVar( float, m_flWeightDeltaRate );
  47. float m_flBlendIn; // start and end blend frac (0.0 for now blend)
  48. float m_flBlendOut;
  49. float m_flKillRate;
  50. float m_flKillDelay;
  51. float m_flLayerAnimtime;
  52. float m_flLayerFadeOuttime;
  53. // dispatch flags
  54. CStudioHdr *m_pDispatchedStudioHdr;
  55. int m_nDispatchedSrc;
  56. int m_nDispatchedDst;
  57. // For checking for duplicates
  58. Activity m_nActivity;
  59. // order of layering on client
  60. int m_nPriority;
  61. CNetworkVar( int, m_nOrder );
  62. int GetOrder( void ) { return m_nOrder; }
  63. bool IsActive( void ) { return ((m_fFlags & ANIM_LAYER_ACTIVE) != 0); }
  64. bool IsAutokill( void ) { return ((m_fFlags & ANIM_LAYER_AUTOKILL) != 0); }
  65. bool IsKillMe( void ) { return ((m_fFlags & ANIM_LAYER_KILLME) != 0); }
  66. bool IsAutoramp( void ) { return (m_flBlendIn != 0.0 || m_flBlendOut != 0.0); }
  67. void KillMe( void ) { m_fFlags |= ANIM_LAYER_KILLME; }
  68. void Dying( void ) { m_fFlags |= ANIM_LAYER_DYING; }
  69. bool IsDying( void ) { return ((m_fFlags & ANIM_LAYER_DYING) != 0); }
  70. void Dead( void ) { m_fFlags &= ~ANIM_LAYER_DYING; }
  71. bool NoEvents( void ) { return ((m_fFlags & ANIM_LAYER_NOEVENTS) != 0); }
  72. void SetSequence( int nSequence );
  73. void SetCycle( float flCycle );
  74. void SetPrevCycle( float flCycle );
  75. void SetPlaybackRate( float flPlaybackRate );
  76. void SetWeight( float flWeight );
  77. void SetWeightDeltaRate( float flDelta );
  78. int GetSequence( ) const;
  79. float GetCycle( ) const;
  80. float GetPrevCycle( ) const;
  81. float GetPlaybackRate( ) const;
  82. float GetWeight( ) const;
  83. float GetWeightDeltaRate( ) const;
  84. bool IsAbandoned( void );
  85. void MarkActive( void );
  86. float m_flLastEventCheck;
  87. float m_flLastAccess;
  88. // Network state changes get forwarded here.
  89. CBaseAnimatingOverlay *m_pOwnerEntity;
  90. DECLARE_SIMPLE_DATADESC();
  91. };
  92. inline float CAnimationLayer::GetFadeout( float flCurTime )
  93. {
  94. float s;
  95. if (m_flLayerFadeOuttime <= 0.0f)
  96. {
  97. s = 0;
  98. }
  99. else
  100. {
  101. // blend in over 0.2 seconds
  102. s = 1.0 - (flCurTime - m_flLayerAnimtime) / m_flLayerFadeOuttime;
  103. if (s > 0 && s <= 1.0)
  104. {
  105. // do a nice spline curve
  106. s = 3 * s * s - 2 * s * s * s;
  107. }
  108. else if ( s > 1.0f )
  109. {
  110. // Shouldn't happen, but maybe curtime is behind animtime?
  111. s = 1.0f;
  112. }
  113. }
  114. return s;
  115. }
  116. FORCEINLINE void CAnimationLayer::SetSequence( int nSequence )
  117. {
  118. m_nSequence = nSequence;
  119. }
  120. FORCEINLINE void CAnimationLayer::SetCycle( float flCycle )
  121. {
  122. m_flCycle = flCycle;
  123. }
  124. FORCEINLINE void CAnimationLayer::SetWeight( float flWeight )
  125. {
  126. m_flWeight = flWeight;
  127. }
  128. FORCEINLINE void CAnimationLayer::SetWeightDeltaRate( float flDelta )
  129. {
  130. m_flWeightDeltaRate = flDelta;
  131. }
  132. FORCEINLINE void CAnimationLayer::SetPrevCycle( float flPrevCycle )
  133. {
  134. m_flPrevCycle = flPrevCycle;
  135. }
  136. FORCEINLINE void CAnimationLayer::SetPlaybackRate( float flPlaybackRate )
  137. {
  138. m_flPlaybackRate = flPlaybackRate;
  139. }
  140. FORCEINLINE int CAnimationLayer::GetSequence( ) const
  141. {
  142. return m_nSequence;
  143. }
  144. FORCEINLINE float CAnimationLayer::GetCycle( ) const
  145. {
  146. return m_flCycle;
  147. }
  148. FORCEINLINE float CAnimationLayer::GetPrevCycle( ) const
  149. {
  150. return m_flPrevCycle;
  151. }
  152. FORCEINLINE float CAnimationLayer::GetPlaybackRate( ) const
  153. {
  154. return m_flPlaybackRate;
  155. }
  156. FORCEINLINE float CAnimationLayer::GetWeight( ) const
  157. {
  158. return m_flWeight;
  159. }
  160. FORCEINLINE float CAnimationLayer::GetWeightDeltaRate( ) const
  161. {
  162. return m_flWeightDeltaRate;
  163. }
  164. class CBaseAnimatingOverlay : public CBaseAnimating
  165. {
  166. DECLARE_CLASS( CBaseAnimatingOverlay, CBaseAnimating );
  167. public:
  168. enum
  169. {
  170. MAX_OVERLAYS = 15,
  171. };
  172. private:
  173. CUtlVector< CAnimationLayer > m_AnimOverlay;
  174. //int m_nActiveLayers;
  175. //int m_nActiveBaseLayers;
  176. public:
  177. virtual CBaseAnimatingOverlay * GetBaseAnimatingOverlay() { return this; }
  178. virtual void OnRestore();
  179. virtual void SetModel( const char *szModelName );
  180. virtual void StudioFrameAdvance();
  181. virtual void DispatchAnimEvents ( CBaseAnimating *eventHandler );
  182. virtual void GetSkeleton( CStudioHdr *pStudioHdr, BoneVector pos[], BoneQuaternionAligned q[], int boneMask );
  183. int AddGestureSequence( int sequence, bool autokill = true );
  184. int AddGestureSequence( int sequence, float flDuration, bool autokill = true );
  185. int AddGesture( Activity activity, bool autokill = true );
  186. int AddGesture( Activity activity, float flDuration, bool autokill = true );
  187. bool IsPlayingGesture( Activity activity );
  188. void RestartGesture( Activity activity, bool addifmissing = true, bool autokill = true );
  189. void RemoveGesture( Activity activity );
  190. void RemoveAllGestures( void );
  191. int AddLayeredSequence( int sequence, int iPriority );
  192. void SetLayerPriority( int iLayer, int iPriority );
  193. bool IsValidLayer( int iLayer );
  194. void SetLayerDuration( int iLayer, float flDuration );
  195. float GetLayerDuration( int iLayer );
  196. void SetLayerCycle( int iLayer, float flCycle );
  197. void SetLayerCycle( int iLayer, float flCycle, float flPrevCycle );
  198. float GetLayerCycle( int iLayer );
  199. void SetLayerPlaybackRate( int iLayer, float flPlaybackRate );
  200. void SetLayerWeight( int iLayer, float flWeight );
  201. float GetLayerWeight( int iLayer );
  202. void SetLayerBlendIn( int iLayer, float flBlendIn );
  203. void SetLayerBlendOut( int iLayer, float flBlendOut );
  204. void SetLayerAutokill( int iLayer, bool bAutokill );
  205. void SetLayerLooping( int iLayer, bool bLooping );
  206. void SetLayerNoRestore( int iLayer, bool bNoRestore );
  207. void SetLayerNoEvents( int iLayer, bool bNoEvents );
  208. Activity GetLayerActivity( int iLayer );
  209. int GetLayerSequence( int iLayer );
  210. int FindGestureLayer( Activity activity );
  211. void RemoveLayer( int iLayer, float flKillRate = 0.2, float flKillDelay = 0.0 );
  212. void FastRemoveLayer( int iLayer );
  213. CAnimationLayer *GetAnimOverlay( int iIndex, bool bUseOrder = true );
  214. int GetNumAnimOverlays() const;
  215. void SetNumAnimOverlays( int num );
  216. void VerifyOrder( void );
  217. bool HasActiveLayer( void );
  218. virtual bool UpdateDispatchLayer( CAnimationLayer *pLayer, CStudioHdr *pWeaponStudioHdr, int iSequence );
  219. void AccumulateDispatchedLayers( CBaseAnimatingOverlay *pWeapon, CStudioHdr *pWeaponStudioHdr, IBoneSetup &boneSetup, BoneVector pos[], BoneQuaternion q[], float currentTime );
  220. void RegenerateDispatchedLayers( IBoneSetup &boneSetup, BoneVector pos[], BoneQuaternion q[], float currentTime );
  221. private:
  222. int AllocateLayer( int iPriority = 0 ); // lower priorities are processed first
  223. DECLARE_SERVERCLASS();
  224. DECLARE_DATADESC();
  225. DECLARE_PREDICTABLE();
  226. };
  227. EXTERN_SEND_TABLE(DT_BaseAnimatingOverlay);
  228. inline int CBaseAnimatingOverlay::GetNumAnimOverlays() const
  229. {
  230. return m_AnimOverlay.Count();
  231. }
  232. // ------------------------------------------------------------------------------------------ //
  233. // CAnimationLayer inlines.
  234. // ------------------------------------------------------------------------------------------ //
  235. inline void CAnimationLayer::SetOrder( int nOrder )
  236. {
  237. m_nOrder = nOrder;
  238. }
  239. inline void CAnimationLayer::NetworkStateChanged()
  240. {
  241. if ( m_pOwnerEntity )
  242. m_pOwnerEntity->NetworkStateChanged();
  243. }
  244. inline void CAnimationLayer::NetworkStateChanged( void *pVar )
  245. {
  246. if ( m_pOwnerEntity )
  247. m_pOwnerEntity->NetworkStateChanged();
  248. }
  249. #endif // BASE_ANIMATING_OVERLAY_H