spook953

full multiplayer_animstate.h

Jun 28th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.90 KB | None | 0 0
  1. //========= Copyright 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.  
  12. #include "convar.h"
  13. #include "basecombatweapon_shared.h"
  14. #include "iplayeranimstate.h"
  15.  
  16. #if defined( CLIENT_DLL )
  17. class C_BasePlayer;
  18. #define CPlayer C_BasePlayer
  19. #else
  20. class CBasePlayer;
  21. #endif
  22.  
  23. enum PlayerAnimEvent_t
  24. {
  25.     PLAYERANIMEVENT_ATTACK_PRIMARY,
  26.     PLAYERANIMEVENT_ATTACK_SECONDARY,
  27.     PLAYERANIMEVENT_ATTACK_GRENADE,
  28.     PLAYERANIMEVENT_RELOAD,
  29.     PLAYERANIMEVENT_RELOAD_LOOP,
  30.     PLAYERANIMEVENT_RELOAD_END,
  31.     PLAYERANIMEVENT_JUMP,
  32.     PLAYERANIMEVENT_SWIM,
  33.     PLAYERANIMEVENT_DIE,
  34.     PLAYERANIMEVENT_FLINCH_CHEST,
  35.     PLAYERANIMEVENT_FLINCH_HEAD,
  36.     PLAYERANIMEVENT_FLINCH_LEFTARM,
  37.     PLAYERANIMEVENT_FLINCH_RIGHTARM,
  38.     PLAYERANIMEVENT_FLINCH_LEFTLEG,
  39.     PLAYERANIMEVENT_FLINCH_RIGHTLEG,
  40.     PLAYERANIMEVENT_DOUBLEJUMP,
  41.  
  42.     // Cancel.
  43.     PLAYERANIMEVENT_CANCEL,
  44.     PLAYERANIMEVENT_SPAWN,
  45.  
  46.     // Snap to current yaw exactly
  47.     PLAYERANIMEVENT_SNAP_YAW,
  48.  
  49.     PLAYERANIMEVENT_CUSTOM,             // Used to play specific activities
  50.     PLAYERANIMEVENT_CUSTOM_GESTURE,
  51.     PLAYERANIMEVENT_CUSTOM_SEQUENCE,    // Used to play specific sequences
  52.     PLAYERANIMEVENT_CUSTOM_GESTURE_SEQUENCE,
  53.  
  54.     // TF Specific. Here until there's a derived game solution to this.
  55.     PLAYERANIMEVENT_ATTACK_PRE,
  56.     PLAYERANIMEVENT_ATTACK_POST,
  57.     PLAYERANIMEVENT_GRENADE1_DRAW,
  58.     PLAYERANIMEVENT_GRENADE2_DRAW,
  59.     PLAYERANIMEVENT_GRENADE1_THROW,
  60.     PLAYERANIMEVENT_GRENADE2_THROW,
  61.     PLAYERANIMEVENT_VOICE_COMMAND_GESTURE,
  62.     PLAYERANIMEVENT_DOUBLEJUMP_CROUCH,
  63.     PLAYERANIMEVENT_STUN_BEGIN,
  64.     PLAYERANIMEVENT_STUN_MIDDLE,
  65.     PLAYERANIMEVENT_STUN_END,
  66.     PLAYERANIMEVENT_PASSTIME_THROW_BEGIN,
  67.     PLAYERANIMEVENT_PASSTIME_THROW_MIDDLE,
  68.     PLAYERANIMEVENT_PASSTIME_THROW_END,
  69.     PLAYERANIMEVENT_PASSTIME_THROW_CANCEL,
  70.  
  71.     PLAYERANIMEVENT_ATTACK_PRIMARY_SUPER,
  72.  
  73.     PLAYERANIMEVENT_COUNT
  74. };
  75.  
  76. // Gesture Slots.
  77. enum
  78. {
  79.     GESTURE_SLOT_ATTACK_AND_RELOAD,
  80.     GESTURE_SLOT_GRENADE,
  81.     GESTURE_SLOT_JUMP,
  82.     GESTURE_SLOT_SWIM,
  83.     GESTURE_SLOT_FLINCH,
  84.     GESTURE_SLOT_VCD,
  85.     GESTURE_SLOT_CUSTOM,
  86.  
  87.     GESTURE_SLOT_COUNT,
  88. };
  89.  
  90. #define GESTURE_SLOT_INVALID    -1
  91.  
  92. struct GestureSlot_t
  93. {
  94.     int                 m_iGestureSlot;
  95.     Activity            m_iActivity;
  96.     bool                m_bAutoKill;
  97.     bool                m_bActive;
  98.     CAnimationLayer     *m_pAnimLayer;
  99. };
  100.  
  101. inline bool IsCustomPlayerAnimEvent( PlayerAnimEvent_t event )
  102. {
  103.     return ( event == PLAYERANIMEVENT_CUSTOM ) || ( event == PLAYERANIMEVENT_CUSTOM_GESTURE ) ||
  104.         ( event == PLAYERANIMEVENT_CUSTOM_SEQUENCE ) || ( event == PLAYERANIMEVENT_CUSTOM_GESTURE_SEQUENCE );
  105. }
  106.  
  107. struct MultiPlayerPoseData_t
  108. {
  109.     int         m_iMoveX;
  110.     int         m_iMoveY;
  111.     int         m_iAimYaw;
  112.     int         m_iAimPitch;
  113.     int         m_iBodyHeight;
  114.     int         m_iMoveYaw;
  115.     int         m_iMoveScale;
  116.  
  117.     float       m_flEstimateYaw;
  118.     float       m_flLastAimTurnTime;
  119.  
  120.     void Init()
  121.     {
  122.         m_iMoveX = 0;
  123.         m_iMoveY = 0;
  124.         m_iAimYaw = 0;
  125.         m_iAimPitch = 0;
  126.         m_iBodyHeight = 0;
  127.         m_iMoveYaw = 0;
  128.         m_iMoveScale = 0;
  129.         m_flEstimateYaw = 0.0f;
  130.         m_flLastAimTurnTime = 0.0f;
  131.     }
  132. };
  133.  
  134. struct DebugPlayerAnimData_t
  135. {
  136.     float       m_flSpeed;
  137.     float       m_flAimPitch;
  138.     float       m_flAimYaw;
  139.     float       m_flBodyHeight;
  140.     Vector2D    m_vecMoveYaw;
  141.  
  142.     void Init()
  143.     {
  144.         m_flSpeed = 0.0f;
  145.         m_flAimPitch = 0.0f;
  146.         m_flAimYaw = 0.0f;
  147.         m_flBodyHeight = 0.0f;
  148.         m_vecMoveYaw.Init();
  149.     }
  150. };
  151.  
  152. struct MultiPlayerMovementData_t
  153. {
  154.     // Set speeds to -1 if they are not used.
  155.     float       m_flWalkSpeed;
  156.     float       m_flRunSpeed;
  157.     float       m_flSprintSpeed;   
  158.     float       m_flBodyYawRate;
  159. };
  160.  
  161.  
  162. //=============================================================================
  163. //
  164. // Multi-Player Animation State
  165. //
  166. class CMultiPlayerAnimState
  167. {
  168. public:
  169.  
  170.     DECLARE_CLASS_NOBASE( CMultiPlayerAnimState );
  171.  
  172.     // Creation/Destruction
  173.     CMultiPlayerAnimState() {}
  174.     CMultiPlayerAnimState( CBasePlayer *pPlayer, MultiPlayerMovementData_t &movementData );
  175.     virtual ~CMultiPlayerAnimState();
  176.  
  177.     // This is called by both the client and the server in the same way to trigger events for
  178.     // players firing, jumping, throwing grenades, etc.
  179.     virtual void ClearAnimationState();
  180.     virtual void DoAnimationEvent( PlayerAnimEvent_t event, int nData = 0 );
  181.     virtual Activity CalcMainActivity();   
  182.     virtual void Update( float eyeYaw, float eyePitch );
  183.     virtual void Release( void );
  184.  
  185.     const QAngle &GetRenderAngles();
  186.  
  187.     virtual Activity TranslateActivity( Activity actDesired );
  188.  
  189.     virtual void SetRunSpeed( float flSpeed ) { m_MovementData.m_flRunSpeed = flSpeed; }
  190.     virtual void SetWalkSpeed( float flSpeed ) { m_MovementData.m_flWalkSpeed = flSpeed; }
  191.     virtual void SetSprintSpeed( float flSpeed ) { m_MovementData.m_flSprintSpeed = flSpeed; }
  192.  
  193.     // Debug
  194.     virtual void ShowDebugInfo( void );
  195.     virtual void DebugShowAnimState( int iStartLine );
  196.  
  197.     Activity GetCurrentMainActivity( void ) { return m_eCurrentMainSequenceActivity; }
  198.  
  199.     void OnNewModel( void );
  200.  
  201.     // Gestures.
  202.     void    ResetGestureSlots( void );
  203.     void    ResetGestureSlot( int iGestureSlot );
  204.     void AddVCDSequenceToGestureSlot( int iGestureSlot, int iGestureSequence, float flCycle = 0.0f, bool bAutoKill = true );
  205.     CAnimationLayer* GetGestureSlotLayer( int iGestureSlot );
  206.     bool    IsGestureSlotActive( int iGestureSlot );
  207.     bool    VerifyAnimLayerInSlot( int iGestureSlot );
  208.  
  209.     // Feet.
  210.     // If you are forcing aim yaw, your code is almost definitely broken if you don't include a delay between
  211.     // teleporting and forcing yaw. This is due to an unfortunate interaction between the command lookback window,
  212.     // and the fact that m_flEyeYaw is never propogated from the server to the client.
  213.     // TODO: Fix this after Halloween 2014.
  214.     bool    m_bForceAimYaw;
  215.  
  216. protected:
  217.  
  218.     virtual void Init( CBasePlayer *pPlayer, MultiPlayerMovementData_t &movementData );
  219.     CBasePlayer *GetBasePlayer( void )              { return m_pPlayer; }
  220.  
  221.     // Allow inheriting classes to override SelectWeightedSequence
  222.     virtual int SelectWeightedSequence( Activity activity ) { return GetBasePlayer()->SelectWeightedSequence( activity ); }
  223.     virtual void RestartMainSequence();
  224.  
  225.     virtual void GetOuterAbsVelocity( Vector& vel );
  226.     float GetOuterXYSpeed();
  227.  
  228.     virtual bool HandleJumping( Activity &idealActivity );
  229.     virtual bool HandleDucking( Activity &idealActivity );
  230.     virtual bool HandleMoving( Activity &idealActivity );
  231.     virtual bool HandleSwimming( Activity &idealActivity );
  232.     virtual bool HandleDying( Activity &idealActivity );
  233.  
  234.     // Gesture Slots
  235.     CUtlVector<GestureSlot_t>       m_aGestureSlots;
  236.     bool    InitGestureSlots( void );
  237.     void    ShutdownGestureSlots( void );
  238.     bool    IsGestureSlotPlaying( int iGestureSlot, Activity iGestureActivity );
  239.     void    AddToGestureSlot( int iGestureSlot, Activity iGestureActivity, bool bAutoKill );
  240.     virtual void RestartGesture( int iGestureSlot, Activity iGestureActivity, bool bAutoKill = true );
  241.     void    ComputeGestureSequence( CStudioHdr *pStudioHdr );
  242.     void    UpdateGestureLayer( CStudioHdr *pStudioHdr, GestureSlot_t *pGesture );
  243.     void    DebugGestureInfo( void );
  244.     virtual float   GetGesturePlaybackRate( void ) { return 1.0f; }
  245.  
  246. #ifdef CLIENT_DLL
  247.     void    RunGestureSlotAnimEventsToCompletion( GestureSlot_t *pGesture );
  248. #endif
  249.  
  250.     virtual void PlayFlinchGesture( Activity iActivity );
  251.  
  252.     virtual float CalcMovementSpeed( bool *bIsMoving );
  253.     virtual float CalcMovementPlaybackRate( bool *bIsMoving );
  254.  
  255.     void DoMovementTest( CStudioHdr *pStudioHdr, float flX, float flY );
  256.     void DoMovementTest( CStudioHdr *pStudioHdr );
  257.     void GetMovementFlags( CStudioHdr *pStudioHdr );
  258.  
  259.     // Pose parameters.
  260.     bool                SetupPoseParameters( CStudioHdr *pStudioHdr );
  261.     virtual void        ComputePoseParam_MoveYaw( CStudioHdr *pStudioHdr );
  262.     virtual void        ComputePoseParam_AimPitch( CStudioHdr *pStudioHdr );
  263.     virtual void        ComputePoseParam_AimYaw( CStudioHdr *pStudioHdr );
  264.     void                ComputePoseParam_BodyHeight( CStudioHdr *pStudioHdr );
  265.     virtual void        EstimateYaw( void );
  266.     void                ConvergeYawAngles( float flGoalYaw, float flYawRate, float flDeltaTime, float &flCurrentYaw );
  267.  
  268.     virtual float GetCurrentMaxGroundSpeed();
  269.     virtual void ComputeSequences( CStudioHdr *pStudioHdr );
  270.     void ComputeMainSequence();
  271.     void UpdateInterpolators();
  272.     void ResetGroundSpeed( void );
  273.     float GetInterpolatedGroundSpeed( void );
  274.  
  275.     void ComputeFireSequence();
  276.     void ComputeDeployedSequence();
  277.  
  278.     virtual bool ShouldUpdateAnimState();
  279.  
  280.     void                DebugShowAnimStateForPlayer( bool bIsServer );
  281.     void                DebugShowEyeYaw( void );
  282.  
  283. // Client specific.
  284. #ifdef CLIENT_DLL
  285.  
  286.     // Debug.
  287.     void                DebugShowActivity( Activity activity );
  288.  
  289. #endif
  290.  
  291. protected:
  292.  
  293.     CBasePlayer *m_pPlayer;
  294.  
  295.     QAngle              m_angRender;
  296.  
  297.     // Pose parameters.
  298.     bool                        m_bPoseParameterInit;
  299.     MultiPlayerPoseData_t       m_PoseParameterData;
  300.     DebugPlayerAnimData_t       m_DebugAnimData;
  301.  
  302.     bool                        m_bCurrentFeetYawInitialized;
  303.     float                       m_flLastAnimationStateClearTime;
  304.    
  305.     float m_flEyeYaw;
  306.     float m_flEyePitch;
  307.     float m_flGoalFeetYaw;
  308.     float m_flCurrentFeetYaw;
  309.     float m_flLastAimTurnTime;
  310.  
  311.     MultiPlayerMovementData_t   m_MovementData;
  312.  
  313.     // Jumping.
  314.     bool    m_bJumping;
  315.     float   m_flJumpStartTime; 
  316.     bool    m_bFirstJumpFrame;
  317.  
  318.     // Swimming.
  319.     bool    m_bInSwim;
  320.     bool    m_bFirstSwimFrame;
  321.  
  322.     // Dying
  323.     bool    m_bDying;
  324.     bool    m_bFirstDyingFrame;
  325.  
  326.     // Last activity we've used on the lower body. Used to determine if animations should restart.
  327.     Activity m_eCurrentMainSequenceActivity;   
  328.  
  329.     // Specific full-body sequence to play
  330.     int     m_nSpecificMainSequence;
  331.  
  332.     // Weapon data.
  333.     CHandle<CBaseCombatWeapon>  m_hActiveWeapon;
  334.  
  335.     // Ground speed interpolators.
  336. #ifdef CLIENT_DLL
  337.     float m_flLastGroundSpeedUpdateTime;
  338.     CInterpolatedVar<float> m_iv_flMaxGroundSpeed;
  339. #endif
  340.     float m_flMaxGroundSpeed;
  341.  
  342.     // movement playback options
  343.     int m_nMovementSequence;
  344.     LegAnimType_t m_LegAnimType;
  345. };
  346.  
  347. // If this is set, then the game code needs to make sure to send player animation events
  348. // to the local player if he's the one being watched.
  349. extern ConVar cl_showanimstate;
  350.  
  351. #endif // DOD_PLAYERANIMSTATE_H
Add Comment
Please, Sign In to add comment