BVB Source Codes

CRYENGINE Show CooperativeAnimationManager.cpp Source code

Return Download CRYENGINE: download CooperativeAnimationManager.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  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 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. #include "StdAfx.h"
  16. #include "CooperativeAnimationManager.h"
  17. #include "IAnimatedCharacter.h"
  18.  
  19. // -------------------------------------------
  20. //     Now to the actual implementation
  21. // -------------------------------------------
  22.  
  23. CCooperativeAnimationManager::~CCooperativeAnimationManager()
  24. {
  25.         // delete all active animations
  26.         TActiveAnimations::iterator it = m_activeAnimations.begin();
  27.         TActiveAnimations::iterator iend = m_activeAnimations.end();
  28.         for (; it != iend; ++it)
  29.                 SAFE_DELETE(*it);
  30.  
  31.         m_activeAnimations.clear();
  32. }
  33.  
  34. bool CCooperativeAnimationManager::StartNewCooperativeAnimation(TCharacterParams& characterParams, const SCooperativeAnimParams& generalParams)
  35. {
  36.         // tries to start a new cooperative animation
  37.  
  38.         // By default, the animation should only start if all actors are available
  39.         // But if force start, we will stop any other coop animations these actors are in
  40.         TActiveAnimations::iterator it = m_activeAnimations.begin();
  41.         TActiveAnimations::iterator iend = m_activeAnimations.end();
  42.         for (; it != iend; ++it)
  43.         {
  44.                 CCooperativeAnimation* pAnim = *it;
  45.                 TCharacterParams::const_iterator itParamsEnd = characterParams.end();
  46.                 bool bUsingSomeActor = false;
  47.  
  48.                 for (TCharacterParams::const_iterator itParams = characterParams.begin(); (itParams != itParamsEnd) && !bUsingSomeActor; ++itParams)
  49.                 {
  50.                         bUsingSomeActor = pAnim->IsUsingActor(itParams->GetActor());
  51.                 }
  52.  
  53.                 if (bUsingSomeActor)
  54.                 {
  55.                         if (generalParams.bForceStart)
  56.                         {
  57.                                 pAnim->Stop();
  58.                         }
  59.                         else
  60.                         {
  61.                                 return false;
  62.                         }
  63.                 }
  64.         }
  65.  
  66.         // create the new animation an push it into the vector of active coop-animations
  67.         CCooperativeAnimation* newAnimation = new CCooperativeAnimation();
  68.         if (!newAnimation->Init(characterParams, generalParams))
  69.         {
  70.                 // if initialization fails for some reason, don't continue
  71.                 CRY_ASSERT_MESSAGE(0, "Cannot initialize cooperative animation. Init returned false.");
  72.                 CryLogAlways("Cannot initialize cooperative animation. Init returned false.");
  73.                 SAFE_DELETE(newAnimation);
  74.                 return false;
  75.         }
  76.  
  77.         m_activeAnimations.push_back(newAnimation);
  78.  
  79.         return true;
  80. }
  81.  
  82. bool CCooperativeAnimationManager::StartNewCooperativeAnimation(SCharacterParams& params1, SCharacterParams& params2, const SCooperativeAnimParams& generalParams)
  83. {
  84.         TCharacterParams characterParams;
  85.         characterParams.push_back(params1);
  86.         characterParams.push_back(params2);
  87.  
  88.         bool bReturn = StartNewCooperativeAnimation(characterParams, generalParams);
  89.  
  90.         params1 = characterParams[0];
  91.         params2 = characterParams[1];
  92.  
  93.         return bReturn;
  94. }
  95.  
  96. bool CCooperativeAnimationManager::StartExactPositioningAnimation(const SCharacterParams& params, const SCooperativeAnimParams& generalParams)
  97. {
  98.         // tries to start a new cooperative animation for a single character
  99.  
  100.         // By default, the animation should only start if all actors are available
  101.         // But if force start, we will stop any other coop animations these actors are in
  102.         TActiveAnimations::iterator it = m_activeAnimations.begin();
  103.         TActiveAnimations::iterator iend = m_activeAnimations.end();
  104.         for (; it != iend; ++it)
  105.         {
  106.                 CCooperativeAnimation* pAnim = *it;
  107.                 if (pAnim->IsUsingActor(params.GetActor()))
  108.                 {
  109.                         if (generalParams.bForceStart)
  110.                         {
  111.                                 pAnim->Stop();
  112.                         }
  113.                         else
  114.                         {
  115.                                 return false;
  116.                         }
  117.                 }
  118.         }
  119.  
  120.         // create the new animation an push it into the vector of active coop-animations
  121.         CCooperativeAnimation* newAnimation = new CCooperativeAnimation();
  122.         if (!newAnimation->InitForOne(params, generalParams))
  123.         {
  124.                 // if initialization fails for some reason, don't continue
  125.                 CRY_ASSERT_MESSAGE(0, "Cannot initialize cooperative animation. Init returned false.");
  126.                 CryLogAlways("Cannot initialize cooperative animation. Init returned false.");
  127.                 SAFE_DELETE(newAnimation);
  128.                 return false;
  129.         }
  130.  
  131.         m_activeAnimations.push_back(newAnimation);
  132.  
  133.         return true;
  134. }
  135.  
  136. void CCooperativeAnimationManager::Update(float dt)
  137. {
  138.         FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);
  139.  
  140.         // if there are no active animations get right back
  141.         if (m_activeAnimations.empty())
  142.                 return;
  143.  
  144.         TActiveAnimations forDeletion;
  145.  
  146.         // Go through all active animations an update them
  147.         TActiveAnimations::iterator it = m_activeAnimations.begin();
  148.         TActiveAnimations::iterator iend = m_activeAnimations.end();
  149.         for (; it != iend; ++it)
  150.         {
  151.                 // If the coop-animation returns false, it will be removed from the vector
  152.                 if (!(*it)->Update(dt))
  153.                 {
  154.                         // remember this one for deletion
  155.                         forDeletion.push_back((*it));
  156.                 }
  157.         }
  158.  
  159.         // remove all that are to be deleted
  160.         it = forDeletion.begin();
  161.         iend = forDeletion.end();
  162.         TActiveAnimations::iterator eraseMe;
  163.         for (; it != iend; ++it)
  164.         {
  165.                 CCooperativeAnimation* cAnim = (*it);
  166.                 eraseMe = std::find(m_activeAnimations.begin(), m_activeAnimations.end(), cAnim);
  167.                 SAFE_DELETE(cAnim);
  168.                 if (eraseMe != m_activeAnimations.end())
  169.                         m_activeAnimations.erase(eraseMe);
  170.         }
  171.  
  172. }
  173.  
  174. bool CCooperativeAnimationManager::IsActorBusy(const IAnimatedCharacter* pActor, const CCooperativeAnimation* pIgnoreAnimation /*=NULL*/) const
  175. {
  176.         // Check if the actors is already in a cooperative animation first
  177.         TActiveAnimations::const_iterator it = m_activeAnimations.begin();
  178.         TActiveAnimations::const_iterator iend = m_activeAnimations.end();
  179.         for (; it != iend; ++it)
  180.         {
  181.                 if (*it && (*it) != pIgnoreAnimation && (*it)->IsUsingActor(pActor))
  182.                         return true;
  183.         }
  184.  
  185.         return false;
  186. }
  187.  
  188. bool CCooperativeAnimationManager::IsActorBusy(const EntityId entID) const
  189. {
  190.         // Check if the actors is already in a cooperative animation first
  191.         TActiveAnimations::const_iterator it = m_activeAnimations.begin();
  192.         TActiveAnimations::const_iterator iend = m_activeAnimations.end();
  193.         for (; it != iend; ++it)
  194.         {
  195.                 if (*it && (*it)->IsUsingActor(entID))
  196.                         return true;
  197.         }
  198.  
  199.         return false;
  200. }
  201.  
  202. bool CCooperativeAnimationManager::StopCooperativeAnimationOnActor(IAnimatedCharacter* pActor)
  203. {
  204.         bool retVal = false;
  205.  
  206.         TActiveAnimations::iterator it = m_activeAnimations.begin();
  207.         TActiveAnimations::iterator iend = m_activeAnimations.end();
  208.         for (; it != iend; ++it)
  209.         {
  210.                 CCooperativeAnimation* pAnim = *it;
  211.                 if (pAnim->IsUsingActor(pActor))
  212.                 {
  213.                         pAnim->Stop();
  214.                         retVal = true;
  215.                 }
  216.         }
  217.  
  218.         return retVal;
  219. }
  220.  
  221. bool CCooperativeAnimationManager::StopCooperativeAnimationOnActor(IAnimatedCharacter* pActor1, IAnimatedCharacter* pActor2)
  222. {
  223.         bool retVal = false;
  224.  
  225.         TActiveAnimations::iterator it = m_activeAnimations.begin();
  226.         TActiveAnimations::iterator iend = m_activeAnimations.end();
  227.         for (; it != iend; ++it)
  228.         {
  229.                 CCooperativeAnimation* pAnim = *it;
  230.                 if (pAnim->IsUsingActor(pActor1) && pAnim->IsUsingActor(pActor2))
  231.                 {
  232.                         pAnim->Stop();
  233.                         retVal = true;
  234.                 }
  235.         }
  236.  
  237.         return retVal;
  238. }
  239.  
  240. void CCooperativeAnimationManager::Reset()
  241. {
  242.         // stop all existing animations
  243.         TActiveAnimations::iterator it = m_activeAnimations.begin();
  244.         TActiveAnimations::iterator iend = m_activeAnimations.end();
  245.         for (; it != iend; ++it)
  246.                 SAFE_DELETE(*it);
  247.  
  248.         stl::free_container(m_activeAnimations);
  249. }
  250.  
downloadCooperativeAnimationManager.cpp 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