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.

327 lines
8.7 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef MULTIPLAYERANIMSTATE_H
  7. #define MULTIPLAYERANIMSTATE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "convar.h"
  12. #if defined( CLIENT_DLL )
  13. class C_BasePlayer;
  14. #define CPlayer C_BasePlayer
  15. #else
  16. class CBasePlayer;
  17. #endif
  18. enum PlayerAnimEvent_t
  19. {
  20. PLAYERANIMEVENT_ATTACK_PRIMARY,
  21. PLAYERANIMEVENT_ATTACK_SECONDARY,
  22. PLAYERANIMEVENT_ATTACK_GRENADE,
  23. PLAYERANIMEVENT_RELOAD,
  24. PLAYERANIMEVENT_RELOAD_LOOP,
  25. PLAYERANIMEVENT_RELOAD_END,
  26. PLAYERANIMEVENT_JUMP,
  27. PLAYERANIMEVENT_SWIM,
  28. PLAYERANIMEVENT_DIE,
  29. PLAYERANIMEVENT_FLINCH_CHEST,
  30. PLAYERANIMEVENT_FLINCH_HEAD,
  31. PLAYERANIMEVENT_FLINCH_LEFTARM,
  32. PLAYERANIMEVENT_FLINCH_RIGHTARM,
  33. PLAYERANIMEVENT_FLINCH_LEFTLEG,
  34. PLAYERANIMEVENT_FLINCH_RIGHTLEG,
  35. PLAYERANIMEVENT_DOUBLEJUMP,
  36. // Cancel.
  37. PLAYERANIMEVENT_CANCEL,
  38. PLAYERANIMEVENT_SPAWN,
  39. // Snap to current yaw exactly
  40. PLAYERANIMEVENT_SNAP_YAW,
  41. PLAYERANIMEVENT_CUSTOM, // Used to play specific activities
  42. PLAYERANIMEVENT_CUSTOM_GESTURE,
  43. PLAYERANIMEVENT_CUSTOM_SEQUENCE, // Used to play specific sequences
  44. PLAYERANIMEVENT_CUSTOM_GESTURE_SEQUENCE,
  45. // TF Specific. Here until there's a derived game solution to this.
  46. PLAYERANIMEVENT_ATTACK_PRE,
  47. PLAYERANIMEVENT_ATTACK_POST,
  48. PLAYERANIMEVENT_GRENADE1_DRAW,
  49. PLAYERANIMEVENT_GRENADE2_DRAW,
  50. PLAYERANIMEVENT_GRENADE1_THROW,
  51. PLAYERANIMEVENT_GRENADE2_THROW,
  52. PLAYERANIMEVENT_VOICE_COMMAND_GESTURE,
  53. PLAYERANIMEVENT_COUNT
  54. };
  55. // Gesture Slots.
  56. enum
  57. {
  58. GESTURE_SLOT_ATTACK_AND_RELOAD,
  59. GESTURE_SLOT_GRENADE,
  60. GESTURE_SLOT_JUMP,
  61. GESTURE_SLOT_SWIM,
  62. GESTURE_SLOT_FLINCH,
  63. GESTURE_SLOT_VCD,
  64. GESTURE_SLOT_CUSTOM,
  65. GESTURE_SLOT_COUNT,
  66. };
  67. #define GESTURE_SLOT_INVALID -1
  68. struct GestureSlot_t
  69. {
  70. int m_iGestureSlot;
  71. Activity m_iActivity;
  72. bool m_bAutoKill;
  73. bool m_bActive;
  74. CAnimationLayer *m_pAnimLayer;
  75. };
  76. inline bool IsCustomPlayerAnimEvent( PlayerAnimEvent_t event )
  77. {
  78. return ( event == PLAYERANIMEVENT_CUSTOM ) || ( event == PLAYERANIMEVENT_CUSTOM_GESTURE ) ||
  79. ( event == PLAYERANIMEVENT_CUSTOM_SEQUENCE ) || ( event == PLAYERANIMEVENT_CUSTOM_GESTURE_SEQUENCE );
  80. }
  81. struct MultiPlayerPoseData_t
  82. {
  83. int m_iMoveX;
  84. int m_iMoveY;
  85. int m_iAimYaw;
  86. int m_iAimPitch;
  87. int m_iBodyHeight;
  88. float m_flEstimateYaw;
  89. float m_flLastAimTurnTime;
  90. void Init()
  91. {
  92. m_iMoveX = 0;
  93. m_iMoveY = 0;
  94. m_iAimYaw = 0;
  95. m_iAimPitch = 0;
  96. m_iBodyHeight = 0;
  97. m_flEstimateYaw = 0.0f;
  98. m_flLastAimTurnTime = 0.0f;
  99. }
  100. };
  101. struct DebugPlayerAnimData_t
  102. {
  103. float m_flSpeed;
  104. float m_flAimPitch;
  105. float m_flAimYaw;
  106. float m_flBodyHeight;
  107. Vector2D m_vecMoveYaw;
  108. void Init()
  109. {
  110. m_flSpeed = 0.0f;
  111. m_flAimPitch = 0.0f;
  112. m_flAimYaw = 0.0f;
  113. m_flBodyHeight = 0.0f;
  114. m_vecMoveYaw.Init();
  115. }
  116. };
  117. struct MultiPlayerMovementData_t
  118. {
  119. // Set speeds to -1 if they are not used.
  120. float m_flWalkSpeed;
  121. float m_flRunSpeed;
  122. float m_flSprintSpeed;
  123. float m_flBodyYawRate;
  124. };
  125. //=============================================================================
  126. //
  127. // Multi-Player Animation State
  128. //
  129. class CBaseCombatWeapon;
  130. class CBasePlayer;
  131. class CMultiPlayerAnimState
  132. {
  133. public:
  134. DECLARE_CLASS_NOBASE( CMultiPlayerAnimState );
  135. // Creation/Destruction
  136. CMultiPlayerAnimState() {}
  137. CMultiPlayerAnimState( CBasePlayer *pPlayer, MultiPlayerMovementData_t &movementData );
  138. ~CMultiPlayerAnimState();
  139. // This is called by both the client and the server in the same way to trigger events for
  140. // players firing, jumping, throwing grenades, etc.
  141. virtual void ClearAnimationState();
  142. virtual void DoAnimationEvent( PlayerAnimEvent_t event, int nData = 0 );
  143. virtual Activity CalcMainActivity();
  144. virtual void Update( float eyeYaw, float eyePitch );
  145. virtual void Release( void );
  146. const QAngle &GetRenderAngles();
  147. virtual Activity TranslateActivity( Activity actDesired );
  148. virtual void SetRunSpeed( float flSpeed ) { m_MovementData.m_flRunSpeed = flSpeed; }
  149. virtual void SetWalkSpeed( float flSpeed ) { m_MovementData.m_flWalkSpeed = flSpeed; }
  150. virtual void SetSprintSpeed( float flSpeed ) { m_MovementData.m_flSprintSpeed = flSpeed; }
  151. // Debug
  152. virtual void ShowDebugInfo( void );
  153. virtual void DebugShowAnimState( int iStartLine );
  154. Activity GetCurrentMainActivity( void ) { return m_eCurrentMainSequenceActivity; }
  155. void OnNewModel( void );
  156. // Gestures.
  157. void ResetGestureSlots( void );
  158. void ResetGestureSlot( int iGestureSlot );
  159. void AddVCDSequenceToGestureSlot( int iGestureSlot, int iGestureSequence, bool bAutoKill = true );
  160. // Feet.
  161. bool m_bForceAimYaw;
  162. protected:
  163. virtual void Init( CBasePlayer *pPlayer, MultiPlayerMovementData_t &movementData );
  164. CBasePlayer *GetBasePlayer( void ) { return m_pPlayer; }
  165. // Allow inheriting classes to override SelectWeightedSequence
  166. virtual int SelectWeightedSequence( Activity activity ) { return GetBasePlayer()->SelectWeightedSequence( activity ); }
  167. virtual void RestartMainSequence();
  168. void GetOuterAbsVelocity( Vector& vel );
  169. float GetOuterXYSpeed();
  170. virtual bool HandleJumping( Activity &idealActivity );
  171. virtual bool HandleDucking( Activity &idealActivity );
  172. virtual bool HandleMoving( Activity &idealActivity );
  173. virtual bool HandleSwimming( Activity &idealActivity );
  174. virtual bool HandleDying( Activity &idealActivity );
  175. // Gesture Slots
  176. CUtlVector<GestureSlot_t> m_aGestureSlots;
  177. bool InitGestureSlots( void );
  178. void ShutdownGestureSlots( void );
  179. bool IsGestureSlotActive( int iGestureSlot );
  180. bool IsGestureSlotPlaying( int iGestureSlot, Activity iGestureActivity );
  181. void AddToGestureSlot( int iGestureSlot, Activity iGestureActivity, bool bAutoKill );
  182. void RestartGesture( int iGestureSlot, Activity iGestureActivity, bool bAutoKill = true );
  183. void ComputeGestureSequence( CStudioHdr *pStudioHdr );
  184. void UpdateGestureLayer( CStudioHdr *pStudioHdr, GestureSlot_t *pGesture );
  185. void DebugGestureInfo( void );
  186. #ifdef CLIENT_DLL
  187. void RunGestureSlotAnimEventsToCompletion( GestureSlot_t *pGesture );
  188. #endif
  189. virtual void PlayFlinchGesture( Activity iActivity );
  190. virtual float CalcMovementPlaybackRate( bool *bIsMoving );
  191. // Pose paramters.
  192. virtual bool SetupPoseParameters( CStudioHdr *pStudioHdr );
  193. virtual void ComputePoseParam_MoveYaw( CStudioHdr *pStudioHdr );
  194. virtual void ComputePoseParam_AimPitch( CStudioHdr *pStudioHdr );
  195. virtual void ComputePoseParam_AimYaw( CStudioHdr *pStudioHdr );
  196. void ComputePoseParam_BodyHeight( CStudioHdr *pStudioHdr );
  197. virtual void EstimateYaw( void );
  198. void ConvergeYawAngles( float flGoalYaw, float flYawRate, float flDeltaTime, float &flCurrentYaw );
  199. virtual float GetCurrentMaxGroundSpeed();
  200. virtual void ComputeSequences( CStudioHdr *pStudioHdr );
  201. void ComputeMainSequence();
  202. void UpdateInterpolators();
  203. void ResetGroundSpeed( void );
  204. float GetInterpolatedGroundSpeed( void );
  205. void ComputeFireSequence();
  206. void ComputeDeployedSequence();
  207. bool ShouldUpdateAnimState();
  208. void DebugShowAnimStateForPlayer( bool bIsServer );
  209. void DebugShowEyeYaw( void );
  210. // Client specific.
  211. #ifdef CLIENT_DLL
  212. // Debug.
  213. void DebugShowActivity( Activity activity );
  214. #endif
  215. protected:
  216. CBasePlayer *m_pPlayer;
  217. QAngle m_angRender;
  218. #if defined( PORTAL ) && defined( CLIENT_DLL )
  219. QAngle m_angRender_InterpHistory; //discontinuous space handling
  220. #endif
  221. // Pose parameters.
  222. bool m_bPoseParameterInit;
  223. MultiPlayerPoseData_t m_PoseParameterData;
  224. DebugPlayerAnimData_t m_DebugAnimData;
  225. bool m_bCurrentFeetYawInitialized;
  226. float m_flLastAnimationStateClearTime;
  227. float m_flEyeYaw;
  228. float m_flEyePitch;
  229. float m_flGoalFeetYaw;
  230. float m_flCurrentFeetYaw;
  231. float m_flLastAimTurnTime;
  232. MultiPlayerMovementData_t m_MovementData;
  233. // Jumping.
  234. bool m_bJumping;
  235. float m_flJumpStartTime;
  236. bool m_bFirstJumpFrame;
  237. // Swimming.
  238. bool m_bInSwim;
  239. bool m_bFirstSwimFrame;
  240. // Dying
  241. bool m_bDying;
  242. bool m_bFirstDyingFrame;
  243. // Last activity we've used on the lower body. Used to determine if animations should restart.
  244. Activity m_eCurrentMainSequenceActivity;
  245. // Specific full-body sequence to play
  246. int m_nSpecificMainSequence;
  247. // Weapon data.
  248. CHandle<CBaseCombatWeapon> m_hActiveWeapon;
  249. // Ground speed interpolators.
  250. #ifdef CLIENT_DLL
  251. float m_flLastGroundSpeedUpdateTime;
  252. CInterpolatedVar<float> m_iv_flMaxGroundSpeed;
  253. #endif
  254. float m_flMaxGroundSpeed;
  255. };
  256. // If this is set, then the game code needs to make sure to send player animation events
  257. // to the local player if he's the one being watched.
  258. extern ConVar cl_showanimstate;
  259. #endif // DOD_PLAYERANIMSTATE_H