diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index 1e158667b0..fd240e4a0b 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -32,11 +32,11 @@ namespace DetourNavigator { switch (value) { - case UpdateNavMeshStatus::ignore: + case UpdateNavMeshStatus::ignored: return stream << "ignore"; case UpdateNavMeshStatus::removed: return stream << "removed"; - case UpdateNavMeshStatus::add: + case UpdateNavMeshStatus::added: return stream << "add"; case UpdateNavMeshStatus::replaced: return stream << "replaced"; diff --git a/components/detournavigator/makenavmesh.cpp b/components/detournavigator/makenavmesh.cpp index 5b39230063..a03e9fd8d5 100644 --- a/components/detournavigator/makenavmesh.cpp +++ b/components/detournavigator/makenavmesh.cpp @@ -441,17 +441,47 @@ namespace return NavMeshData(navMeshData, navMeshDataSize); } - UpdateNavMeshStatus makeUpdateNavMeshStatus(bool removed, bool add) + class UpdateNavMeshStatusBuilder { - if (removed && add) - return UpdateNavMeshStatus::replaced; - else if (removed) - return UpdateNavMeshStatus::removed; - else if (add) - return UpdateNavMeshStatus::add; - else - return UpdateNavMeshStatus::ignore; - } + public: + UpdateNavMeshStatusBuilder() = default; + + UpdateNavMeshStatusBuilder removed(bool value) + { + if (value) + set(UpdateNavMeshStatus::removed); + else + unset(UpdateNavMeshStatus::removed); + return *this; + } + + UpdateNavMeshStatusBuilder added(bool value) + { + if (value) + set(UpdateNavMeshStatus::added); + else + unset(UpdateNavMeshStatus::added); + return *this; + } + + UpdateNavMeshStatus getResult() const + { + return mResult; + } + + private: + UpdateNavMeshStatus mResult = UpdateNavMeshStatus::ignored; + + void set(UpdateNavMeshStatus value) + { + mResult = static_cast(static_cast(mResult) | static_cast(value)); + } + + void unset(UpdateNavMeshStatus value) + { + mResult = static_cast(static_cast(mResult) & ~static_cast(value)); + } + }; template unsigned long getMinValuableBitsNumber(const T value) @@ -494,14 +524,14 @@ namespace if (dtStatusSucceed(addStatus)) { locked->setUsedTile(changedTile, std::forward(navMeshData)); - return makeUpdateNavMeshStatus(removed, true); + return UpdateNavMeshStatusBuilder().added(true).removed(removed).getResult(); } else { if (removed) locked->removeUsedTile(changedTile); log("failed to add tile with status=", WriteDtStatus {addStatus}); - return makeUpdateNavMeshStatus(removed, false); + return UpdateNavMeshStatusBuilder().removed(removed).getResult(); } } } @@ -565,7 +595,7 @@ namespace DetourNavigator const auto removed = dtStatusSucceed(navMesh.removeTile(tileRef, nullptr, nullptr)); if (removed) locked->removeUsedTile(changedTile); - return makeUpdateNavMeshStatus(removed, false); + return UpdateNavMeshStatusBuilder().removed(removed).getResult(); }; if (!recastMesh) diff --git a/components/detournavigator/makenavmesh.hpp b/components/detournavigator/makenavmesh.hpp index 55d3e261c5..20198047c3 100644 --- a/components/detournavigator/makenavmesh.hpp +++ b/components/detournavigator/makenavmesh.hpp @@ -20,12 +20,12 @@ namespace DetourNavigator class RecastMesh; struct Settings; - enum class UpdateNavMeshStatus + enum class UpdateNavMeshStatus : unsigned { - ignore, - removed, - add, - replaced + ignored = 0, + removed = 1 << 0, + added = 1 << 1, + replaced = removed | added, }; inline float getLength(const osg::Vec2i& value)