From 151b2e24b747d9c6c58543943f351729fa52f141 Mon Sep 17 00:00:00 2001 From: Graham Pentheny Date: Mon, 25 Aug 2025 00:02:32 -0400 Subject: [PATCH] Use an enum class rather than an old-style enum for sample partition type --- RecastDemo/Include/Sample.h | 10 +++++----- RecastDemo/Source/Sample.cpp | 18 +++++++++--------- RecastDemo/Source/Sample_SoloMesh.cpp | 6 +++--- RecastDemo/Source/Sample_TileMesh.cpp | 6 +++--- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/RecastDemo/Include/Sample.h b/RecastDemo/Include/Sample.h index 30d3e28e..1034e02f 100644 --- a/RecastDemo/Include/Sample.h +++ b/RecastDemo/Include/Sample.h @@ -68,11 +68,11 @@ enum SamplePolyFlags SAMPLE_POLYFLAGS_ALL = ~0 // 0xff // All abilities. }; -enum SamplePartitionType +enum class SamplePartitionType : uint8_t { - SAMPLE_PARTITION_WATERSHED, - SAMPLE_PARTITION_MONOTONE, - SAMPLE_PARTITION_LAYERS + WATERSHED, + MONOTONE, + LAYERS }; class SampleDebugDraw : public DebugDrawGL @@ -136,7 +136,7 @@ public: int vertsPerPoly; float detailSampleDist; float detailSampleMaxError; - int partitionType; + SamplePartitionType partitionType = SamplePartitionType::WATERSHED; bool filterLowHangingObstacles = true; bool filterLedgeSpans = true; diff --git a/RecastDemo/Source/Sample.cpp b/RecastDemo/Source/Sample.cpp index c4379b85..9f5b08fd 100644 --- a/RecastDemo/Source/Sample.cpp +++ b/RecastDemo/Source/Sample.cpp @@ -182,7 +182,7 @@ void Sample::onMeshChanged(InputGeom* geom) edgeMaxError = buildSettings->edgeMaxError; detailSampleDist = buildSettings->detailSampleDist; detailSampleMaxError = buildSettings->detailSampleMaxError; - partitionType = buildSettings->partitionType; + partitionType = static_cast(buildSettings->partitionType); } } @@ -200,7 +200,7 @@ void Sample::collectSettings(BuildSettings& settings) settings.edgeMaxError = edgeMaxError; settings.detailSampleDist = detailSampleDist; settings.detailSampleMaxError = detailSampleMaxError; - settings.partitionType = partitionType; + settings.partitionType = static_cast(partitionType); } void Sample::resetCommonSettings() @@ -218,7 +218,7 @@ void Sample::resetCommonSettings() vertsPerPoly = 6; detailSampleDist = 6.0f; detailSampleMaxError = 1.0f; - partitionType = SAMPLE_PARTITION_WATERSHED; + partitionType = SamplePartitionType::WATERSHED; } void Sample::drawCommonSettingsUI() @@ -251,17 +251,17 @@ void Sample::drawCommonSettingsUI() DrawFloatSlider(®ionMergeSize, 0.0f, 150.0f, "##Merged Region Size", "Merged Region Size"); ImGui::SeparatorText("Partitioning"); - if (ImGui::RadioButton("Watershed", partitionType == SAMPLE_PARTITION_WATERSHED)) + if (ImGui::RadioButton("Watershed", partitionType == SamplePartitionType::WATERSHED)) { - partitionType = SAMPLE_PARTITION_WATERSHED; + partitionType = SamplePartitionType::WATERSHED; } - if (ImGui::RadioButton("Monotone", partitionType == SAMPLE_PARTITION_MONOTONE)) + if (ImGui::RadioButton("Monotone", partitionType == SamplePartitionType::MONOTONE)) { - partitionType = SAMPLE_PARTITION_MONOTONE; + partitionType = SamplePartitionType::MONOTONE; } - if (ImGui::RadioButton("Layers", partitionType == SAMPLE_PARTITION_LAYERS)) + if (ImGui::RadioButton("Layers", partitionType == SamplePartitionType::LAYERS)) { - partitionType = SAMPLE_PARTITION_LAYERS; + partitionType = SamplePartitionType::LAYERS; } ImGui::SeparatorText("Filtering"); diff --git a/RecastDemo/Source/Sample_SoloMesh.cpp b/RecastDemo/Source/Sample_SoloMesh.cpp index 871ccdde..19a0e74b 100644 --- a/RecastDemo/Source/Sample_SoloMesh.cpp +++ b/RecastDemo/Source/Sample_SoloMesh.cpp @@ -561,7 +561,7 @@ bool Sample_SoloMesh::build() // This is less of a problem if you use a tiled navmesh. // * A good choice for a tiled navmesh with small to medium-sized tiles - if (partitionType == SAMPLE_PARTITION_WATERSHED) + if (partitionType == SamplePartitionType::WATERSHED) { // Prepare for region partitioning, by calculating distance field along the walkable surface. if (!rcBuildDistanceField(buildContext, *compactHeightfield)) @@ -577,7 +577,7 @@ bool Sample_SoloMesh::build() return false; } } - else if (partitionType == SAMPLE_PARTITION_MONOTONE) + else if (partitionType == SamplePartitionType::MONOTONE) { // Partition the walkable surface into contiguous regions. // Monotone partitioning does not need distancefield. @@ -587,7 +587,7 @@ bool Sample_SoloMesh::build() return false; } } - else // SAMPLE_PARTITION_LAYERS + else // SamplePartitionType::LAYERS { // Partition the walkable surface into contiguous regions. // Layer partitioning does not need distancefield. diff --git a/RecastDemo/Source/Sample_TileMesh.cpp b/RecastDemo/Source/Sample_TileMesh.cpp index 314fafc7..0e0d661b 100644 --- a/RecastDemo/Source/Sample_TileMesh.cpp +++ b/RecastDemo/Source/Sample_TileMesh.cpp @@ -1052,7 +1052,7 @@ unsigned char* Sample_TileMesh::buildTileMesh( // if you have large open areas with small obstacles (not a problem if you use tiles) // * good choice to use for tiled navmesh with medium and small sized tiles - if (partitionType == SAMPLE_PARTITION_WATERSHED) + if (partitionType == SamplePartitionType::WATERSHED) { // Prepare for region partitioning, by calculating distance field along the walkable surface. if (!rcBuildDistanceField(buildContext, *compactHeightfield)) @@ -1068,7 +1068,7 @@ unsigned char* Sample_TileMesh::buildTileMesh( return 0; } } - else if (partitionType == SAMPLE_PARTITION_MONOTONE) + else if (partitionType == SamplePartitionType::MONOTONE) { // Partition the walkable surface into simple regions without holes. // Monotone partitioning does not need distancefield. @@ -1083,7 +1083,7 @@ unsigned char* Sample_TileMesh::buildTileMesh( return 0; } } - else // SAMPLE_PARTITION_LAYERS + else // SamplePartitionType::LAYERS { // Partition the walkable surface into simple regions without holes. if (!rcBuildLayerRegions(buildContext, *compactHeightfield, config.borderSize, config.minRegionArea))