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.

444 lines
12 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef CSGO_PLAYERANIMSTATE_H
  7. #define CSGO_PLAYERANIMSTATE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "iplayeranimstate.h"
  12. #include "studio.h"
  13. #include "sequence_Transitioner.h"
  14. #include "cs_weapon_parse.h"
  15. #ifdef CLIENT_DLL
  16. #define CCSPlayer C_CSPlayer
  17. #endif
  18. class CCSPlayer;
  19. enum animstate_layer_t
  20. {
  21. ANIMATION_LAYER_AIMMATRIX = 0,
  22. ANIMATION_LAYER_WEAPON_ACTION,
  23. ANIMATION_LAYER_WEAPON_ACTION_RECROUCH,
  24. ANIMATION_LAYER_ADJUST,
  25. ANIMATION_LAYER_MOVEMENT_JUMP_OR_FALL,
  26. ANIMATION_LAYER_MOVEMENT_LAND_OR_CLIMB,
  27. ANIMATION_LAYER_MOVEMENT_MOVE,
  28. ANIMATION_LAYER_MOVEMENT_STRAFECHANGE,
  29. ANIMATION_LAYER_WHOLE_BODY,
  30. ANIMATION_LAYER_FLASHED,
  31. ANIMATION_LAYER_FLINCH,
  32. ANIMATION_LAYER_ALIVELOOP,
  33. ANIMATION_LAYER_LEAN,
  34. ANIMATION_LAYER_COUNT,
  35. };
  36. #define USE_ANIMLAYER_RAW_INDEX false
  37. typedef const int* animlayerpreset;
  38. #define get_animlayerpreset( _n ) s_animLayerOrder ## _n
  39. #define REGISTER_ANIMLAYER_ORDER( _n ) static const int s_animLayerOrder ## _n [ANIMATION_LAYER_COUNT]
  40. REGISTER_ANIMLAYER_ORDER( Default ) = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
  41. // animations can trigger the player to re-order their layers according to hardcoded presets, e.g.:
  42. REGISTER_ANIMLAYER_ORDER( WeaponPost ) = {
  43. ANIMATION_LAYER_AIMMATRIX,
  44. ANIMATION_LAYER_WEAPON_ACTION_RECROUCH,
  45. ANIMATION_LAYER_ADJUST,
  46. ANIMATION_LAYER_MOVEMENT_JUMP_OR_FALL,
  47. ANIMATION_LAYER_MOVEMENT_LAND_OR_CLIMB,
  48. ANIMATION_LAYER_MOVEMENT_MOVE,
  49. ANIMATION_LAYER_MOVEMENT_STRAFECHANGE,
  50. ANIMATION_LAYER_WEAPON_ACTION,
  51. ANIMATION_LAYER_WHOLE_BODY,
  52. ANIMATION_LAYER_FLASHED,
  53. ANIMATION_LAYER_FLINCH,
  54. ANIMATION_LAYER_ALIVELOOP,
  55. ANIMATION_LAYER_LEAN,
  56. };
  57. enum animstate_pose_param_idx_t
  58. {
  59. PLAYER_POSE_PARAM_FIRST = 0,
  60. PLAYER_POSE_PARAM_LEAN_YAW = PLAYER_POSE_PARAM_FIRST,
  61. PLAYER_POSE_PARAM_SPEED,
  62. PLAYER_POSE_PARAM_LADDER_SPEED,
  63. PLAYER_POSE_PARAM_LADDER_YAW,
  64. PLAYER_POSE_PARAM_MOVE_YAW,
  65. PLAYER_POSE_PARAM_RUN,
  66. PLAYER_POSE_PARAM_BODY_YAW,
  67. PLAYER_POSE_PARAM_BODY_PITCH,
  68. PLAYER_POSE_PARAM_DEATH_YAW,
  69. PLAYER_POSE_PARAM_STAND,
  70. PLAYER_POSE_PARAM_JUMP_FALL,
  71. PLAYER_POSE_PARAM_AIM_BLEND_STAND_IDLE,
  72. PLAYER_POSE_PARAM_AIM_BLEND_CROUCH_IDLE,
  73. PLAYER_POSE_PARAM_STRAFE_DIR,
  74. PLAYER_POSE_PARAM_AIM_BLEND_STAND_WALK,
  75. PLAYER_POSE_PARAM_AIM_BLEND_STAND_RUN,
  76. PLAYER_POSE_PARAM_AIM_BLEND_CROUCH_WALK,
  77. PLAYER_POSE_PARAM_MOVE_BLEND_WALK,
  78. PLAYER_POSE_PARAM_MOVE_BLEND_RUN,
  79. PLAYER_POSE_PARAM_MOVE_BLEND_CROUCH_WALK,
  80. //PLAYER_POSE_PARAM_STRAFE_CROSS,
  81. PLAYER_POSE_PARAM_COUNT,
  82. };
  83. struct animstate_pose_param_cache_t
  84. {
  85. bool m_bInitialized;
  86. int m_nIndex;
  87. const char* m_szName;
  88. animstate_pose_param_cache_t()
  89. {
  90. m_bInitialized = false;
  91. m_nIndex = -1;
  92. m_szName = "";
  93. }
  94. int GetIndex( void );
  95. float GetValue( CCSPlayer* pPlayer );
  96. void SetValue( CCSPlayer* pPlayer, float flValue );
  97. bool Init( CCSPlayer* pPlayer, const char* szPoseParamName );
  98. };
  99. #define MAX_ANIMSTATE_ANIMNAME_CHARS 64
  100. #define ANIM_TRANSITION_WALK_TO_RUN 0
  101. #define ANIM_TRANSITION_RUN_TO_WALK 1
  102. //these correlate to the CSWeaponType enum
  103. const char* const g_szWeaponPrefixLookupTable[] = {
  104. "knife",
  105. "pistol",
  106. "smg",
  107. "rifle",
  108. "shotgun",
  109. "sniper",
  110. "heavy",
  111. "c4",
  112. "grenade",
  113. "knife"
  114. };
  115. struct procedural_foot_t
  116. {
  117. Vector m_vecPosAnim;
  118. Vector m_vecPosAnimLast;
  119. Vector m_vecPosPlant;
  120. Vector m_vecPlantVel;
  121. float m_flLockAmount;
  122. float m_flLastPlantTime;
  123. procedural_foot_t()
  124. {
  125. m_vecPosAnim.Init();
  126. m_vecPosAnimLast.Init();
  127. m_vecPosPlant.Init();
  128. m_vecPlantVel.Init();
  129. m_flLockAmount = 0;
  130. m_flLastPlantTime = gpGlobals->curtime;
  131. }
  132. void Init( Vector vecNew )
  133. {
  134. m_vecPosAnim = vecNew;
  135. m_vecPosAnimLast = vecNew;
  136. m_vecPosPlant = vecNew;
  137. m_vecPlantVel.Init();
  138. m_flLockAmount = 0;
  139. m_flLastPlantTime = gpGlobals->curtime;
  140. }
  141. };
  142. struct aimmatrix_transition_t
  143. {
  144. float m_flDurationStateHasBeenValid;
  145. float m_flDurationStateHasBeenInValid;
  146. float m_flHowLongToWaitUntilTransitionCanBlendIn;
  147. float m_flHowLongToWaitUntilTransitionCanBlendOut;
  148. float m_flBlendValue;
  149. void UpdateTransitionState( bool bStateShouldBeValid, float flTimeInterval, float flSpeed )
  150. {
  151. if ( bStateShouldBeValid )
  152. {
  153. m_flDurationStateHasBeenInValid = 0;
  154. m_flDurationStateHasBeenValid += flTimeInterval;
  155. if ( m_flDurationStateHasBeenValid >= m_flHowLongToWaitUntilTransitionCanBlendIn )
  156. {
  157. m_flBlendValue = Approach( 1, m_flBlendValue, flSpeed );
  158. }
  159. }
  160. else
  161. {
  162. m_flDurationStateHasBeenValid = 0;
  163. m_flDurationStateHasBeenInValid += flTimeInterval;
  164. if ( m_flDurationStateHasBeenInValid >= m_flHowLongToWaitUntilTransitionCanBlendOut )
  165. {
  166. m_flBlendValue = Approach( 0, m_flBlendValue, flSpeed );
  167. }
  168. }
  169. }
  170. void Init( void )
  171. {
  172. m_flDurationStateHasBeenValid = 0;
  173. m_flDurationStateHasBeenInValid = 0;
  174. m_flHowLongToWaitUntilTransitionCanBlendIn = 0.3f;
  175. m_flHowLongToWaitUntilTransitionCanBlendOut = 0.3f;
  176. m_flBlendValue = 0;
  177. }
  178. aimmatrix_transition_t()
  179. {
  180. Init();
  181. }
  182. };
  183. class CCSGOPlayerAnimState
  184. {
  185. public:
  186. DECLARE_CLASS_NOBASE( CCSGOPlayerAnimState );
  187. CCSGOPlayerAnimState( CCSPlayer *pPlayer );
  188. void Reset( void );
  189. void Release( void ) { delete this; }
  190. void Update( float eyeYaw, float eyePitch, bool bForce = false );
  191. float GetPrimaryCycle( void ) { return m_flPrimaryCycle; }
  192. void SetUpVelocity( void );
  193. void SetUpAimMatrix( void );
  194. void SetUpWeaponAction( void );
  195. void SetUpMovement( void );
  196. void SetUpAliveloop( void );
  197. void SetUpWholeBodyAction( void );
  198. void SetUpFlashedReaction( void );
  199. void SetUpFlinch( void );
  200. void SetUpLean( void );
  201. void UpdateAnimLayer( animstate_layer_t nLayerIndex, int nSequence, float flPlaybackRate, float flWeight, float flCycle = 0 );
  202. void IncrementLayerCycleWeightRateGeneric( animstate_layer_t nLayerIndex );
  203. void IncrementLayerCycle( animstate_layer_t nLayerIndex, bool bAllowLoop = false );
  204. void IncrementLayerWeight( animstate_layer_t nLayerIndex );
  205. void SetLayerRate( animstate_layer_t nLayerIndex, float flRate );
  206. void SetLayerCycle( animstate_layer_t nLayerIndex, float flCycle );
  207. void SetLayerWeight( animstate_layer_t nLayerIndex, float flWeight );
  208. void SetLayerWeightRate( animstate_layer_t nLayerIndex, float flPrevious );
  209. void SetLayerSequence( animstate_layer_t nLayerIndex, int nSequence );
  210. float GetLayerWeight( animstate_layer_t nLayerIndex );
  211. float GetLayerIdealWeightFromSeqCycle( animstate_layer_t nLayerIndex );
  212. float GetLayerRate( animstate_layer_t nLayerIndex );
  213. float GetLayerCycle( animstate_layer_t nLayerIndex );
  214. int GetLayerSequence( animstate_layer_t nLayerIndex );
  215. Activity GetLayerActivity( animstate_layer_t nLayerIndex );
  216. bool IsLayerSequenceCompleted( animstate_layer_t nLayerIndex );
  217. bool LayerSequenceHasActMod( animstate_layer_t nLayerIndex, const char* szActMod );
  218. void WriteAnimstateDebugBuffer( char *pDest );
  219. void ApplyLayerOrderPreset( animlayerpreset nNewPreset, bool bForce = false );
  220. void UpdateLayerOrderPreset( animstate_layer_t nLayerIndex, int nSequence );
  221. animlayerpreset m_pLayerOrderPreset;
  222. bool m_bFirstRunSinceInit;
  223. void ModifyEyePosition( Vector& vecInputEyePos );
  224. #ifdef CLIENT_DLL
  225. bool m_bFirstFootPlantSinceInit;
  226. void DoProceduralFootPlant( matrix3x4a_t boneToWorld[], mstudioikchain_t *pLeftFootChain, mstudioikchain_t *pRightFootChain, BoneVector pos[] );
  227. int m_iLastUpdateFrame;
  228. float m_flEyePositionSmoothLerp;
  229. void OnClientWeaponChange( CWeaponCSBase* pCurrentWeapon );
  230. float m_flStrafeChangeWeightSmoothFalloff;
  231. void NotifyOnLayerChangeSequence( const CAnimationLayer* pLayer, const int nNewSequence );
  232. void NotifyOnLayerChangeWeight( const CAnimationLayer* pLayer, const float flNewWeight );
  233. void NotifyOnLayerChangeCycle( const CAnimationLayer* pLayer, const float flNewcycle );
  234. #endif
  235. #ifndef CLIENT_DLL
  236. void AddActivityModifier( const char *szName );
  237. void UpdateActivityModifiers( void );
  238. int SelectSequenceFromActMods( Activity iAct );
  239. void DoAnimationEvent( PlayerAnimEvent_t event, int nData = 0 );
  240. void SelectDeathPose( const CTakeDamageInfo &info, int hitgroup, Activity& activity, float& yaw );
  241. #endif
  242. #ifndef CLIENT_DLL
  243. float m_flFlashedAmountEaseOutStart;
  244. float m_flFlashedAmountEaseOutEnd;
  245. #endif
  246. private:
  247. aimmatrix_transition_t m_tStandWalkAim;
  248. aimmatrix_transition_t m_tStandRunAim;
  249. aimmatrix_transition_t m_tCrouchWalkAim;
  250. bool LayerToIndex( const CAnimationLayer* pLayer, int &nIndex );
  251. float LerpCrouchWalkRun( float flCrouchVal, float flWalkVal, float flRunVal );
  252. bool CacheSequences( void );
  253. const char* GetWeaponPrefix( void );
  254. int m_cachedModelIndex;
  255. #ifdef CLIENT_DLL
  256. float FootBarrierEq( float flIn, float flMinWidth );
  257. float m_flStepHeightLeft;
  258. float m_flStepHeightRight;
  259. CWeaponCSBase* m_pWeaponLastBoneSetup;
  260. #endif
  261. CCSPlayer* m_pPlayer;
  262. CWeaponCSBase* m_pWeapon;
  263. CWeaponCSBase* m_pWeaponLast;
  264. float m_flLastUpdateTime;
  265. int m_nLastUpdateFrame;
  266. float m_flLastUpdateIncrement;
  267. float m_flEyeYaw;
  268. float m_flEyePitch;
  269. float m_flFootYaw;
  270. float m_flFootYawLast;
  271. float m_flMoveYaw;
  272. float m_flMoveYawIdeal;
  273. float m_flMoveYawCurrentToIdeal;
  274. float m_flTimeToAlignLowerBody;
  275. float m_flPrimaryCycle;
  276. float m_flMoveWeight;
  277. float m_flMoveWeightSmoothed;
  278. float m_flAnimDuckAmount;
  279. float m_flDuckAdditional;
  280. float m_flRecrouchWeight;
  281. Vector m_vecPositionCurrent;
  282. Vector m_vecPositionLast;
  283. Vector m_vecVelocity;
  284. Vector m_vecVelocityNormalized;
  285. Vector m_vecVelocityNormalizedNonZero;
  286. float m_flVelocityLengthXY;
  287. float m_flVelocityLengthZ;
  288. float m_flSpeedAsPortionOfRunTopSpeed;
  289. float m_flSpeedAsPortionOfWalkTopSpeed;
  290. float m_flSpeedAsPortionOfCrouchTopSpeed;
  291. float m_flDurationMoving;
  292. float m_flDurationStill;
  293. bool m_bOnGround;
  294. #ifndef CLIENT_DLL
  295. bool m_bJumping;
  296. float m_flLowerBodyRealignTimer;
  297. #endif
  298. bool m_bLanding;
  299. float m_flJumpToFall;
  300. float m_flDurationInAir;
  301. float m_flLeftGroundHeight;
  302. float m_flLandAnimMultiplier;
  303. float m_flWalkToRunTransition;
  304. bool m_bLandedOnGroundThisFrame;
  305. bool m_bLeftTheGroundThisFrame;
  306. float m_flInAirSmoothValue;
  307. bool m_bOnLadder;
  308. float m_flLadderWeight;
  309. float m_flLadderSpeed;
  310. bool m_bWalkToRunTransitionState;
  311. bool m_bDefuseStarted;
  312. bool m_bPlantAnimStarted;
  313. bool m_bTwitchAnimStarted;
  314. bool m_bAdjustStarted;
  315. CUtlVector<CUtlSymbol> m_ActivityModifiers;
  316. float m_flNextTwitchTime;
  317. float m_flTimeOfLastKnownInjury;
  318. float m_flLastVelocityTestTime;
  319. Vector m_vecVelocityLast;
  320. Vector m_vecTargetAcceleration;
  321. Vector m_vecAcceleration;
  322. float m_flAccelerationWeight;
  323. float m_flAimMatrixTransition;
  324. float m_flAimMatrixTransitionDelay;
  325. bool m_bFlashed;
  326. float m_flStrafeChangeWeight;
  327. float m_flStrafeChangeTargetWeight;
  328. float m_flStrafeChangeCycle;
  329. int m_nStrafeSequence;
  330. bool m_bStrafeChanging;
  331. float m_flDurationStrafing;
  332. float m_flFootLerp;
  333. bool m_bFeetCrossed;
  334. bool m_bPlayerIsAccelerating;
  335. animstate_pose_param_cache_t m_tPoseParamMappings[ PLAYER_POSE_PARAM_COUNT ];
  336. #ifndef CLIENT_DLL
  337. bool m_bDeployRateLimiting;
  338. #endif
  339. float m_flDurationMoveWeightIsTooHigh;
  340. float m_flStaticApproachSpeed;
  341. int m_nPreviousMoveState;
  342. float m_flStutterStep;
  343. float m_flActionWeightBiasRemainder;
  344. #ifdef CLIENT_DLL
  345. procedural_foot_t m_footLeft;
  346. procedural_foot_t m_footRight;
  347. float m_flCameraSmoothHeight;
  348. bool m_bSmoothHeightValid;
  349. float m_flLastTimeVelocityOverTen;
  350. #endif
  351. float m_flAimYawMin;
  352. float m_flAimYawMax;
  353. float m_flAimPitchMin;
  354. float m_flAimPitchMax;
  355. //float m_flMoveWalkWeight;
  356. //float m_flMoveCrouchWalkWeight;
  357. //float m_flMoveRunWeight;
  358. int m_nAnimstateModelVersion;
  359. };
  360. CCSGOPlayerAnimState *CreateCSGOPlayerAnimstate( CBaseAnimatingOverlay *pEntity );
  361. #endif // CSGO_PLAYERANIMSTATE_H