BVB Source Codes

CRYENGINE Show AIProxyManager.cpp Source code

Return Download CRYENGINE: download AIProxyManager.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: Manages AI proxies
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 16:04:2010: Created by Kevin Kirst
  12.  
  13. *************************************************************************/
  14.  
  15. #include "StdAfx.h"
  16. #include "AIProxyManager.h"
  17. #include "AIProxy.h"
  18. #include "AIGroupProxy.h"
  19.  
  20. //////////////////////////////////////////////////////////////////////////
  21. CAIProxyManager::CAIProxyManager()
  22. {
  23.  
  24. }
  25.  
  26. //////////////////////////////////////////////////////////////////////////
  27. CAIProxyManager::~CAIProxyManager()
  28. {
  29.  
  30. }
  31.  
  32. //////////////////////////////////////////////////////////////////////////
  33. void CAIProxyManager::Init()
  34. {
  35.         gEnv->pEntitySystem->AddSink(this, IEntitySystem::OnReused, 0);
  36.  
  37.         gEnv->pAISystem->SetActorProxyFactory(this);
  38.         gEnv->pAISystem->SetGroupProxyFactory(this);
  39. }
  40.  
  41. //////////////////////////////////////////////////////////////////////////
  42. void CAIProxyManager::Shutdown()
  43. {
  44.         gEnv->pEntitySystem->RemoveSink(this);
  45.  
  46.         gEnv->pAISystem->SetActorProxyFactory(NULL);
  47.         gEnv->pAISystem->SetGroupProxyFactory(NULL);
  48. }
  49.  
  50. //////////////////////////////////////////////////////////////////////////
  51. IAIActorProxy* CAIProxyManager::GetAIActorProxy(EntityId id) const
  52. {
  53.         TAIProxyMap::const_iterator it = m_aiProxyMap.find(id);
  54.         if (it != m_aiProxyMap.end())
  55.                 return it->second;
  56.         return NULL;
  57. }
  58.  
  59. //////////////////////////////////////////////////////////////////////////
  60. IAIActorProxy* CAIProxyManager::CreateActorProxy(EntityId entityID)
  61. {
  62.         CAIProxy* pResult = NULL;
  63.  
  64.         if (IGameObject* gameObject = CCryAction::GetCryAction()->GetGameObject(entityID))
  65.         {
  66.                 pResult = new CAIProxy(gameObject);
  67.  
  68.                 // (MATT) Check if this instance already has a proxy - right now there's no good reason to change proxies on an instance {2009/04/06}
  69.                 TAIProxyMap::iterator it = m_aiProxyMap.find(entityID);
  70.                 if (it != m_aiProxyMap.end())
  71.                 {
  72.                         CRY_ASSERT_TRACE(false, ("Entity ID %d already has an actor proxy! possible memory leak", entityID));
  73.                         it->second = pResult;
  74.                 }
  75.                 else
  76.                 {
  77.                         m_aiProxyMap.insert(std::make_pair(entityID, pResult));
  78.                 }
  79.         }
  80.         else
  81.         {
  82.                 GameWarning("Trying to create AIActorProxy for un-existent game object.");
  83.         }
  84.  
  85.         return pResult;
  86. }
  87.  
  88. //////////////////////////////////////////////////////////////////////////
  89. IAIGroupProxy* CAIProxyManager::CreateGroupProxy(int groupID)
  90. {
  91.         return new CAIGroupProxy(groupID);
  92. }
  93.  
  94. //////////////////////////////////////////////////////////////////////////
  95. void CAIProxyManager::OnAIProxyDestroyed(IAIActorProxy* pProxy)
  96. {
  97.         assert(pProxy);
  98.  
  99.         TAIProxyMap::iterator itProxy = m_aiProxyMap.begin();
  100.         TAIProxyMap::iterator itProxyEnd = m_aiProxyMap.end();
  101.         for (; itProxy != itProxyEnd; ++itProxy)
  102.         {
  103.                 if (itProxy->second == pProxy)
  104.                 {
  105.                         m_aiProxyMap.erase(itProxy);
  106.                         break;
  107.                 }
  108.         }
  109. }
  110.  
  111. //////////////////////////////////////////////////////////////////////////
  112. bool CAIProxyManager::OnBeforeSpawn(SEntitySpawnParams& params)
  113. {
  114.         return true;
  115. }
  116.  
  117. //////////////////////////////////////////////////////////////////////////
  118. void CAIProxyManager::OnSpawn(IEntity* pEntity, SEntitySpawnParams& params)
  119. {
  120.  
  121. }
  122.  
  123. //////////////////////////////////////////////////////////////////////////
  124. bool CAIProxyManager::OnRemove(IEntity* pEntity)
  125. {
  126.         return true;
  127. }
  128.  
  129. //////////////////////////////////////////////////////////////////////////
  130. void CAIProxyManager::OnEvent(IEntity* pEntity, SEntityEvent& event)
  131. {
  132.  
  133. }
  134.  
  135. //////////////////////////////////////////////////////////////////////////
  136. void CAIProxyManager::OnReused(IEntity* pEntity, SEntitySpawnParams& params)
  137. {
  138.         TAIProxyMap::iterator itProxy = m_aiProxyMap.find(params.prevId);
  139.         if (itProxy != m_aiProxyMap.end())
  140.         {
  141.                 CAIProxy* pProxy = itProxy->second;
  142.                 assert(pProxy);
  143.  
  144.                 pProxy->OnReused(pEntity, params);
  145.  
  146.                 // Update lookup map
  147.                 m_aiProxyMap.erase(itProxy);
  148.                 m_aiProxyMap[pEntity->GetId()] = pProxy;
  149.         }
  150. }
  151.  
downloadAIProxyManager.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