From 375dd6f68d1ca5c60df84d1723245da8fe2cef0d Mon Sep 17 00:00:00 2001 From: Graham Pentheny Date: Tue, 22 Jul 2025 00:54:07 -0400 Subject: [PATCH] Removed unnecessary accessors for sample tool state --- RecastDemo/Include/Sample.h | 4 +-- RecastDemo/Source/CrowdTool.cpp | 44 ++++++++------------------------- 2 files changed, 11 insertions(+), 37 deletions(-) diff --git a/RecastDemo/Include/Sample.h b/RecastDemo/Include/Sample.h index 33a0a871..9f7bd1c2 100644 --- a/RecastDemo/Include/Sample.h +++ b/RecastDemo/Include/Sample.h @@ -115,6 +115,7 @@ public: unsigned char navMeshDrawFlags; + SampleToolState* toolStates[static_cast(SampleToolType::MAX_TOOLS)] = {}; protected: float cellSize; float cellHeight; @@ -136,7 +137,6 @@ protected: bool filterWalkableLowHeightSpans = true; SampleTool* tool = nullptr; - SampleToolState* toolStates[static_cast(SampleToolType::MAX_TOOLS)] = {}; BuildContext* buildContext = nullptr; @@ -156,8 +156,6 @@ public: void setContext(BuildContext* ctx) { buildContext = ctx; } void setTool(SampleTool* tool); - SampleToolState* getToolState(const int type) const { return toolStates[type]; } - void setToolState(const int type, SampleToolState* s) { toolStates[type] = s; } SampleDebugDraw& getDebugDraw() { return debugDraw; } diff --git a/RecastDemo/Source/CrowdTool.cpp b/RecastDemo/Source/CrowdTool.cpp index 04dfdac5..d1b27fbb 100644 --- a/RecastDemo/Source/CrowdTool.cpp +++ b/RecastDemo/Source/CrowdTool.cpp @@ -954,31 +954,11 @@ void CrowdToolState::updateAgentParams() } unsigned char updateFlags = 0; - - if (toolParams.anticipateTurns) - { - updateFlags |= DT_CROWD_ANTICIPATE_TURNS; - } - if (toolParams.optimizeVis) - { - updateFlags |= DT_CROWD_OPTIMIZE_VIS; - } - if (toolParams.optimizeTopo) - { - updateFlags |= DT_CROWD_OPTIMIZE_TOPO; - } - if (toolParams.obstacleAvoidance) - { - updateFlags |= DT_CROWD_OBSTACLE_AVOIDANCE; - } - if (toolParams.obstacleAvoidance) - { - updateFlags |= DT_CROWD_OBSTACLE_AVOIDANCE; - } - if (toolParams.separation) - { - updateFlags |= DT_CROWD_SEPARATION; - } + updateFlags |= toolParams.anticipateTurns ? DT_CROWD_ANTICIPATE_TURNS : 0; + updateFlags |= toolParams.optimizeVis ? DT_CROWD_OPTIMIZE_VIS : 0; + updateFlags |= toolParams.optimizeTopo ? DT_CROWD_OPTIMIZE_TOPO : 0; + updateFlags |= toolParams.obstacleAvoidance ? DT_CROWD_OBSTACLE_AVOIDANCE : 0; + updateFlags |= toolParams.separation ? DT_CROWD_SEPARATION : 0; unsigned char obstacleAvoidanceType = static_cast(toolParams.obstacleAvoidanceType); @@ -1040,23 +1020,19 @@ void CrowdToolState::updateTick(const float dt) void CrowdTool::init(Sample* newSample) { - if (this->sample != newSample) - { - this->sample = newSample; - } - - if (!newSample) + sample = newSample; + if (!sample) { return; } - state = static_cast(newSample->getToolState(static_cast(type()))); + state = static_cast(sample->toolStates[static_cast(type())]); if (!state) { state = new CrowdToolState(); - newSample->setToolState(static_cast(type()), state); + sample->toolStates[static_cast(type())] = state; } - state->init(newSample); + state->init(sample); } void CrowdTool::reset() {}