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.

308 lines
9.5 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. // Client-side CBasePlayer
  9. #ifndef C_STUDIOFLEX_H
  10. #define C_STUDIOFLEX_H
  11. #pragma once
  12. #include "c_baseanimatingoverlay.h"
  13. #include "sceneentity_shared.h"
  14. #include "utlvector.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Item in list of loaded scene files
  17. //-----------------------------------------------------------------------------
  18. class CFlexSceneFile
  19. {
  20. public:
  21. enum
  22. {
  23. MAX_FLEX_FILENAME = 128,
  24. };
  25. char filename[ MAX_FLEX_FILENAME ];
  26. void *buffer;
  27. };
  28. // For phoneme emphasis track
  29. struct Emphasized_Phoneme;
  30. class CSentence;
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. //-----------------------------------------------------------------------------
  34. class C_BaseFlex : public C_BaseAnimatingOverlay
  35. {
  36. DECLARE_CLASS( C_BaseFlex, C_BaseAnimatingOverlay );
  37. public:
  38. DECLARE_CLIENTCLASS();
  39. DECLARE_PREDICTABLE();
  40. DECLARE_INTERPOLATION();
  41. C_BaseFlex();
  42. virtual ~C_BaseFlex();
  43. virtual void Spawn();
  44. virtual IClientModelRenderable* GetClientModelRenderable();
  45. virtual void InitPhonemeMappings();
  46. void SetupMappings( char const *pchFileRoot );
  47. virtual CStudioHdr *OnNewModel( void );
  48. virtual void StandardBlendingRules( CStudioHdr *hdr, BoneVector pos[], BoneQuaternionAligned q[], float currentTime, int boneMask );
  49. virtual void OnThreadedDrawSetup();
  50. // model specific
  51. virtual void BuildTransformations( CStudioHdr *pStudioHdr, BoneVector *pos, BoneQuaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed );
  52. virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights );
  53. virtual bool UsesFlexDelayedWeights();
  54. virtual bool GetSoundSpatialization( SpatializationInfo_t& info );
  55. virtual void GetToolRecordingState( KeyValues *msg );
  56. // Called at the lowest level to actually apply a flex animation
  57. void AddFlexAnimation( CSceneEventInfo *info );
  58. void SetFlexWeight( LocalFlexController_t index, float value );
  59. float GetFlexWeight( LocalFlexController_t index );
  60. // Look up flex controller index by global name
  61. LocalFlexController_t FindFlexController( const char *szName );
  62. public:
  63. Vector m_viewtarget;
  64. CInterpolatedVar< Vector > m_iv_viewtarget;
  65. // indexed by model local flexcontroller
  66. float m_flexWeight[MAXSTUDIOFLEXCTRL];
  67. CInterpolatedVarArray< float, MAXSTUDIOFLEXCTRL > m_iv_flexWeight;
  68. int m_blinktoggle;
  69. static int AddGlobalFlexController( char *szName );
  70. static char const *GetGlobalFlexControllerName( int idx );
  71. // bah, this should be unified with all prev/current stuff.
  72. public:
  73. // Keep track of what scenes are being played
  74. void StartChoreoScene( CChoreoScene *scene );
  75. void RemoveChoreoScene( CChoreoScene *scene );
  76. // Start the specifics of an scene event
  77. virtual bool StartSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event, CChoreoActor *actor, C_BaseEntity *pTarget );
  78. virtual bool ProcessSequenceSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  79. // Remove all playing events
  80. void ClearSceneEvents( CChoreoScene *scene, bool canceled );
  81. // Stop specifics of event
  82. virtual bool ClearSceneEvent( CSceneEventInfo *info, bool fastKill, bool canceled );
  83. // Add the event to the queue for this actor
  84. void AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, C_BaseEntity *pTarget = NULL, bool bClientSide = false, C_SceneEntity *pSceneEntity = NULL );
  85. // Remove the event from the queue for this actor
  86. void RemoveSceneEvent( CChoreoScene *scene, CChoreoEvent *event, bool fastKill );
  87. // Checks to see if the event should be considered "completed"
  88. bool CheckSceneEvent( float currenttime, CChoreoScene *scene, CChoreoEvent *event );
  89. // Checks to see if a event should be considered "completed"
  90. virtual bool CheckSceneEventCompletion( CSceneEventInfo *info, float currenttime, CChoreoScene *scene, CChoreoEvent *event );
  91. int FlexControllerLocalToGlobal( const flexsettinghdr_t *pSettinghdr, int key );
  92. void EnsureTranslations( const flexsettinghdr_t *pSettinghdr );
  93. // For handling scene files
  94. const void *FindSceneFile( const char *filename );
  95. static void InvalidateFlexCaches();
  96. bool IsFlexCacheValid() const;
  97. private:
  98. Vector SetViewTarget( CStudioHdr *pStudioHdr, const float *pGlobalFlexWeight );
  99. void RunFlexRules( CStudioHdr *pStudioHdr, const float *pGlobalFlexWeight, float *dest );
  100. // Manipulation of events for the object
  101. // Should be called by think function to process all scene events
  102. // The default implementation resets m_flexWeight array and calls
  103. // AddSceneEvents
  104. void ProcessSceneEvents( bool bFlexEvents, float *pGlobalFlexWeight );
  105. // Assumes m_flexWeight array has been set up, this adds the actual currently playing
  106. // expressions to the flex weights and adds other scene events as needed
  107. bool ProcessSceneEvent( float *pGlobalFlexWeight, bool bFlexEvents, CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  108. bool RequestStartSequenceSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event, CChoreoActor *actor, CBaseEntity *pTarget );
  109. bool ProcessFlexAnimationSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  110. bool ProcessFlexSettingSceneEvent( float *pGlobalFlexWeight, CSceneEventInfo *info, CChoreoScene *scene, CChoreoEvent *event );
  111. void AddFlexSetting( float *pGlobalFlexWeight, const char *expr, float scale,
  112. const flexsettinghdr_t *pSettinghdr, bool newexpression );
  113. // Array of active SceneEvents, in order oldest to newest
  114. CUtlVector < CSceneEventInfo > m_SceneEvents;
  115. CUtlVector < CChoreoScene * > m_ActiveChoreoScenes;
  116. bool HasSceneEvents() const;
  117. private:
  118. // Mapping for each loaded scene file used by this actor
  119. struct FS_LocalToGlobal_t
  120. {
  121. explicit FS_LocalToGlobal_t() :
  122. m_Key( 0 ),
  123. m_nCount( 0 ),
  124. m_Mapping( 0 )
  125. {
  126. }
  127. explicit FS_LocalToGlobal_t( const flexsettinghdr_t *key ) :
  128. m_Key( key ),
  129. m_nCount( 0 ),
  130. m_Mapping( 0 )
  131. {
  132. }
  133. void SetCount( int count )
  134. {
  135. Assert( !m_Mapping );
  136. Assert( count > 0 );
  137. m_nCount = count;
  138. m_Mapping = new int[ m_nCount ];
  139. Q_memset( m_Mapping, 0, m_nCount * sizeof( int ) );
  140. }
  141. FS_LocalToGlobal_t( const FS_LocalToGlobal_t& src )
  142. {
  143. m_Key = src.m_Key;
  144. delete m_Mapping;
  145. m_Mapping = new int[ src.m_nCount ];
  146. Q_memcpy( m_Mapping, src.m_Mapping, src.m_nCount * sizeof( int ) );
  147. m_nCount = src.m_nCount;
  148. }
  149. ~FS_LocalToGlobal_t()
  150. {
  151. delete m_Mapping;
  152. m_nCount = 0;
  153. m_Mapping = 0;
  154. }
  155. const flexsettinghdr_t *m_Key;
  156. int m_nCount;
  157. int *m_Mapping;
  158. };
  159. static bool FlexSettingLessFunc( const FS_LocalToGlobal_t& lhs, const FS_LocalToGlobal_t& rhs );
  160. CUtlRBTree< FS_LocalToGlobal_t, unsigned short > m_LocalToGlobal;
  161. float m_blinktime;
  162. int m_prevblinktoggle;
  163. int m_iBlink;
  164. LocalFlexController_t m_iEyeUpdown;
  165. LocalFlexController_t m_iEyeRightleft;
  166. int m_iMouthAttachment;
  167. float *m_flFlexDelayedWeight;
  168. int m_iMostRecentFlexCounter;
  169. Vector m_CachedViewTarget;
  170. CUtlVector< float > m_CachedFlexWeights;
  171. CUtlVector< float > m_CachedDelayedFlexWeights;
  172. // shared flex controllers
  173. static int g_numflexcontrollers;
  174. static char *g_flexcontroller[MAXSTUDIOFLEXCTRL*4]; // room for global set of flexcontrollers
  175. static float s_pGlobalFlexWeight[MAXSTUDIOFLEXCTRL*4];
  176. protected:
  177. enum
  178. {
  179. PHONEME_CLASS_WEAK = 0,
  180. PHONEME_CLASS_NORMAL,
  181. PHONEME_CLASS_STRONG,
  182. NUM_PHONEME_CLASSES
  183. };
  184. //-----------------------------------------------------------------------------
  185. // Purpose:
  186. //-----------------------------------------------------------------------------
  187. struct Emphasized_Phoneme
  188. {
  189. // Global fields, setup at start
  190. char classname[ 64 ];
  191. bool required;
  192. // Global fields setup first time tracks played
  193. bool basechecked;
  194. const flexsettinghdr_t *base;
  195. const flexsetting_t *exp;
  196. // Local fields, processed for each sentence
  197. bool valid;
  198. float amount;
  199. };
  200. Emphasized_Phoneme m_PhonemeClasses[ NUM_PHONEME_CLASSES ];
  201. private:
  202. C_BaseFlex( const C_BaseFlex & ); // not defined, not accessible
  203. const flexsetting_t *FindNamedSetting( const flexsettinghdr_t *pSettinghdr, const char *expr );
  204. void ProcessVisemes( Emphasized_Phoneme *classes, float *pGlobalFlexWeight );
  205. void AddVisemesForSentence( float *pGlobalFlexWeight, Emphasized_Phoneme *classes, float emphasis_intensity, CSentence *sentence, float t, float dt, bool juststarted );
  206. void AddViseme( float *pGlobalFlexWeight, Emphasized_Phoneme *classes, float emphasis_intensity, int phoneme, float scale, bool newexpression );
  207. bool SetupEmphasisBlend( Emphasized_Phoneme *classes, int phoneme );
  208. void ComputeBlendedSetting( Emphasized_Phoneme *classes, float emphasis_intensity );
  209. #ifdef HL2_CLIENT_DLL
  210. public:
  211. Vector m_vecLean;
  212. CInterpolatedVar< Vector > m_iv_vecLean;
  213. Vector m_vecShift;
  214. CInterpolatedVar< Vector > m_iv_vecShift;
  215. #endif
  216. };
  217. //-----------------------------------------------------------------------------
  218. // Do we have active expressions?
  219. //-----------------------------------------------------------------------------
  220. inline bool C_BaseFlex::HasSceneEvents() const
  221. {
  222. return m_SceneEvents.Count() != 0;
  223. }
  224. EXTERN_RECV_TABLE(DT_BaseFlex);
  225. float *GetVisemeWeights( int phoneme );
  226. #endif // C_STUDIOFLEX_H