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.

232 lines
6.0 KiB

  1. //========= Copyright 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 CAnimationLayer
  16. {
  17. public:
  18. DECLARE_CLASS_NOBASE( CAnimationLayer );
  19. CAnimationLayer( void );
  20. void Init( CBaseAnimatingOverlay *pOverlay );
  21. // float SetBlending( int iBlender, float flValue, CBaseAnimating *pOwner );
  22. void StudioFrameAdvance( float flInterval, CBaseAnimating *pOwner );
  23. void DispatchAnimEvents( CBaseAnimating *eventHandler, CBaseAnimating *pOwner );
  24. void SetOrder( int nOrder );
  25. float GetFadeout( float flCurTime );
  26. // For CNetworkVars.
  27. void NetworkStateChanged();
  28. void NetworkStateChanged( void *pVar );
  29. public:
  30. #define ANIM_LAYER_ACTIVE 0x0001
  31. #define ANIM_LAYER_AUTOKILL 0x0002
  32. #define ANIM_LAYER_KILLME 0x0004
  33. #define ANIM_LAYER_DONTRESTORE 0x0008
  34. #define ANIM_LAYER_CHECKACCESS 0x0010
  35. #define ANIM_LAYER_DYING 0x0020
  36. int m_fFlags;
  37. bool m_bSequenceFinished;
  38. bool m_bLooping;
  39. CNetworkVar( int, m_nSequence );
  40. CNetworkVar( float, m_flCycle );
  41. CNetworkVar( float, m_flPrevCycle );
  42. CNetworkVar( float, m_flWeight );
  43. float m_flPlaybackRate;
  44. float m_flBlendIn; // start and end blend frac (0.0 for now blend)
  45. float m_flBlendOut;
  46. float m_flKillRate;
  47. float m_flKillDelay;
  48. float m_flLayerAnimtime;
  49. float m_flLayerFadeOuttime;
  50. // For checking for duplicates
  51. Activity m_nActivity;
  52. // order of layering on client
  53. int m_nPriority;
  54. CNetworkVar( int, m_nOrder );
  55. bool IsActive( void ) { return ((m_fFlags & ANIM_LAYER_ACTIVE) != 0); }
  56. bool IsAutokill( void ) { return ((m_fFlags & ANIM_LAYER_AUTOKILL) != 0); }
  57. bool IsKillMe( void ) { return ((m_fFlags & ANIM_LAYER_KILLME) != 0); }
  58. bool IsAutoramp( void ) { return (m_flBlendIn != 0.0 || m_flBlendOut != 0.0); }
  59. void KillMe( void ) { m_fFlags |= ANIM_LAYER_KILLME; }
  60. void Dying( void ) { m_fFlags |= ANIM_LAYER_DYING; }
  61. bool IsDying( void ) { return ((m_fFlags & ANIM_LAYER_DYING) != 0); }
  62. void Dead( void ) { m_fFlags &= ~ANIM_LAYER_DYING; }
  63. bool IsAbandoned( void );
  64. void MarkActive( void );
  65. float m_flLastEventCheck;
  66. float m_flLastAccess;
  67. // Network state changes get forwarded here.
  68. CBaseAnimatingOverlay *m_pOwnerEntity;
  69. DECLARE_SIMPLE_DATADESC();
  70. };
  71. inline float CAnimationLayer::GetFadeout( float flCurTime )
  72. {
  73. float s;
  74. if (m_flLayerFadeOuttime <= 0.0f)
  75. {
  76. s = 0;
  77. }
  78. else
  79. {
  80. // blend in over 0.2 seconds
  81. s = 1.0 - (flCurTime - m_flLayerAnimtime) / m_flLayerFadeOuttime;
  82. if (s > 0 && s <= 1.0)
  83. {
  84. // do a nice spline curve
  85. s = 3 * s * s - 2 * s * s * s;
  86. }
  87. else if ( s > 1.0f )
  88. {
  89. // Shouldn't happen, but maybe curtime is behind animtime?
  90. s = 1.0f;
  91. }
  92. }
  93. return s;
  94. }
  95. class CBaseAnimatingOverlay : public CBaseAnimating
  96. {
  97. DECLARE_CLASS( CBaseAnimatingOverlay, CBaseAnimating );
  98. public:
  99. enum
  100. {
  101. MAX_OVERLAYS = 15,
  102. };
  103. private:
  104. CUtlVector< CAnimationLayer > m_AnimOverlay;
  105. //int m_nActiveLayers;
  106. //int m_nActiveBaseLayers;
  107. public:
  108. virtual void OnRestore();
  109. virtual void StudioFrameAdvance();
  110. virtual void DispatchAnimEvents ( CBaseAnimating *eventHandler );
  111. virtual void GetSkeleton( CStudioHdr *pStudioHdr, Vector pos[], Quaternion q[], int boneMask );
  112. int AddGestureSequence( int sequence, bool autokill = true );
  113. int AddGestureSequence( int sequence, float flDuration, bool autokill = true );
  114. int AddGesture( Activity activity, bool autokill = true );
  115. int AddGesture( Activity activity, float flDuration, bool autokill = true );
  116. bool IsPlayingGesture( Activity activity );
  117. void RestartGesture( Activity activity, bool addifmissing = true, bool autokill = true );
  118. void RemoveGesture( Activity activity );
  119. void RemoveAllGestures( void );
  120. int AddLayeredSequence( int sequence, int iPriority );
  121. void SetLayerPriority( int iLayer, int iPriority );
  122. bool IsValidLayer( int iLayer );
  123. void SetLayerDuration( int iLayer, float flDuration );
  124. float GetLayerDuration( int iLayer );
  125. void SetLayerCycle( int iLayer, float flCycle );
  126. void SetLayerCycle( int iLayer, float flCycle, float flPrevCycle );
  127. void SetLayerCycle( int iLayer, float flCycle, float flPrevCycle, float flLastEventCheck );
  128. float GetLayerCycle( int iLayer );
  129. void SetLayerPlaybackRate( int iLayer, float flPlaybackRate );
  130. void SetLayerWeight( int iLayer, float flWeight );
  131. float GetLayerWeight( int iLayer );
  132. void SetLayerBlendIn( int iLayer, float flBlendIn );
  133. void SetLayerBlendOut( int iLayer, float flBlendOut );
  134. void SetLayerAutokill( int iLayer, bool bAutokill );
  135. void SetLayerLooping( int iLayer, bool bLooping );
  136. void SetLayerNoRestore( int iLayer, bool bNoRestore );
  137. Activity GetLayerActivity( int iLayer );
  138. int GetLayerSequence( int iLayer );
  139. int FindGestureLayer( Activity activity );
  140. void RemoveLayer( int iLayer, float flKillRate = 0.2, float flKillDelay = 0.0 );
  141. void FastRemoveLayer( int iLayer );
  142. CAnimationLayer *GetAnimOverlay( int iIndex );
  143. int GetNumAnimOverlays() const;
  144. void SetNumAnimOverlays( int num );
  145. void VerifyOrder( void );
  146. bool HasActiveLayer( void );
  147. private:
  148. int AllocateLayer( int iPriority = 0 ); // lower priorities are processed first
  149. DECLARE_SERVERCLASS();
  150. DECLARE_DATADESC();
  151. DECLARE_PREDICTABLE();
  152. };
  153. EXTERN_SEND_TABLE(DT_BaseAnimatingOverlay);
  154. inline int CBaseAnimatingOverlay::GetNumAnimOverlays() const
  155. {
  156. return m_AnimOverlay.Count();
  157. }
  158. // ------------------------------------------------------------------------------------------ //
  159. // CAnimationLayer inlines.
  160. // ------------------------------------------------------------------------------------------ //
  161. inline void CAnimationLayer::SetOrder( int nOrder )
  162. {
  163. m_nOrder = nOrder;
  164. }
  165. inline void CAnimationLayer::NetworkStateChanged()
  166. {
  167. if ( m_pOwnerEntity )
  168. m_pOwnerEntity->NetworkStateChanged();
  169. }
  170. inline void CAnimationLayer::NetworkStateChanged( void *pVar )
  171. {
  172. if ( m_pOwnerEntity )
  173. m_pOwnerEntity->NetworkStateChanged();
  174. }
  175. #endif // BASE_ANIMATING_OVERLAY_H