From 5d6312ab1e3218bb7e9a7087bb4dc893ba9a1ca0 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 13 Jul 2016 05:37:15 +0200 Subject: [PATCH 1/2] Mark start poly in NavMeshPruneTool The start poly would not be pruned if it was the only poly on the island. Fix #216 --- RecastDemo/Source/NavMeshPruneTool.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RecastDemo/Source/NavMeshPruneTool.cpp b/RecastDemo/Source/NavMeshPruneTool.cpp index 859f67e..6536393 100644 --- a/RecastDemo/Source/NavMeshPruneTool.cpp +++ b/RecastDemo/Source/NavMeshPruneTool.cpp @@ -171,6 +171,8 @@ static void floodNavmesh(dtNavMesh* nav, NavmeshFlags* flags, dtPolyRef start, u // If already visited, skip. if (flags->getFlags(start)) return; + + flags->setFlags(start, flag); PolyRefArray openList; openList.push(start); From 1445d05838edccc26808ff96ebb1fedcc9084bea Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 13 Jul 2016 05:37:37 +0200 Subject: [PATCH 2/2] Use std::vector in NavMeshPruneTool --- RecastDemo/Source/NavMeshPruneTool.cpp | 48 ++++---------------------- 1 file changed, 7 insertions(+), 41 deletions(-) diff --git a/RecastDemo/Source/NavMeshPruneTool.cpp b/RecastDemo/Source/NavMeshPruneTool.cpp index 6536393..79a48df 100644 --- a/RecastDemo/Source/NavMeshPruneTool.cpp +++ b/RecastDemo/Source/NavMeshPruneTool.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "SDL.h" #include "SDL_opengl.h" #include "imgui.h" @@ -36,43 +37,6 @@ # define snprintf _snprintf #endif - - -// Copy/paste from Recast int array -class PolyRefArray -{ - dtPolyRef* m_data; - int m_size, m_cap; - inline PolyRefArray(const PolyRefArray&); - inline PolyRefArray& operator=(const PolyRefArray&); -public: - - inline PolyRefArray() : m_data(0), m_size(0), m_cap(0) {} - inline PolyRefArray(int n) : m_data(0), m_size(0), m_cap(0) { resize(n); } - inline ~PolyRefArray() { dtFree(m_data); } - void resize(int n) - { - if (n > m_cap) - { - if (!m_cap) m_cap = n; - while (m_cap < n) m_cap *= 2; - dtPolyRef* newData = (dtPolyRef*)dtAlloc(m_cap*sizeof(dtPolyRef), DT_ALLOC_TEMP); - if (m_size && newData) memcpy(newData, m_data, m_size*sizeof(dtPolyRef)); - dtFree(m_data); - m_data = newData; - } - m_size = n; - } - inline void push(dtPolyRef item) { resize(m_size+1); m_data[m_size-1] = item; } - inline dtPolyRef pop() { if (m_size > 0) m_size--; return m_data[m_size]; } - inline const dtPolyRef& operator[](int i) const { return m_data[i]; } - inline dtPolyRef& operator[](int i) { return m_data[i]; } - inline int size() const { return m_size; } -}; - - - - class NavmeshFlags { struct TileFlags @@ -174,12 +138,14 @@ static void floodNavmesh(dtNavMesh* nav, NavmeshFlags* flags, dtPolyRef start, u flags->setFlags(start, flag); - PolyRefArray openList; - openList.push(start); + std::vector openList; + openList.push_back(start); while (openList.size()) { - const dtPolyRef ref = openList.pop(); + const dtPolyRef ref = openList.back(); + openList.pop_back(); + // Get current poly and tile. // The API input has been cheked already, skip checking internal data. const dtMeshTile* tile = 0; @@ -196,7 +162,7 @@ static void floodNavmesh(dtNavMesh* nav, NavmeshFlags* flags, dtPolyRef start, u // Mark as visited flags->setFlags(neiRef, flag); // Visit neighbours - openList.push(neiRef); + openList.push_back(neiRef); } } }