BVB Source Codes

CRYENGINE Show CooperativeAnimation.h Source code

Return Download CRYENGINE: download CooperativeAnimation.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: synchronized animation playing on multiple actors
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - August 5th, 2008: Created by Michelle Martin
  12.    - February 5th, 2009: Moved to CryAction by David Ramos
  13. *************************************************************************/
  14.  
  15. #ifndef __COOPERATIVEANIMATION_H__
  16. #define __COOPERATIVEANIMATION_H__
  17.  
  18. #include <ICooperativeAnimationManager.h>
  19.  
  20. struct IAnimatedCharacter;
  21.  
  22. class CCooperativeAnimation : public IEntityEventListener
  23. {
  24. public:
  25.         // constructor for two-person-animations
  26.         CCooperativeAnimation();
  27.  
  28.         // destructor
  29.         ~CCooperativeAnimation();
  30.  
  31.         //! Update function to be called every frame
  32.         //! When the animation is finished, it will return false;
  33.         bool Update(float dt);
  34.  
  35.         //! Force cooperative animation to stop
  36.         //! Doesn't do any fancy finish, just makes next update return false
  37.         void Stop();
  38.  
  39.         // Check if an actor is in use by this coop-animation
  40.         ILINE bool IsUsingActor(const IAnimatedCharacter* pActor) const { CRY_ASSERT(pActor); return pActor && IsUsingActor(pActor->GetEntityId()); }
  41.         bool       IsUsingActor(const EntityId entID) const;
  42.  
  43.         // Check if all actors in coop-animation are still alive
  44.         bool AreActorsAlive();
  45.  
  46.         // Check if all actors involved are still valid
  47.         bool AreActorsValid() const;
  48.  
  49.         // retrieve the animation time for this entity's animation
  50.         float GetAnimationNormalizedTime(const EntityId entID) const;
  51.  
  52.         // Check if we are in the vertical correction blendout phase (animations have finished, we're just reorienting characters now)
  53.         bool DoingVerticalCorrectionBlendout() const;
  54.  
  55.         // Initialize the coop-animation
  56.         bool Init(TCharacterParams& characterParams, const SCooperativeAnimParams& generalParams);
  57.         bool Init(SCharacterParams& params1, SCharacterParams& params2, const SCooperativeAnimParams& generalParams);
  58.  
  59.         bool InitForOne(const SCharacterParams& params, const SCooperativeAnimParams& generalParams);
  60.  
  61.         //Keep track of entities involved in the animation to ensure they are still valid
  62.         virtual void OnEntityEvent(IEntity* pEntity, SEntityEvent& event);
  63.  
  64. private:
  65.  
  66.         enum ECoopAnimState
  67.         {
  68.                 eCS_PlayAndSlide,
  69.                 eCS_WaitForAnimationFinish,
  70.                 eCS_ForceStopping,
  71.         };
  72.  
  73.         //! Depending on parameters and positions this function determines a reference position
  74.         //! to which all other animations are relative. Then it calculates Target positions for
  75.         //! all characters.
  76.         void DetermineReferencePositionAndCalculateTargets();
  77.  
  78.         //! Determines how much this character needs to slide
  79.         //! to get into position. It sets the qSlideOffset value for the character
  80.         //! and only needs to be called once.
  81.         void GatherSlidingInformation(SCharacterParams& params) const;
  82.  
  83.         //! Pushes the characters over the last centimeters into position
  84.         //! while the animation is already playing.
  85.         //! Starts animation at the appropriate time (immediately or with a
  86.         //! delay if start delay has been set
  87.         void PlayAndSlideCharacters(float dt, bool& bAnimFailure, bool& bAllStarted, bool& bAllDone);
  88.  
  89.         //! Starts the animations for all characters
  90.         bool StartAnimations();
  91.  
  92.         //! Starts the animation for the given character
  93.         bool StartAnimation(SCharacterParams& params, int characterIndex);
  94.  
  95.         //! Returns true when the animation for all characters are finished
  96.         bool AnimationsFinished();
  97.  
  98.         bool IsAnimationPlaying(const ISkeletonAnim* pISkeletonAnim, const CAnimation* pAnim);
  99.  
  100.         //! Cleans up after a character has finished playing his animation.
  101.         //! Since this has to be done when either the animation is finished,
  102.         //! forcefully stopped, or the CoopAnimation gets destroyed, it is
  103.         //! safer to put everything in this separate function instead of
  104.         //! maintaining duplicate code.
  105.         void CleanupForFinishedCharacter(SCharacterParams& params);
  106.  
  107.         //! Returns the relative StartLocation for a specific character
  108.         //! as it is stored in the animation, i.e. the offset of the
  109.         //! character's root from the animator scene's origin
  110.         QuatT GetStartOffset(SCharacterParams& params);
  111.  
  112.         //! To avoid code duplication, this function sets the necessary
  113.         //! collider mode and movement control method for each character.
  114.         void SetColliderModeAndMCM(SCharacterParams* params);
  115.  
  116.         //! Disables/Reenables collisions between first actor and the rest
  117.         void IgnoreCollisionsWithFirstActor(SCharacterParams& characterParams, bool ignore);
  118.  
  119.         //! Handles streaming state of the involved anims
  120.         bool UpdateAnimationsStreaming();
  121.  
  122.         bool                   m_isInitialized;
  123.         bool                   m_bPauseAG;
  124.         ECoopAnimState         m_activeState;
  125.         QuatT                  m_refPoint;
  126.         SCooperativeAnimParams m_generalParams;
  127.  
  128.         // saving the params for all actors involved in this cooperative animation
  129.         TCharacterParams m_paramsList;
  130.  
  131.         // DEBUG OUTPUT STUFF
  132.         Vec3  m_firstActorStartPosition;
  133.         Vec3  m_firstActorStartDirection;
  134.         Vec3  m_firstActorTargetPosition;
  135.         Vec3  m_firstActorTargetDirection;
  136.         float m_firstActorPushedDistance;
  137.         // end of DEBUG OUTPUT STUFF
  138.  
  139. };
  140.  
  141. #endif
  142.  
downloadCooperativeAnimation.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