From 6b7363bd59c199409c7c8358ccecf93a4f18531f Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 1 Nov 2021 20:21:27 +0100 Subject: [PATCH] Replace generation and revision by version --- apps/openmw/mwrender/navmesh.cpp | 11 +++----- apps/openmw/mwrender/navmesh.hpp | 9 ++++--- apps/openmw/mwrender/renderingmanager.cpp | 3 +-- .../detournavigator/navigator.cpp | 6 ++--- .../detournavigator/asyncnavmeshupdater.cpp | 13 +++------- .../detournavigator/navmeshcacheitem.cpp | 6 ++--- .../detournavigator/navmeshcacheitem.hpp | 17 ++++-------- components/detournavigator/version.hpp | 26 ++++++++++++++++--- 8 files changed, 47 insertions(+), 44 deletions(-) diff --git a/apps/openmw/mwrender/navmesh.cpp b/apps/openmw/mwrender/navmesh.cpp index 548e85ad10..7cf045d0bd 100644 --- a/apps/openmw/mwrender/navmesh.cpp +++ b/apps/openmw/mwrender/navmesh.cpp @@ -18,8 +18,6 @@ namespace MWRender : mRootNode(root) , mEnabled(enabled) , mId(std::numeric_limits::max()) - , mGeneration(0) - , mRevision(0) { } @@ -39,15 +37,14 @@ namespace MWRender return mEnabled; } - void NavMesh::update(const dtNavMesh& navMesh, const std::size_t id, - const std::size_t generation, const std::size_t revision, const DetourNavigator::Settings& settings) + void NavMesh::update(const dtNavMesh& navMesh, std::size_t id, const DetourNavigator::Version& version, + const DetourNavigator::Settings& settings) { - if (!mEnabled || (mGroup && mId == id && mGeneration == generation && mRevision == revision)) + if (!mEnabled || (mGroup && mId == id && mVersion == version)) return; mId = id; - mGeneration = generation; - mRevision = revision; + mVersion = version; if (mGroup) mRootNode->removeChild(mGroup); mGroup = SceneUtil::createNavMeshGroup(navMesh, settings); diff --git a/apps/openmw/mwrender/navmesh.hpp b/apps/openmw/mwrender/navmesh.hpp index 4c71dc74ec..c3aa31e05b 100644 --- a/apps/openmw/mwrender/navmesh.hpp +++ b/apps/openmw/mwrender/navmesh.hpp @@ -1,6 +1,8 @@ #ifndef OPENMW_MWRENDER_NAVMESH_H #define OPENMW_MWRENDER_NAVMESH_H +#include + #include #include @@ -28,8 +30,8 @@ namespace MWRender bool toggle(); - void update(const dtNavMesh& navMesh, const std::size_t number, const std::size_t generation, - const std::size_t revision, const DetourNavigator::Settings& settings); + void update(const dtNavMesh& navMesh, std::size_t id, const DetourNavigator::Version& version, + const DetourNavigator::Settings& settings); void reset(); @@ -46,8 +48,7 @@ namespace MWRender osg::ref_ptr mRootNode; bool mEnabled; std::size_t mId; - std::size_t mGeneration; - std::size_t mRevision; + DetourNavigator::Version mVersion; osg::ref_ptr mGroup; }; } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 30be74c839..58a1383c7c 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1366,8 +1366,7 @@ namespace MWRender try { const auto locked = it->second->lockConst(); - mNavMesh->update(locked->getImpl(), mNavMeshNumber, locked->getGeneration(), - locked->getNavMeshRevision(), mNavigator.getSettings()); + mNavMesh->update(locked->getImpl(), mNavMeshNumber, locked->getVersion(), mNavigator.getSettings()); } catch (const std::exception& e) { diff --git a/apps/openmw_test_suite/detournavigator/navigator.cpp b/apps/openmw_test_suite/detournavigator/navigator.cpp index d7422cda8b..0f4f1e3345 100644 --- a/apps/openmw_test_suite/detournavigator/navigator.cpp +++ b/apps/openmw_test_suite/detournavigator/navigator.cpp @@ -990,8 +990,7 @@ namespace ASSERT_EQ(navMeshes.size(), 1); { const auto navMesh = navMeshes.begin()->second->lockConst(); - ASSERT_EQ(navMesh->getGeneration(), 1); - ASSERT_EQ(navMesh->getNavMeshRevision(), 4); + ASSERT_EQ(navMesh->getVersion(), (Version {1, 4})); } for (int n = 0; n < 10; ++n) @@ -1006,8 +1005,7 @@ namespace ASSERT_EQ(navMeshes.size(), 1); { const auto navMesh = navMeshes.begin()->second->lockConst(); - ASSERT_EQ(navMesh->getGeneration(), 1); - ASSERT_EQ(navMesh->getNavMeshRevision(), 4); + ASSERT_EQ(navMesh->getVersion(), (Version {1, 4})); } } diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index 966e07bc5a..583fd1162a 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -311,12 +311,7 @@ namespace DetourNavigator if (recastMesh != nullptr) { - Version navMeshVersion; - { - const auto locked = navMeshCacheItem->lockConst(); - navMeshVersion.mGeneration = locked->getGeneration(); - navMeshVersion.mRevision = locked->getNavMeshRevision(); - } + const Version navMeshVersion = navMeshCacheItem->lockConst()->getVersion(); mRecastMeshManager.get().reportNavMeshChange(job.mChangedTile, Version {recastMesh->getGeneration(), recastMesh->getRevision()}, navMeshVersion); @@ -339,13 +334,13 @@ namespace DetourNavigator using FloatMs = std::chrono::duration; - const auto locked = navMeshCacheItem->lockConst(); + const Version version = navMeshCacheItem->lockConst()->getVersion(); Log(Debug::Debug) << std::fixed << std::setprecision(2) << "Cache updated for agent=(" << job.mAgentHalfExtents << ")" << " tile=" << job.mChangedTile << " status=" << status << - " generation=" << locked->getGeneration() << - " revision=" << locked->getNavMeshRevision() << + " generation=" << version.mGeneration << + " revision=" << version.mRevision << " time=" << std::chrono::duration_cast(finish - start).count() << "ms" << " thread=" << std::this_thread::get_id(); diff --git a/components/detournavigator/navmeshcacheitem.cpp b/components/detournavigator/navmeshcacheitem.cpp index ee6f3308d0..889b764c3c 100644 --- a/components/detournavigator/navmeshcacheitem.cpp +++ b/components/detournavigator/navmeshcacheitem.cpp @@ -55,7 +55,7 @@ namespace DetourNavigator if (dtStatusSucceed(addStatus)) { mUsedTiles[position] = std::make_pair(std::move(cached), std::move(navMeshData)); - ++mNavMeshRevision; + ++mVersion.mRevision; return UpdateNavMeshStatusBuilder().added(true).removed(removed).getResult(); } else @@ -63,7 +63,7 @@ namespace DetourNavigator if (removed) { mUsedTiles.erase(position); - ++mNavMeshRevision; + ++mVersion.mRevision; } return UpdateNavMeshStatusBuilder().removed(removed).failed((addStatus & DT_OUT_OF_MEMORY) != 0).getResult(); } @@ -75,7 +75,7 @@ namespace DetourNavigator if (removed) { mUsedTiles.erase(position); - ++mNavMeshRevision; + ++mVersion.mRevision; } return UpdateNavMeshStatusBuilder().removed(removed).getResult(); } diff --git a/components/detournavigator/navmeshcacheitem.hpp b/components/detournavigator/navmeshcacheitem.hpp index ac68caedb3..6fc9b17189 100644 --- a/components/detournavigator/navmeshcacheitem.hpp +++ b/components/detournavigator/navmeshcacheitem.hpp @@ -6,6 +6,7 @@ #include "navmeshtilescache.hpp" #include "dtstatus.hpp" #include "navmeshdata.hpp" +#include "version.hpp" #include @@ -127,7 +128,8 @@ namespace DetourNavigator { public: NavMeshCacheItem(const NavMeshPtr& impl, std::size_t generation) - : mImpl(impl), mGeneration(generation), mNavMeshRevision(0) + : mImpl(impl) + , mVersion {generation, 0} { } @@ -136,15 +138,7 @@ namespace DetourNavigator return *mImpl; } - std::size_t getGeneration() const - { - return mGeneration; - } - - std::size_t getNavMeshRevision() const - { - return mNavMeshRevision; - } + const Version& getVersion() const { return mVersion; } UpdateNavMeshStatus updateTile(const TilePosition& position, NavMeshTilesCache::Value&& cached, NavMeshData&& navMeshData); @@ -153,8 +147,7 @@ namespace DetourNavigator private: NavMeshPtr mImpl; - std::size_t mGeneration; - std::size_t mNavMeshRevision; + Version mVersion; std::map> mUsedTiles; }; diff --git a/components/detournavigator/version.hpp b/components/detournavigator/version.hpp index c9de98459d..792680a7d5 100644 --- a/components/detournavigator/version.hpp +++ b/components/detournavigator/version.hpp @@ -8,12 +8,32 @@ namespace DetourNavigator { struct Version { - std::size_t mGeneration; - std::size_t mRevision; + std::size_t mGeneration = 0; + std::size_t mRevision = 0; + + friend inline auto tie(const Version& value) + { + return std::tie(value.mGeneration, value.mRevision); + } friend inline bool operator<(const Version& lhs, const Version& rhs) { - return std::tie(lhs.mGeneration, lhs.mRevision) < std::tie(rhs.mGeneration, rhs.mRevision); + return tie(lhs) < tie(rhs); + } + + friend inline bool operator<=(const Version& lhs, const Version& rhs) + { + return tie(lhs) <= tie(rhs); + } + + friend inline bool operator==(const Version& lhs, const Version& rhs) + { + return tie(lhs) == tie(rhs); + } + + friend inline bool operator!=(const Version& lhs, const Version& rhs) + { + return !(lhs == rhs); } }; }