From 4def1f9a58e9a2afca6890761df94dc809001302 Mon Sep 17 00:00:00 2001 From: Graham Pentheny Date: Tue, 8 Apr 2025 23:54:27 -0400 Subject: [PATCH] Whitespace changes, use nullptr instead of 0, pragma once --- RecastDemo/Include/Filelist.h | 4 +- RecastDemo/Include/InputGeom.h | 17 +++--- RecastDemo/Include/Sample_SoloMesh.h | 6 +-- RecastDemo/Include/Sample_TileMesh.h | 14 ++--- RecastDemo/Source/Filelist.cpp | 17 +++--- RecastDemo/Source/NavMeshPruneTool.cpp | 73 +++++++++++--------------- RecastDemo/Source/Sample_SoloMesh.cpp | 1 - RecastDemo/Source/Sample_TileMesh.cpp | 12 ++--- 8 files changed, 63 insertions(+), 81 deletions(-) diff --git a/RecastDemo/Include/Filelist.h b/RecastDemo/Include/Filelist.h index 30ade6ec..3bf91c72 100644 --- a/RecastDemo/Include/Filelist.h +++ b/RecastDemo/Include/Filelist.h @@ -16,8 +16,7 @@ // 3. This notice may not be removed or altered from any source distribution. // -#ifndef FILELIST_H -#define FILELIST_H +#pragma once #include #include @@ -25,4 +24,3 @@ void scanDirectoryAppend(const std::string& path, const std::string& ext, std::vector& fileList); void scanDirectory(const std::string& path, const std::string& ext, std::vector& fileList); -#endif // FILELIST_H diff --git a/RecastDemo/Include/InputGeom.h b/RecastDemo/Include/InputGeom.h index edc12957..b1a56ed2 100644 --- a/RecastDemo/Include/InputGeom.h +++ b/RecastDemo/Include/InputGeom.h @@ -16,8 +16,7 @@ // 3. This notice may not be removed or altered from any source distribution. // -#ifndef INPUTGEOM_H -#define INPUTGEOM_H +#pragma once #include "ChunkyTriMesh.h" #include "MeshLoaderObj.h" @@ -76,7 +75,7 @@ class InputGeom float m_meshBMin[3], m_meshBMax[3]; BuildSettings m_buildSettings; bool m_hasBuildSettings; - + /// @name Off-Mesh connections. ///@{ static const int MAX_OFFMESH_CONNECTIONS = 256; @@ -95,17 +94,17 @@ class InputGeom ConvexVolume m_volumes[MAX_VOLUMES]; int m_volumeCount; ///@} - + bool loadMesh(class rcContext* ctx, const std::string& filepath); bool loadGeomSet(class rcContext* ctx, const std::string& filepath); public: InputGeom(); ~InputGeom(); - - + + bool load(class rcContext* ctx, const std::string& filepath); bool saveGeomSet(const BuildSettings* settings); - + /// Method to return static mesh data. const rcMeshLoaderObj* getMesh() const { return m_mesh; } const float* getMeshBoundsMin() const { return m_meshBMin; } @@ -140,11 +139,9 @@ public: void deleteConvexVolume(int i); void drawConvexVolumes(struct duDebugDraw* dd, bool hilight = false); ///@} - + private: // Explicitly disabled copy constructor and copy assignment operator. InputGeom(const InputGeom&); InputGeom& operator=(const InputGeom&); }; - -#endif // INPUTGEOM_H diff --git a/RecastDemo/Include/Sample_SoloMesh.h b/RecastDemo/Include/Sample_SoloMesh.h index c6690ccd..124af3ac 100644 --- a/RecastDemo/Include/Sample_SoloMesh.h +++ b/RecastDemo/Include/Sample_SoloMesh.h @@ -37,7 +37,7 @@ protected: rcContourSet* m_contourSet = nullptr; rcPolyMesh* m_polyMesh = nullptr; rcPolyMeshDetail* m_detailMesh = nullptr; - + enum class DrawMode : uint8_t { NAVMESH, @@ -59,7 +59,7 @@ protected: POLYMESH_DETAIL }; DrawMode m_drawMode = DrawMode::NAVMESH; - + void cleanup(); public: @@ -76,7 +76,7 @@ public: void handleRender() override; void handleRenderOverlay(double* proj, double* model, int* view) override; - void handleMeshChanged(class InputGeom* geom) override; + void handleMeshChanged(InputGeom* geom) override; bool handleBuild() override; private: diff --git a/RecastDemo/Include/Sample_TileMesh.h b/RecastDemo/Include/Sample_TileMesh.h index ffa7f075..1ce82a26 100644 --- a/RecastDemo/Include/Sample_TileMesh.h +++ b/RecastDemo/Include/Sample_TileMesh.h @@ -37,7 +37,7 @@ protected: rcPolyMesh* m_polyMesh = nullptr; rcPolyMeshDetail* m_detailPolyMesh = nullptr; rcConfig m_config {}; - + enum class DrawMode : uint8_t { NAVMESH, @@ -60,11 +60,11 @@ protected: POLYMESH_DETAIL }; DrawMode m_drawMode = DrawMode::NAVMESH; - + int m_maxTiles = 0; int m_maxPolysPerTile = 0; float m_tileSize = 32.0f; - + unsigned int m_tileColor = duRGBA(0,0,0,32); float m_lastBuiltTileBoundsMin[3] = { 0.0f, 0.0f, 0.0f }; float m_lastBuiltTileBoundsMax[3] = { 0.0f, 0.0f, 0.0f }; @@ -73,10 +73,10 @@ protected: int m_tileTriCount = 0; unsigned char* buildTileMesh(int tileX, int tileY, const float* boundsMin, const float* boundsMax, int& outDataSize); - + void cleanup(); void UI_DrawModeOption(const char* name, DrawMode drawMode, bool enabled); - + public: Sample_TileMesh(); ~Sample_TileMesh() override; @@ -93,9 +93,9 @@ public: void handleMeshChanged(InputGeom* geom) override; bool handleBuild() override; void collectSettings(BuildSettings& settings) override; - + void getTilePos(const float* pos, int& tileX, int& tileY) const; - + void buildTile(const float* pos); void removeTile(const float* pos); void buildAllTiles(); diff --git a/RecastDemo/Source/Filelist.cpp b/RecastDemo/Source/Filelist.cpp index bd715c47..6d02ae5f 100644 --- a/RecastDemo/Source/Filelist.cpp +++ b/RecastDemo/Source/Filelist.cpp @@ -26,21 +26,18 @@ # include #endif -using std::vector; -using std::string; - -void scanDirectoryAppend(const string& path, const string& ext, vector& filelist) +void scanDirectoryAppend(const std::string& path, const std::string& ext, std::vector& filelist) { #ifdef WIN32 - string pathWithExt = path + "/*" + ext; - + std::string pathWithExt = path + "/*" + ext; + _finddata_t dir; intptr_t fh = _findfirst(pathWithExt.c_str(), &dir); if (fh == -1L) { return; } - + do { filelist.push_back(dir.name); @@ -54,7 +51,7 @@ void scanDirectoryAppend(const string& path, const string& ext, vector& { return; } - + size_t extLen = strlen(ext.c_str()); while ((current = readdir(dp)) != 0) { @@ -66,12 +63,12 @@ void scanDirectoryAppend(const string& path, const string& ext, vector& } closedir(dp); #endif - + // Sort the list of files alphabetically. std::sort(filelist.begin(), filelist.end()); } -void scanDirectory(const string& path, const string& ext, vector& filelist) +void scanDirectory(const std::string& path, const std::string& ext, std::vector& filelist) { filelist.clear(); scanDirectoryAppend(path, ext, filelist); diff --git a/RecastDemo/Source/NavMeshPruneTool.cpp b/RecastDemo/Source/NavMeshPruneTool.cpp index c775e5f9..1ad17922 100644 --- a/RecastDemo/Source/NavMeshPruneTool.cpp +++ b/RecastDemo/Source/NavMeshPruneTool.cpp @@ -45,36 +45,32 @@ class NavmeshFlags int nflags; dtPolyRef base; }; - + const dtNavMesh* m_nav; TileFlags* m_tiles; int m_ntiles; public: - NavmeshFlags() : - m_nav(0), m_tiles(0), m_ntiles(0) - { - } - + NavmeshFlags() : m_nav(0), m_tiles(0), m_ntiles(0) { } + ~NavmeshFlags() { for (int i = 0; i < m_ntiles; ++i) + { m_tiles[i].purge(); + } dtFree(m_tiles); } - + bool init(const dtNavMesh* nav) { m_ntiles = nav->getMaxTiles(); - if (!m_ntiles) - return true; + if (!m_ntiles) { return true; } + m_tiles = (TileFlags*)dtAlloc(sizeof(TileFlags)*m_ntiles, DT_ALLOC_TEMP); - if (!m_tiles) - { - return false; - } + if (!m_tiles) { return false; } memset(m_tiles, 0, sizeof(TileFlags)*m_ntiles); - + // Alloc flags for each tile. for (int i = 0; i < nav->getMaxTiles(); ++i) { @@ -91,12 +87,12 @@ public: memset(tf->flags, 0, tf->nflags); } } - + m_nav = nav; - + return false; } - + inline void clearAllFlags() { for (int i = 0; i < m_ntiles; ++i) @@ -106,7 +102,7 @@ public: memset(tf->flags, 0, tf->nflags); } } - + inline unsigned char getFlags(dtPolyRef ref) { dtAssert(m_nav); @@ -126,17 +122,15 @@ public: m_nav->decodePolyId(ref, salt, it, ip); m_tiles[it].flags[ip] = flags; } - }; static void floodNavmesh(dtNavMesh* nav, NavmeshFlags* flags, dtPolyRef start, unsigned char flag) { // If already visited, skip. - if (flags->getFlags(start)) - return; + if (flags->getFlags(start)) { return; } flags->setFlags(start, flag); - + std::vector openList; openList.push_back(start); @@ -156,8 +150,8 @@ static void floodNavmesh(dtNavMesh* nav, NavmeshFlags* flags, dtPolyRef start, u { const dtPolyRef neiRef = tile->links[i].ref; // Skip invalid and already visited. - if (!neiRef || flags->getFlags(neiRef)) - continue; + if (!neiRef || flags->getFlags(neiRef)) { continue; } + // Mark as visited flags->setFlags(neiRef, flag); // Visit neighbours @@ -171,7 +165,7 @@ static void disableUnvisitedPolys(dtNavMesh* nav, NavmeshFlags* flags) for (int i = 0; i < nav->getMaxTiles(); ++i) { const dtMeshTile* tile = ((const dtNavMesh*)nav)->getTile(i); - if (!tile->header) continue; + if (!tile->header) { continue; } const dtPolyRef base = nav->getPolyRefBase(tile); for (int j = 0; j < tile->header->polyCount; ++j) { @@ -206,26 +200,24 @@ void NavMeshPruneTool::init(Sample* sample) void NavMeshPruneTool::reset() { m_hitPosSet = false; - delete m_flags; - m_flags = 0; + delete m_flags; m_flags = nullptr; } void NavMeshPruneTool::handleMenu() { dtNavMesh* nav = m_sample->getNavMesh(); - if (!nav) return; - if (!m_flags) return; + if (!nav) { return; } + if (!m_flags) { return; } if (imguiButton("Clear Selection")) { m_flags->clearAllFlags(); } - + if (imguiButton("Prune Unselected")) { disableUnvisitedPolys(nav, m_flags); - delete m_flags; - m_flags = 0; + delete m_flags; m_flags = nullptr; } } @@ -234,23 +226,23 @@ void NavMeshPruneTool::handleClick(const float* s, const float* p, bool shift) rcIgnoreUnused(s); rcIgnoreUnused(shift); - if (!m_sample) return; + if (!m_sample) { return; } InputGeom* geom = m_sample->getInputGeom(); - if (!geom) return; + if (!geom) { return; } dtNavMesh* nav = m_sample->getNavMesh(); - if (!nav) return; + if (!nav) { return; } dtNavMeshQuery* query = m_sample->getNavMeshQuery(); - if (!query) return; - + if (!query) { return; } + dtVcopy(m_hitPos, p); m_hitPosSet = true; - + if (!m_flags) { m_flags = new NavmeshFlags; m_flags->init(nav); } - + const float halfExtents[3] = { 2, 4, 2 }; dtQueryFilter filter; dtPolyRef ref = 0; @@ -295,7 +287,7 @@ void NavMeshPruneTool::handleRender() for (int i = 0; i < nav->getMaxTiles(); ++i) { const dtMeshTile* tile = nav->getTile(i); - if (!tile->header) continue; + if (!tile->header) { continue; } const dtPolyRef base = nav->getPolyRefBase(tile); for (int j = 0; j < tile->header->polyCount; ++j) { @@ -307,7 +299,6 @@ void NavMeshPruneTool::handleRender() } } } - } void NavMeshPruneTool::handleRenderOverlay(double* proj, double* model, int* view) diff --git a/RecastDemo/Source/Sample_SoloMesh.cpp b/RecastDemo/Source/Sample_SoloMesh.cpp index f8294f33..4768dc25 100644 --- a/RecastDemo/Source/Sample_SoloMesh.cpp +++ b/RecastDemo/Source/Sample_SoloMesh.cpp @@ -571,7 +571,6 @@ bool Sample_SoloMesh::handleBuild() m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'pmdtl'."); return false; } - if (!rcBuildPolyMeshDetail(m_buildContext, *m_polyMesh, *m_compactHeightfield, m_config.detailSampleDist, m_config.detailSampleMaxError, *m_detailMesh)) { m_buildContext->log(RC_LOG_ERROR, "buildNavigation: Could not build detail mesh."); diff --git a/RecastDemo/Source/Sample_TileMesh.cpp b/RecastDemo/Source/Sample_TileMesh.cpp index 4c5688a1..b89bad08 100644 --- a/RecastDemo/Source/Sample_TileMesh.cpp +++ b/RecastDemo/Source/Sample_TileMesh.cpp @@ -178,12 +178,12 @@ Sample_TileMesh::~Sample_TileMesh() void Sample_TileMesh::cleanup() { - delete[] m_triareas; m_triareas = 0; - rcFreeHeightField(m_heightfield); m_heightfield = 0; - rcFreeCompactHeightfield(m_compactHeightfield); m_compactHeightfield = 0; - rcFreeContourSet(m_contourSet); m_contourSet = 0; - rcFreePolyMesh(m_polyMesh); m_polyMesh = 0; - rcFreePolyMeshDetail(m_detailPolyMesh); m_detailPolyMesh = 0; + delete[] m_triareas; m_triareas = nullptr; + rcFreeHeightField(m_heightfield); m_heightfield = nullptr; + rcFreeCompactHeightfield(m_compactHeightfield); m_compactHeightfield = nullptr; + rcFreeContourSet(m_contourSet); m_contourSet = nullptr; + rcFreePolyMesh(m_polyMesh); m_polyMesh = nullptr; + rcFreePolyMeshDetail(m_detailPolyMesh); m_detailPolyMesh = nullptr; } void Sample_TileMesh::handleSettings()