BVB Source Codes

CRYENGINE Show VolumesManager.cpp Source code

Return Download CRYENGINE: download VolumesManager.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "VolumesManager.h"
  5.  
  6. bool CVolumesManager::RegisterArea(const char* volumeName, NavigationVolumeID& outVolumeId)
  7. {
  8.         NavigationVolumeID volumeId = NavigationVolumeID();
  9.         bool bResult = false;
  10.  
  11.         VolumesMap::const_iterator it = m_volumeAreas.find(volumeName);
  12.         if (it == m_volumeAreas.end())
  13.         {
  14.                 {
  15.                         VolumesMap::const_iterator it = m_loadedVolumeAreas.find(volumeName);
  16.                         if (it != m_loadedVolumeAreas.end())
  17.                         {
  18.                                 volumeId = it->second;
  19.                                 AILogComment("CVolumesManager::RegisterArea: area '%s' is already loaded with the id = %u", volumeName, (uint32)volumeId);
  20.                                 m_loadedVolumeAreas.erase(it);
  21.                         }
  22.                 }
  23.  
  24.                 m_volumeAreas[volumeName] = volumeId;
  25.  
  26.                 AILogComment("CVolumesManager::RegisterArea: registering new area '%s' with the id = %u", volumeName, (uint32)volumeId);
  27.                 bResult = true;
  28.         }
  29.         else
  30.         {
  31.                 AIWarning("You are trying to register the area %s but it's already registered with id = %u.", volumeName, it->second);
  32.                 bResult = false;
  33.         }
  34.  
  35.         outVolumeId = volumeId;
  36.         return bResult;
  37. }
  38.  
  39. void CVolumesManager::RegisterAreaFromLoadedData(const char* szVolumeName, NavigationVolumeID id)
  40. {
  41.         if (m_loadedVolumeAreas.find(szVolumeName) != m_loadedVolumeAreas.end())
  42.         {
  43.                 AIWarning("You are trying to register the loaded area '%s' but it's already registered.", szVolumeName);
  44.         }
  45.         AILogComment("CVolumesManager::RegisterAreaFromLoadedData %s = %u", szVolumeName, (uint32)id);
  46.         m_loadedVolumeAreas[szVolumeName] = id;
  47. }
  48.  
  49. void CVolumesManager::ClearLoadedAreas()
  50. {
  51.         m_loadedVolumeAreas.clear();
  52. }
  53.  
  54. void CVolumesManager::ValidateAndSanitizeLoadedAreas(const INavigationSystem& navigationSystem)
  55. {
  56.         for (auto iter = m_loadedVolumeAreas.begin(); iter != m_loadedVolumeAreas.end(); )
  57.         {
  58.                 if (!navigationSystem.ValidateVolume(iter->second))
  59.                 {
  60.                         AIWarning("CVolumesManager::ValidateAndSanitizeLoadedAreas: Loaded area '%s' referenced volume '%u', which was not created for loaded navigation mesh. Reference is removed.",
  61.                                   iter->first.c_str(), (uint32)iter->second);
  62.  
  63.                         iter = m_loadedVolumeAreas.erase(iter);
  64.                 }
  65.                 else
  66.                 {
  67.                         ++iter;
  68.                 }
  69.         }
  70. }
  71.  
  72. bool CVolumesManager::SetAreaID(const char* volumeName, NavigationVolumeID id)
  73. {
  74.         if (IsAreaPresent(volumeName))
  75.         {
  76.                 m_volumeAreas[volumeName] = id;
  77.         }
  78.         else
  79.         {
  80.                 AIWarning("The area %s is not registered in the system.", volumeName);
  81.                 return false;
  82.         }
  83.         return true;
  84. }
  85.  
  86. void CVolumesManager::UnRegisterArea(const char* volumeName)
  87. {
  88.         VolumesMap::iterator it = m_volumeAreas.find(volumeName);
  89.         if (it != m_volumeAreas.end())
  90.                 m_volumeAreas.erase(it);
  91. }
  92.  
  93. void CVolumesManager::Clear()
  94. {
  95.         m_volumeAreas.clear();
  96.         m_loadedVolumeAreas.clear();
  97. }
  98.  
  99. bool CVolumesManager::IsAreaPresent(const char* volumeName) const
  100. {
  101.         VolumesMap::const_iterator it = m_volumeAreas.find(volumeName);
  102.         return it != m_volumeAreas.end();
  103. }
  104.  
  105. NavigationVolumeID CVolumesManager::GetAreaID(const char* volumeName) const
  106. {
  107.         NavigationVolumeID areaID;
  108.         VolumesMap::const_iterator it = m_volumeAreas.find(volumeName);
  109.         if (it != m_volumeAreas.end())
  110.                 areaID = it->second;
  111.         return areaID;
  112. }
  113.  
  114. bool CVolumesManager::GetAreaName(NavigationVolumeID id, string& name) const
  115. {
  116.         VolumesMap::const_iterator it = m_volumeAreas.begin();
  117.         VolumesMap::const_iterator end = m_volumeAreas.end();
  118.         for (; it != end; ++it)
  119.         {
  120.                 if (it->second == id)
  121.                 {
  122.                         name = it->first;
  123.                         return true;
  124.                 }
  125.         }
  126.         return false;
  127. }
  128.  
  129. void CVolumesManager::UpdateNameForAreaID(const NavigationVolumeID id, const char* newName)
  130. {
  131.         VolumesMap::const_iterator it = m_volumeAreas.begin();
  132.         VolumesMap::const_iterator end = m_volumeAreas.end();
  133.         for (; it != end; ++it)
  134.         {
  135.                 if (it->second == id)
  136.                 {
  137.                         m_volumeAreas.erase(it->first);
  138.                         break;
  139.                 }
  140.         }
  141.         m_volumeAreas[newName] = id;
  142. }
  143.  
  144. void CVolumesManager::InvalidateID(NavigationVolumeID id)
  145. {
  146.         VolumesMap::iterator it = m_volumeAreas.begin();
  147.         VolumesMap::iterator end = m_volumeAreas.end();
  148.         for (; it != end; ++it)
  149.         {
  150.                 if (it->second == id)
  151.                 {
  152.                         it->second = NavigationVolumeID();
  153.                         return;
  154.                 }
  155.         }
  156.         AIWarning("There is no navigation shape with assigned the ID:%d", (uint32) id);
  157. }
  158.  
  159. void CVolumesManager::GetVolumesNames(std::vector<string>& names) const
  160. {
  161.         names.reserve(m_volumeAreas.size());
  162.         VolumesMap::const_iterator it = m_volumeAreas.begin();
  163.         VolumesMap::const_iterator end = m_volumeAreas.end();
  164.         for (; it != end; ++it)
  165.         {
  166.                 names.push_back(it->first);
  167.         }
  168. }
  169.  
  170. bool CVolumesManager::IsLoadedAreaPresent(const char* volumeName) const
  171. {
  172.         VolumesMap::const_iterator it = m_loadedVolumeAreas.find(volumeName);
  173.         return it != m_loadedVolumeAreas.end();
  174. }
  175.  
  176. NavigationVolumeID CVolumesManager::GetLoadedAreaID(const char* volumeName) const
  177. {
  178.         NavigationVolumeID areaID;
  179.         VolumesMap::const_iterator it = m_loadedVolumeAreas.find(volumeName);
  180.         if (it != m_loadedVolumeAreas.end())
  181.                 areaID = it->second;
  182.         return areaID;
  183. }
  184.  
  185. void CVolumesManager::GetLoadedUnregisteredVolumes(std::vector<NavigationVolumeID>& volumes) const
  186. {
  187.         volumes.clear();
  188.         if (m_loadedVolumeAreas.size() > m_volumeAreas.size())
  189.         {
  190.                 volumes.reserve(m_loadedVolumeAreas.size() - m_volumeAreas.size());
  191.         }
  192.  
  193.         for (const auto& volumeNameIdPair : m_loadedVolumeAreas)
  194.         {
  195.                 const string& name = volumeNameIdPair.first;
  196.                 if (m_volumeAreas.find(name) == m_volumeAreas.end())
  197.                 {
  198.                         volumes.push_back(volumeNameIdPair.second);
  199.                 }
  200.         }
  201. }
  202.  
downloadVolumesManager.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