BVB Source Codes

CRYENGINE Show VertexList.cpp Source code

Return Download CRYENGINE: download VertexList.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 "VertexList.h"
  5. #include "AILog.h"
  6. #include <CrySystem/ISystem.h>
  7. #include <CrySystem/File/CryFile.h>
  8.  
  9. #define BAI_VERTEX_FILE_VERSION 1
  10.  
  11. enum { BUCKET_COUNT = 8192 };
  12.  
  13. CVertexList::CVertexList()
  14. {
  15.         m_hashSpace = new CHashSpace<SVertexRecord, VertexHashSpaceTraits>(Vec3(7, 7, 7), BUCKET_COUNT, VertexHashSpaceTraits(*this));
  16.         m_obstacles.clear();
  17. }
  18.  
  19. CVertexList::~CVertexList()
  20. {
  21.         delete m_hashSpace;
  22. }
  23.  
  24. int CVertexList::FindVertex(const ObstacleData& od) const
  25. {
  26.         const Obstacles::const_iterator oiend = m_obstacles.end();
  27.         int index = 0;
  28.  
  29.         for (Obstacles::const_iterator oi = m_obstacles.begin(); oi != oiend; ++oi, ++index)
  30.         {
  31.                 if ((*oi) == od)
  32.                         return index;
  33.         }
  34.  
  35.         return -1;
  36. }
  37.  
  38. int CVertexList::AddVertex(const ObstacleData& od)
  39. {
  40.         int index = FindVertex(od);
  41.         if (index < 0)
  42.         {
  43.                 m_obstacles.push_back(od);
  44.                 index = (int)m_obstacles.size() - 1;
  45.                 m_hashSpace->AddObject(SVertexRecord(index));
  46.         }
  47.  
  48.         return index;
  49. }
  50.  
  51. const ObstacleData& CVertexList::GetVertex(int index) const
  52. {
  53.         if (!IsIndexValid(index))
  54.         {
  55. #if !defined(_DEBUG)
  56.                 AIError("CVertexList::GetVertex Tried to retrieve a non existing vertex (%d) from vertex list (size %d).Please regenerate the triangulation [Design bug]",
  57. #else
  58.                 AIError("CVertexList::GetVertex Tried to retrieve a non existing vertex (%d) from vertex list (size %" PRISIZE_T ").Please regenerate the triangulation [Design bug]",
  59.  
  60. #endif
  61.                         index, m_obstacles.size());
  62.                 return m_obstacles[0];
  63.         }
  64.         return m_obstacles[index];
  65. }
  66.  
  67. ObstacleData& CVertexList::ModifyVertex(int index)
  68. {
  69.         if (!IsIndexValid(index))
  70.         {
  71. #if !defined(_DEBUG)
  72.                 AIError("CVertexList::ModifyVertex Tried to retrieve a non existing vertex (%d) from vertex list (size %d).Please regenerate the triangulation [Design bug]",
  73. #else
  74.                 AIError("CVertexList::ModifyVertex Tried to retrieve a non existing vertex (%d) from vertex list (size %" PRISIZE_T ").Please regenerate the triangulation [Design bug]",
  75. #endif
  76.                         index, m_obstacles.size());
  77.                 static ObstacleData od;
  78.                 return od;
  79.         }
  80.         return m_obstacles[index];
  81. }
  82.  
  83. bool CVertexList::ReadFromFile(const char* fileName)
  84. {
  85.         MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Navigation, 0, "Triangulation vertices");
  86.  
  87.         m_obstacles.clear();
  88.         m_hashSpace->Clear(true);
  89.  
  90.         CCryFile file;
  91.         if (!file.Open(fileName, "rb"))
  92.         {
  93.                 AIError("CVertexList::ReadFromFile could not open vertex file: Regenerate triangulation in the editor [Design bug]");
  94.                 return false;
  95.         }
  96.  
  97.         int iNumber;
  98.  
  99.         AILogLoading("Verifying BAI file version");
  100.         file.ReadType(&iNumber);
  101.         if (iNumber != BAI_VERTEX_FILE_VERSION)
  102.         {
  103.                 AIError("CVertexList::ReadFromFile Wrong vertex list BAI file version - found %d expected %d: Regenerate triangulation in the editor [Design bug]", iNumber, BAI_VERTEX_FILE_VERSION);
  104.                 file.Close();
  105.                 return false;
  106.         }
  107.  
  108.         // Read number of descriptors.
  109.         file.ReadType(&iNumber);
  110.  
  111.         if (iNumber > 0)
  112.         {
  113.                 std::vector<ObstacleDataDesc> obDescs(iNumber);
  114.                 file.ReadType(&obDescs[0], iNumber);
  115.                 m_obstacles.resize(iNumber);
  116.                 std::vector<uint32> cellCounts(BUCKET_COUNT, 0);
  117.                 for (int i = 0; i < iNumber; ++i)
  118.                 {
  119.                         m_obstacles[i].vPos = obDescs[i].vPos;
  120.                         m_obstacles[i].vDir = obDescs[i].vDir;
  121.                         m_obstacles[i].fApproxRadius = obDescs[i].fApproxRadius;
  122.                         m_obstacles[i].flags = obDescs[i].flags;
  123.                         m_obstacles[i].approxHeight = obDescs[i].approxHeight;
  124.                         m_hashSpace->RecordBucketUsage(SVertexRecord(i), cellCounts);
  125.                 }
  126.  
  127.                 m_hashSpace->ReserveSpaceInBuckets(cellCounts);
  128.  
  129.                 for (int i = 0; i < iNumber; ++i)
  130.                 {
  131.                         m_hashSpace->AddObject(SVertexRecord(i));
  132.                 }
  133.         }
  134.  
  135.         file.Close();
  136.  
  137.         return true;
  138. }
  139.  
  140. //===================================================================
  141. // GetVerticesInRange
  142. //===================================================================
  143. void CVertexList::GetVerticesInRange(std::vector<std::pair<float, unsigned>>& vertsOut, const Vec3& pos, float range, unsigned char flags)
  144. {
  145.         FUNCTION_PROFILER(GetISystem(), PROFILE_AI);
  146.         vertsOut.clear();
  147.         SVertCollector collector(*this, vertsOut, flags);
  148.         m_hashSpace->ProcessObjectsWithinRadius(pos, range, collector);
  149. }
  150.  
  151. void CVertexList::GetMemoryStatistics(ICrySizer* pSizer)
  152. {
  153.         pSizer->AddObject(m_hashSpace, m_hashSpace->MemStats());
  154.         pSizer->AddContainer(m_obstacles);
  155. }
  156.  
  157. //===================================================================
  158. // Reset
  159. //===================================================================
  160. void CVertexList::Reset()
  161. {
  162.         const Obstacles::iterator oiend = m_obstacles.end();
  163.         for (Obstacles::iterator oi = m_obstacles.begin(); oi != oiend; ++oi)
  164.         {
  165.           ObstacleData& od = *oi;
  166.           od.ClearNavNodes();
  167.         }
  168. }
  169.  
downloadVertexList.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