BVB Source Codes

CRYENGINE Show ICooperativeAnimationManager.h Source code

Return Download CRYENGINE: download ICooperativeAnimationManager.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description: Central manager for synchronized animations on multiple animated characters/actors
  8.    -------------------------------------------------------------------------
  9.    History:
  10.    - August 5th, 2008: Created by Michelle Martin
  11.    - February 5th, 2009: Moved to CryAction by David Ramos
  12. *************************************************************************/
  13.  
  14. #ifndef __I_COOPERATIVEANIMATIONMANAGER_H__
  15. #define __I_COOPERATIVEANIMATIONMANAGER_H__
  16.  
  17. #include <CryEntitySystem/IEntity.h>
  18. #include "IAnimatedCharacter.h"
  19. #include "IActorSystem.h"
  20.  
  21. class CCooperativeAnimation;
  22. class SCharacterParams;
  23. struct SCooperativeAnimParams;
  24. struct IAnimatedCharacter;
  25.  
  26. typedef DynArray<SCharacterParams> TCharacterParams;
  27.  
  28. /// Cooperative Animation Manager Common Interface
  29. struct ICooperativeAnimationManager
  30. {
  31.         virtual ~ICooperativeAnimationManager(){}
  32.         // update function for every frame
  33.         // dt is the time passed since last frame
  34.         virtual void Update(float dt) = 0;
  35.  
  36.         virtual void Reset() = 0;
  37.  
  38.         //! Start a new Cooperative animation
  39.         //! Returns true if the animation was started
  40.         //! If one of the specified actors is already part of a cooperative animation,
  41.         //! the function will return false.
  42.         virtual bool StartNewCooperativeAnimation(TCharacterParams& characterParams, const SCooperativeAnimParams& generalParams) = 0;
  43.  
  44.         //! Start a new Cooperative animation
  45.         //! Returns true if the animation was started
  46.         //! If one of the specified actors is already part of a cooperative animation,
  47.         //! the function will return false.
  48.         virtual bool StartNewCooperativeAnimation(SCharacterParams& params1, SCharacterParams& params2, const SCooperativeAnimParams& generalParams) = 0;
  49.  
  50.         //! This neat function allows to abuse the Cooperative Animation System for just a single
  51.         //! character - taking advantage of the exact positioning
  52.         virtual bool StartExactPositioningAnimation(const SCharacterParams& params, const SCooperativeAnimParams& generalParams) = 0;
  53.  
  54.         //! Stops all cooperative animations on this actor
  55.         //! Returns true if there was at least one animation stopped, false otherwise.
  56.         virtual bool StopCooperativeAnimationOnActor(IAnimatedCharacter* pActor) = 0;
  57.  
  58.         //! Same as above, but only stops cooperative animations that include both actors
  59.         virtual bool StopCooperativeAnimationOnActor(IAnimatedCharacter* pActor1, IAnimatedCharacter* pActor2) = 0;
  60.  
  61.         virtual bool IsActorBusy(const IAnimatedCharacter* pActor, const CCooperativeAnimation* pIgnoreAnimation = NULL) const = 0;
  62.         virtual bool IsActorBusy(const EntityId entID) const = 0;
  63. };
  64.  
  65. //! Determines what information is to be used as reference
  66. //! to align the actors for the animations
  67. enum EAlignmentRef
  68. {
  69.         eAF_WildMatch = 0,      //! the best location that involves the least movement will be picked
  70.         eAF_FirstActor,         //! the first actor will not move at all (but can be rotated), all others adjust to him
  71.         eAF_FirstActorNoRot,    //! the first actor will not move or rotate at all, all others adjust to him
  72.         eAF_FirstActorPosition, //! the target pos and rot of the first actor is specified in general params, all others adjust to that
  73.         eAF_Location,           //! the reference location of the animation is specified in general params
  74.         eAF_Max,
  75. };
  76.  
  77. // Default values
  78. const float animParamDefaultDistanceForSliding = 0.4f;
  79. const float animParamDefaultSlidingDuration    = 0.15f;          // this should ideally be the same value that is set in the AG for transition time
  80. const EAlignmentRef animParamDefaultAlignment  = eAF_WildMatch;
  81. const QuatT animParamDefaultLoc                = QuatT(IDENTITY);
  82. // END Default Values
  83.  
  84. //! Parameters needed per character
  85. class SCharacterParams
  86. {
  87.         friend class CCooperativeAnimation;
  88.  
  89. public:
  90.         IAnimatedCharacter* GetActor() const;
  91.         bool                IsActorValid() const;
  92.         void                SetStartDelay(float delay)             { fStartDelay = delay; }
  93.         void                SetAllowHorizontalPhysics(bool bAllow) { bAllowHorizontalPhysics = bAllow; }
  94.         QuatT               GetTargetQuatT()                       { return qTarget; }
  95.  
  96.         SCharacterParams(IAnimatedCharacter* actor, const char* signalName, bool allowHPhysics = false, float slidingDuration = animParamDefaultSlidingDuration) : deltaLocatorMovement(IDENTITY),
  97.                 collisionsDisabledWithFirstActor(0), animationState(AS_Unrequested), animFilepathCRC(0)
  98.         {
  99.                 CRY_ASSERT_MESSAGE(actor != NULL, "Invalid parameter. The actor here may not be NULL");
  100.  
  101.                 CRY_ASSERT_MESSAGE(signalName != NULL, "Invalid parameter. The signal name cannot be NULL");
  102.                 CRY_ASSERT_MESSAGE(strcmp(signalName, "") != 0, "Invalid parameter. The signal name cannot be empty");
  103.  
  104.                 CRY_ASSERT_MESSAGE(slidingDuration > 0.0f, "Invalid parameter. The sliding duration cannot be <= 0.0f");
  105.  
  106.                 bAnimationPlaying = false;
  107.                 bAllowHorizontalPhysics = allowHPhysics;
  108.                 entityId = actor->GetEntityId();
  109.                 pActor = actor;
  110.                 fSlidingDuration = (slidingDuration > 0.0f) ? slidingDuration : animParamDefaultSlidingDuration;
  111.                 fSlidingTimer = 0.0f;
  112.                 fStartDelay = 0.0f;
  113.                 fStartDelayTimer = 0.0f;
  114.  
  115.                 qTarget = QuatT(Vec3(ZERO), IDENTITY);
  116.                 qSlideOffset = QuatT(Vec3(ZERO), IDENTITY);
  117.                 currPos = QuatT(Vec3(ZERO), IDENTITY);
  118.  
  119.                 sSignalName = signalName;
  120.         }
  121.  
  122. private:
  123.         enum eAnimationState
  124.         {
  125.                 AS_Unrequested,
  126.                 AS_NotReady,
  127.                 AS_Ready,
  128.         };
  129.  
  130.         SCharacterParams() {}  // default constructor only available to CCooperativeAnimation
  131.  
  132.         // cached pointer to the actor
  133.         mutable IAnimatedCharacter* pActor;
  134.  
  135.         // EntityId which owns the actor we need
  136.         EntityId entityId;
  137.  
  138.         // time (in secs) this character has to slide into position while animation is already playing
  139.         float fSlidingDuration;
  140.  
  141.         //! timer for when the character is moved over time (internal use in the CCooperativeAnim only)
  142.         // Note: This a bit more complicated way of sliding is necessary to allow the character to move away
  143.         // within the animation while still sliding, otherwise it locators have to be fixed in the animation
  144.         // during the sliding duration and that constricts animators and is generally error-prone.
  145.         float fSlidingTimer;
  146.  
  147.         // time (in secs) to delay starting this character's sliding and animation
  148.         // Generally not needed, but useful for e.g. melee hit reactions, to start the animation of the character
  149.         // being hit later than the one hitting
  150.         float fStartDelay;
  151.  
  152.         //! timer for when the character animation should be started (internal use in the CCooperativeAnim only)
  153.         float fStartDelayTimer;
  154.  
  155.         // name of the signal to the animation graph
  156.         string sSignalName;
  157.  
  158.         // Target position and rotation of this character (internal use in the CCooperativeAnim only)
  159.         QuatT qTarget;
  160.  
  161.         //! Value for the offset when sliding starts (internal use in the CCooperativeAnim only)
  162.         // Needed because the animation will start to move the character away from his starting
  163.         // position, so ::qTargetPos cannot be used as reference after the animation has started.
  164.         // This relative offset will be applied over time.
  165.         QuatT qSlideOffset;
  166.  
  167.         // Needed for internal sliding purposes
  168.         QuatT currPos;
  169.  
  170.         //! Internal use only. Needed for the Play&Slide step, so locator movement is properly applied
  171.         QuatT deltaLocatorMovement;
  172.  
  173.         //! Internal use only. Caches the FilePathCRC of the anim when using non-animgraph-based mode
  174.         uint32 animFilepathCRC;
  175.  
  176.         // checking if the character has finished this coop action (he might already have started another)
  177.         bool bAnimationPlaying;
  178.  
  179.         // if this is true, the animation will not clip into solid objects, but this can then affect
  180.         // and falsify the relative positioning of the characters towards each other.
  181.         bool bAllowHorizontalPhysics;
  182.  
  183.         //! Internal use only. For disabling collisions between first actor and the rest
  184.         bool collisionsDisabledWithFirstActor;
  185.  
  186.         //! Internal use only. Reflects the state of the animation for this character when using non-animgraph-based mode
  187.         uint8 animationState;
  188. };
  189.  
  190. //! General Parameters for the animation
  191. struct SCooperativeAnimParams
  192. {
  193.         //! Set to true if the animations shall be started no matter what.
  194.         //! This can mean interrupting other coopAnims, and can result in animation snapping.
  195.         bool bForceStart;
  196.  
  197.         //! true if this is supposed to be a looping animation
  198.         bool bLooping;
  199.  
  200.         //! true if we don't want to abort animation if one of the characters dies (useful for e.g. melee killing moves)
  201.         bool bIgnoreCharacterDeath;
  202.  
  203.         //! Defines the way the characters are aligned to each other
  204.         EAlignmentRef eAlignment;
  205.  
  206.         //! Position and orientation that animation is to be started from (eAlignment will determine it's specific meaning)
  207.         QuatT qLocation;
  208.  
  209.         //! true to enable the terrain elevation check
  210.         bool bPreventFallingThroughTerrain;
  211.  
  212.         // disables collisions between first actor and the others
  213.         bool bNoCollisionsBetweenFirstActorAndRest;
  214.  
  215.         SCooperativeAnimParams(bool forceStart = false, bool looping = false, EAlignmentRef alignment = animParamDefaultAlignment,
  216.                                const QuatT& location = animParamDefaultLoc, bool bPreventFallingThroughTerrain = true)
  217.                 : bForceStart(forceStart)
  218.                 , bLooping(looping)
  219.                 , bIgnoreCharacterDeath(false)
  220.                 , eAlignment(alignment)
  221.                 , qLocation(location)
  222.                 , bPreventFallingThroughTerrain(bPreventFallingThroughTerrain)
  223.                 , bNoCollisionsBetweenFirstActorAndRest(false)
  224.         {}
  225. };
  226.  
  227. //////////////////////////////////////////////////////////////////////////
  228. ILINE IAnimatedCharacter* SCharacterParams::GetActor() const
  229. {
  230.         return pActor;
  231. }
  232.  
  233. //////////////////////////////////////////////////////////////////////////
  234. ILINE bool SCharacterParams::IsActorValid() const
  235. {
  236.         // No animated character or not Character instance makes an actor invalid
  237.         return (pActor != NULL) && pActor->GetEntity() && (pActor->GetEntity()->GetCharacter(0) != NULL);
  238. }
  239.  
  240. #endif //__I_COOPERATIVEANIMATIONMANAGER_H__
  241.  
downloadICooperativeAnimationManager.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top