diff --git a/RecastDemo/Include/ConvexVolumeTool.h b/RecastDemo/Include/ConvexVolumeTool.h index 1f56cb07..4343c983 100644 --- a/RecastDemo/Include/ConvexVolumeTool.h +++ b/RecastDemo/Include/ConvexVolumeTool.h @@ -40,7 +40,7 @@ class ConvexVolumeTool : public SampleTool public: ConvexVolumeTool(); - virtual int type() { return TOOL_CONVEX_VOLUME; } + virtual SampleToolType type() { return SampleToolType::CONVEX_VOLUME; } virtual void init(Sample* sample); virtual void reset(); virtual void handleMenu(); diff --git a/RecastDemo/Include/CrowdTool.h b/RecastDemo/Include/CrowdTool.h index a2980660..f7fadcfb 100644 --- a/RecastDemo/Include/CrowdTool.h +++ b/RecastDemo/Include/CrowdTool.h @@ -129,7 +129,7 @@ class CrowdTool : public SampleTool public: CrowdTool(); - virtual int type() { return TOOL_CROWD; } + virtual SampleToolType type() { return SampleToolType::CROWD; } virtual void init(Sample* sample); virtual void reset(); virtual void handleMenu(); diff --git a/RecastDemo/Include/NavMeshPruneTool.h b/RecastDemo/Include/NavMeshPruneTool.h index 516098ee..88a68a01 100644 --- a/RecastDemo/Include/NavMeshPruneTool.h +++ b/RecastDemo/Include/NavMeshPruneTool.h @@ -36,7 +36,7 @@ public: NavMeshPruneTool(); virtual ~NavMeshPruneTool(); - virtual int type() { return TOOL_NAVMESH_PRUNE; } + virtual SampleToolType type() { return SampleToolType::NAVMESH_PRUNE; } virtual void init(Sample* sample); virtual void reset(); virtual void handleMenu(); diff --git a/RecastDemo/Include/NavMeshTesterTool.h b/RecastDemo/Include/NavMeshTesterTool.h index 080170ea..8866f7ac 100644 --- a/RecastDemo/Include/NavMeshTesterTool.h +++ b/RecastDemo/Include/NavMeshTesterTool.h @@ -95,7 +95,7 @@ class NavMeshTesterTool : public SampleTool public: NavMeshTesterTool(); - virtual int type() { return TOOL_NAVMESH_TESTER; } + virtual SampleToolType type() { return SampleToolType::NAVMESH_TESTER; } virtual void init(Sample* sample); virtual void reset(); virtual void handleMenu(); diff --git a/RecastDemo/Include/OffMeshConnectionTool.h b/RecastDemo/Include/OffMeshConnectionTool.h index 1b5aefbf..43cca042 100644 --- a/RecastDemo/Include/OffMeshConnectionTool.h +++ b/RecastDemo/Include/OffMeshConnectionTool.h @@ -35,7 +35,7 @@ public: OffMeshConnectionTool(); ~OffMeshConnectionTool(); - virtual int type() { return TOOL_OFFMESH_CONNECTION; } + virtual SampleToolType type() { return SampleToolType::OFFMESH_CONNECTION; } virtual void init(Sample* sample); virtual void reset(); virtual void handleMenu(); diff --git a/RecastDemo/Include/Sample.h b/RecastDemo/Include/Sample.h index a3f6f0c6..d645b32a 100644 --- a/RecastDemo/Include/Sample.h +++ b/RecastDemo/Include/Sample.h @@ -16,9 +16,9 @@ // 3. This notice may not be removed or altered from any source distribution. // -#ifndef RECASTSAMPLE_H -#define RECASTSAMPLE_H +#pragma once +#include #include "SampleInterfaces.h" class Sample; @@ -28,17 +28,19 @@ class dtNavMeshQuery; class dtCrowd; /// Tool types. -enum SampleToolType +enum class SampleToolType : uint8_t { - TOOL_NONE = 0, - TOOL_TILE_EDIT, - TOOL_TILE_HIGHLIGHT, - TOOL_TEMP_OBSTACLE, - TOOL_NAVMESH_TESTER, - TOOL_NAVMESH_PRUNE, - TOOL_OFFMESH_CONNECTION, - TOOL_CONVEX_VOLUME, - TOOL_CROWD, + NONE = 0, + + TILE_EDIT, + TILE_HIGHLIGHT, + TEMP_OBSTACLE, + NAVMESH_TESTER, + NAVMESH_PRUNE, + OFFMESH_CONNECTION, + CONVEX_VOLUME, + CROWD, + MAX_TOOLS }; @@ -79,7 +81,8 @@ public: struct SampleTool { virtual ~SampleTool(); - virtual int type() = 0; + + virtual SampleToolType type() = 0; virtual void init(Sample* sample) = 0; virtual void reset() = 0; virtual void handleMenu() = 0; @@ -128,14 +131,14 @@ protected: bool m_filterLowHangingObstacles; bool m_filterLedgeSpans; bool m_filterWalkableLowHeightSpans; - + SampleTool* m_tool; - SampleToolState* m_toolStates[MAX_TOOLS]; - + SampleToolState* m_toolStates[static_cast(SampleToolType::MAX_TOOLS)]; + BuildContext* m_buildContext; SampleDebugDraw m_debugDraw; - + dtNavMesh* loadAll(const char* path); void saveAll(const char* path, const dtNavMesh* mesh); @@ -146,9 +149,9 @@ public: Sample(const Sample&&) = delete; Sample& operator=(const Sample&) = delete; Sample& operator=(const Sample&&) = delete; - + void setContext(BuildContext* ctx) { m_buildContext = ctx; } - + void setTool(SampleTool* tool); SampleToolState* getToolState(const int type) const { return m_toolStates[type]; } void setToolState(const int type, SampleToolState* s) { m_toolStates[type] = s; } @@ -175,7 +178,7 @@ public: virtual float getAgentRadius() { return m_agentRadius; } virtual float getAgentHeight() { return m_agentHeight; } virtual float getAgentClimb() { return m_agentMaxClimb; } - + unsigned char getNavMeshDrawFlags() const { return m_navMeshDrawFlags; } void setNavMeshDrawFlags(unsigned char flags) { m_navMeshDrawFlags = flags; } @@ -188,6 +191,3 @@ public: void resetCommonSettings(); void handleCommonSettings(); }; - - -#endif // RECASTSAMPLE_H diff --git a/RecastDemo/Source/CrowdTool.cpp b/RecastDemo/Source/CrowdTool.cpp index 7f9f7843..0fb64ee2 100644 --- a/RecastDemo/Source/CrowdTool.cpp +++ b/RecastDemo/Source/CrowdTool.cpp @@ -874,11 +874,11 @@ void CrowdTool::init(Sample* sample) if (!sample) return; - m_state = (CrowdToolState*)sample->getToolState(type()); + m_state = (CrowdToolState*)sample->getToolState(static_cast(type())); if (!m_state) { m_state = new CrowdToolState(); - sample->setToolState(type(), m_state); + sample->setToolState(static_cast(type()), m_state); } m_state->init(sample); } diff --git a/RecastDemo/Source/Sample.cpp b/RecastDemo/Source/Sample.cpp index 773a2754..7ee8a11d 100644 --- a/RecastDemo/Source/Sample.cpp +++ b/RecastDemo/Source/Sample.cpp @@ -79,8 +79,10 @@ Sample::Sample() : m_navQuery = dtAllocNavMeshQuery(); m_crowd = dtAllocCrowd(); - for (int i = 0; i < MAX_TOOLS; i++) + for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) + { m_toolStates[i] = 0; + } } Sample::~Sample() @@ -89,8 +91,10 @@ Sample::~Sample() dtFreeNavMesh(m_navMesh); dtFreeCrowd(m_crowd); delete m_tool; - for (int i = 0; i < MAX_TOOLS; i++) + for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) + { delete m_toolStates[i]; + } } void Sample::setTool(SampleTool* tool) @@ -117,7 +121,7 @@ void Sample::handleRender() { if (!m_inputGeometry) return; - + // Draw mesh duDebugDrawTriMesh(&m_debugDraw, m_inputGeometry->getMesh()->getVerts(), m_inputGeometry->getMesh()->getVertCount(), m_inputGeometry->getMesh()->getTris(), m_inputGeometry->getMesh()->getNormals(), m_inputGeometry->getMesh()->getTriCount(), 0, 1.0f); @@ -196,7 +200,7 @@ void Sample::handleCommonSettings() imguiLabel("Rasterization"); imguiSlider("Cell Size", &m_cellSize, 0.1f, 1.0f, 0.01f); imguiSlider("Cell Height", &m_cellHeight, 0.1f, 1.0f, 0.01f); - + if (m_inputGeometry) { const float* bmin = m_inputGeometry->getNavMeshBoundsMin(); @@ -207,14 +211,14 @@ void Sample::handleCommonSettings() snprintf(text, 64, "Voxels %d x %d", gw, gh); imguiValue(text); } - + imguiSeparator(); imguiLabel("Agent"); imguiSlider("Height", &m_agentHeight, 0.1f, 5.0f, 0.1f); imguiSlider("Radius", &m_agentRadius, 0.0f, 5.0f, 0.1f); imguiSlider("Max Climb", &m_agentMaxClimb, 0.1f, 5.0f, 0.1f); imguiSlider("Max Slope", &m_agentMaxSlope, 0.0f, 90.0f, 1.0f); - + imguiSeparator(); imguiLabel("Region"); imguiSlider("Min Region Size", &m_regionMinSize, 0.0f, 150.0f, 1.0f); @@ -228,7 +232,7 @@ void Sample::handleCommonSettings() m_partitionType = SAMPLE_PARTITION_MONOTONE; if (imguiCheck("Layers", m_partitionType == SAMPLE_PARTITION_LAYERS)) m_partitionType = SAMPLE_PARTITION_LAYERS; - + imguiSeparator(); imguiLabel("Filtering"); if (imguiCheck("Low Hanging Obstacles", m_filterLowHangingObstacles)) @@ -242,13 +246,13 @@ void Sample::handleCommonSettings() imguiLabel("Polygonization"); imguiSlider("Max Edge Length", &m_edgeMaxLen, 0.0f, 50.0f, 1.0f); imguiSlider("Max Edge Error", &m_edgeMaxError, 0.1f, 3.0f, 0.1f); - imguiSlider("Verts Per Poly", &m_vertsPerPoly, 3.0f, 12.0f, 1.0f); + imguiSlider("Verts Per Poly", &m_vertsPerPoly, 3.0f, 12.0f, 1.0f); imguiSeparator(); imguiLabel("Detail Mesh"); imguiSlider("Sample Distance", &m_detailSampleDist, 0.0f, 16.0f, 1.0f); imguiSlider("Max Sample Error", &m_detailSampleMaxError, 0.0f, 16.0f, 1.0f); - + imguiSeparator(); } @@ -285,7 +289,7 @@ void Sample::handleUpdate(const float dt) void Sample::updateToolStates(const float dt) { - for (int i = 0; i < MAX_TOOLS; i++) + for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) { if (m_toolStates[i]) m_toolStates[i]->handleUpdate(dt); @@ -294,7 +298,7 @@ void Sample::updateToolStates(const float dt) void Sample::initToolStates(Sample* sample) { - for (int i = 0; i < MAX_TOOLS; i++) + for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) { if (m_toolStates[i]) m_toolStates[i]->init(sample); @@ -303,7 +307,7 @@ void Sample::initToolStates(Sample* sample) void Sample::resetToolStates() { - for (int i = 0; i < MAX_TOOLS; i++) + for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) { if (m_toolStates[i]) m_toolStates[i]->reset(); @@ -312,7 +316,7 @@ void Sample::resetToolStates() void Sample::renderToolStates() { - for (int i = 0; i < MAX_TOOLS; i++) + for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) { if (m_toolStates[i]) m_toolStates[i]->handleRender(); @@ -321,7 +325,7 @@ void Sample::renderToolStates() void Sample::renderOverlayToolStates(double* proj, double* model, int* view) { - for (int i = 0; i < MAX_TOOLS; i++) + for (int i = 0; i < static_cast(SampleToolType::MAX_TOOLS); i++) { if (m_toolStates[i]) m_toolStates[i]->handleRenderOverlay(proj, model, view); diff --git a/RecastDemo/Source/Sample_SoloMesh.cpp b/RecastDemo/Source/Sample_SoloMesh.cpp index 82ca8e94..f8294f33 100644 --- a/RecastDemo/Source/Sample_SoloMesh.cpp +++ b/RecastDemo/Source/Sample_SoloMesh.cpp @@ -102,13 +102,13 @@ void Sample_SoloMesh::handleSettings() void Sample_SoloMesh::handleTools() { - const int type = !m_tool ? TOOL_NONE : m_tool->type(); + const SampleToolType type = !m_tool ? SampleToolType::NONE : m_tool->type(); - if (imguiCheck("Test Navmesh", type == TOOL_NAVMESH_TESTER)) { setTool(new NavMeshTesterTool); } - if (imguiCheck("Prune Navmesh", type == TOOL_NAVMESH_PRUNE)) { setTool(new NavMeshPruneTool); } - if (imguiCheck("Create Off-Mesh Connections", type == TOOL_OFFMESH_CONNECTION)) { setTool(new OffMeshConnectionTool); } - if (imguiCheck("Create Convex Volumes", type == TOOL_CONVEX_VOLUME)) { setTool(new ConvexVolumeTool); } - if (imguiCheck("Create Crowds", type == TOOL_CROWD)) { setTool(new CrowdTool); } + if (imguiCheck("Test Navmesh", type == SampleToolType::NAVMESH_TESTER)) { setTool(new NavMeshTesterTool); } + if (imguiCheck("Prune Navmesh", type == SampleToolType::NAVMESH_PRUNE)) { setTool(new NavMeshPruneTool); } + if (imguiCheck("Create Off-Mesh Connections", type == SampleToolType::OFFMESH_CONNECTION)) { setTool(new OffMeshConnectionTool); } + if (imguiCheck("Create Convex Volumes", type == SampleToolType::CONVEX_VOLUME)) { setTool(new ConvexVolumeTool); } + if (imguiCheck("Create Crowds", type == SampleToolType::CROWD)) { setTool(new CrowdTool); } imguiSeparatorLine(); diff --git a/RecastDemo/Source/Sample_TempObstacles.cpp b/RecastDemo/Source/Sample_TempObstacles.cpp index b413906e..752b7bc3 100644 --- a/RecastDemo/Source/Sample_TempObstacles.cpp +++ b/RecastDemo/Source/Sample_TempObstacles.cpp @@ -699,7 +699,7 @@ public: virtual ~TempObstacleHilightTool(); - virtual int type() { return TOOL_TILE_HIGHLIGHT; } + virtual SampleToolType type() { return SampleToolType::TILE_HIGHLIGHT; } virtual void init(Sample* sample) { @@ -789,7 +789,7 @@ public: virtual ~TempObstacleCreateTool(); - virtual int type() { return TOOL_TEMP_OBSTACLE; } + virtual SampleToolType type() { return SampleToolType::TEMP_OBSTACLE; } virtual void init(Sample* sample) { @@ -951,29 +951,29 @@ void Sample_TempObstacles::handleSettings() void Sample_TempObstacles::handleTools() { - int type = !m_tool ? TOOL_NONE : m_tool->type(); + const SampleToolType type = !m_tool ? SampleToolType::NONE : m_tool->type(); - if (imguiCheck("Test Navmesh", type == TOOL_NAVMESH_TESTER)) + if (imguiCheck("Test Navmesh", type == SampleToolType::NAVMESH_TESTER)) { setTool(new NavMeshTesterTool); } - if (imguiCheck("Highlight Tile Cache", type == TOOL_TILE_HIGHLIGHT)) + if (imguiCheck("Highlight Tile Cache", type == SampleToolType::TILE_HIGHLIGHT)) { setTool(new TempObstacleHilightTool); } - if (imguiCheck("Create Temp Obstacles", type == TOOL_TEMP_OBSTACLE)) + if (imguiCheck("Create Temp Obstacles", type == SampleToolType::TEMP_OBSTACLE)) { setTool(new TempObstacleCreateTool); } - if (imguiCheck("Create Off-Mesh Links", type == TOOL_OFFMESH_CONNECTION)) + if (imguiCheck("Create Off-Mesh Links", type == SampleToolType::OFFMESH_CONNECTION)) { setTool(new OffMeshConnectionTool); } - if (imguiCheck("Create Convex Volumes", type == TOOL_CONVEX_VOLUME)) + if (imguiCheck("Create Convex Volumes", type == SampleToolType::CONVEX_VOLUME)) { setTool(new ConvexVolumeTool); } - if (imguiCheck("Create Crowds", type == TOOL_CROWD)) + if (imguiCheck("Create Crowds", type == SampleToolType::CROWD)) { setTool(new CrowdTool); } diff --git a/RecastDemo/Source/Sample_TileMesh.cpp b/RecastDemo/Source/Sample_TileMesh.cpp index e0d5c81a..4c5688a1 100644 --- a/RecastDemo/Source/Sample_TileMesh.cpp +++ b/RecastDemo/Source/Sample_TileMesh.cpp @@ -82,7 +82,7 @@ class NavMeshTileTool : public SampleTool public: ~NavMeshTileTool() override = default; - int type() override { return TOOL_TILE_EDIT; } + SampleToolType type() override { return SampleToolType::TILE_EDIT; } void init(Sample* sample) override { m_sample = static_cast(sample); } void reset() override {} @@ -259,14 +259,14 @@ void Sample_TileMesh::handleSettings() void Sample_TileMesh::handleTools() { - const int type = !m_tool ? TOOL_NONE : m_tool->type(); + const SampleToolType type = !m_tool ? SampleToolType::NONE : m_tool->type(); - if (imguiCheck("Test Navmesh", type == TOOL_NAVMESH_TESTER)) { setTool(new NavMeshTesterTool); } - if (imguiCheck("Prune Navmesh", type == TOOL_NAVMESH_PRUNE)) { setTool(new NavMeshPruneTool); } - if (imguiCheck("Create Tiles", type == TOOL_TILE_EDIT)) { setTool(new NavMeshTileTool); } - if (imguiCheck("Create Off-Mesh Links", type == TOOL_OFFMESH_CONNECTION)) { setTool(new OffMeshConnectionTool); } - if (imguiCheck("Create Convex Volumes", type == TOOL_CONVEX_VOLUME)) { setTool(new ConvexVolumeTool); } - if (imguiCheck("Create Crowds", type == TOOL_CROWD)) { setTool(new CrowdTool); } + if (imguiCheck("Test Navmesh", type == SampleToolType::NAVMESH_TESTER)) { setTool(new NavMeshTesterTool); } + if (imguiCheck("Prune Navmesh", type == SampleToolType::NAVMESH_PRUNE)) { setTool(new NavMeshPruneTool); } + if (imguiCheck("Create Tiles", type == SampleToolType::TILE_EDIT)) { setTool(new NavMeshTileTool); } + if (imguiCheck("Create Off-Mesh Links", type == SampleToolType::OFFMESH_CONNECTION)) { setTool(new OffMeshConnectionTool); } + if (imguiCheck("Create Convex Volumes", type == SampleToolType::CONVEX_VOLUME)) { setTool(new ConvexVolumeTool); } + if (imguiCheck("Create Crowds", type == SampleToolType::CROWD)) { setTool(new CrowdTool); } imguiSeparatorLine();