Replace generation and revision by version

switch-to-ppa
elsid 3 years ago
parent 3ea4305a60
commit 6b7363bd59
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -18,8 +18,6 @@ namespace MWRender
: mRootNode(root) : mRootNode(root)
, mEnabled(enabled) , mEnabled(enabled)
, mId(std::numeric_limits<std::size_t>::max()) , mId(std::numeric_limits<std::size_t>::max())
, mGeneration(0)
, mRevision(0)
{ {
} }
@ -39,15 +37,14 @@ namespace MWRender
return mEnabled; return mEnabled;
} }
void NavMesh::update(const dtNavMesh& navMesh, const std::size_t id, void NavMesh::update(const dtNavMesh& navMesh, std::size_t id, const DetourNavigator::Version& version,
const std::size_t generation, const std::size_t revision, const DetourNavigator::Settings& settings) const DetourNavigator::Settings& settings)
{ {
if (!mEnabled || (mGroup && mId == id && mGeneration == generation && mRevision == revision)) if (!mEnabled || (mGroup && mId == id && mVersion == version))
return; return;
mId = id; mId = id;
mGeneration = generation; mVersion = version;
mRevision = revision;
if (mGroup) if (mGroup)
mRootNode->removeChild(mGroup); mRootNode->removeChild(mGroup);
mGroup = SceneUtil::createNavMeshGroup(navMesh, settings); mGroup = SceneUtil::createNavMeshGroup(navMesh, settings);

@ -1,6 +1,8 @@
#ifndef OPENMW_MWRENDER_NAVMESH_H #ifndef OPENMW_MWRENDER_NAVMESH_H
#define OPENMW_MWRENDER_NAVMESH_H #define OPENMW_MWRENDER_NAVMESH_H
#include <components/detournavigator/version.hpp>
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <cstddef> #include <cstddef>
@ -28,8 +30,8 @@ namespace MWRender
bool toggle(); bool toggle();
void update(const dtNavMesh& navMesh, const std::size_t number, const std::size_t generation, void update(const dtNavMesh& navMesh, std::size_t id, const DetourNavigator::Version& version,
const std::size_t revision, const DetourNavigator::Settings& settings); const DetourNavigator::Settings& settings);
void reset(); void reset();
@ -46,8 +48,7 @@ namespace MWRender
osg::ref_ptr<osg::Group> mRootNode; osg::ref_ptr<osg::Group> mRootNode;
bool mEnabled; bool mEnabled;
std::size_t mId; std::size_t mId;
std::size_t mGeneration; DetourNavigator::Version mVersion;
std::size_t mRevision;
osg::ref_ptr<osg::Group> mGroup; osg::ref_ptr<osg::Group> mGroup;
}; };
} }

@ -1366,8 +1366,7 @@ namespace MWRender
try try
{ {
const auto locked = it->second->lockConst(); const auto locked = it->second->lockConst();
mNavMesh->update(locked->getImpl(), mNavMeshNumber, locked->getGeneration(), mNavMesh->update(locked->getImpl(), mNavMeshNumber, locked->getVersion(), mNavigator.getSettings());
locked->getNavMeshRevision(), mNavigator.getSettings());
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {

@ -990,8 +990,7 @@ namespace
ASSERT_EQ(navMeshes.size(), 1); ASSERT_EQ(navMeshes.size(), 1);
{ {
const auto navMesh = navMeshes.begin()->second->lockConst(); const auto navMesh = navMeshes.begin()->second->lockConst();
ASSERT_EQ(navMesh->getGeneration(), 1); ASSERT_EQ(navMesh->getVersion(), (Version {1, 4}));
ASSERT_EQ(navMesh->getNavMeshRevision(), 4);
} }
for (int n = 0; n < 10; ++n) for (int n = 0; n < 10; ++n)
@ -1006,8 +1005,7 @@ namespace
ASSERT_EQ(navMeshes.size(), 1); ASSERT_EQ(navMeshes.size(), 1);
{ {
const auto navMesh = navMeshes.begin()->second->lockConst(); const auto navMesh = navMeshes.begin()->second->lockConst();
ASSERT_EQ(navMesh->getGeneration(), 1); ASSERT_EQ(navMesh->getVersion(), (Version {1, 4}));
ASSERT_EQ(navMesh->getNavMeshRevision(), 4);
} }
} }

@ -311,12 +311,7 @@ namespace DetourNavigator
if (recastMesh != nullptr) if (recastMesh != nullptr)
{ {
Version navMeshVersion; const Version navMeshVersion = navMeshCacheItem->lockConst()->getVersion();
{
const auto locked = navMeshCacheItem->lockConst();
navMeshVersion.mGeneration = locked->getGeneration();
navMeshVersion.mRevision = locked->getNavMeshRevision();
}
mRecastMeshManager.get().reportNavMeshChange(job.mChangedTile, mRecastMeshManager.get().reportNavMeshChange(job.mChangedTile,
Version {recastMesh->getGeneration(), recastMesh->getRevision()}, Version {recastMesh->getGeneration(), recastMesh->getRevision()},
navMeshVersion); navMeshVersion);
@ -339,13 +334,13 @@ namespace DetourNavigator
using FloatMs = std::chrono::duration<float, std::milli>; using FloatMs = std::chrono::duration<float, std::milli>;
const auto locked = navMeshCacheItem->lockConst(); const Version version = navMeshCacheItem->lockConst()->getVersion();
Log(Debug::Debug) << std::fixed << std::setprecision(2) << Log(Debug::Debug) << std::fixed << std::setprecision(2) <<
"Cache updated for agent=(" << job.mAgentHalfExtents << ")" << "Cache updated for agent=(" << job.mAgentHalfExtents << ")" <<
" tile=" << job.mChangedTile << " tile=" << job.mChangedTile <<
" status=" << status << " status=" << status <<
" generation=" << locked->getGeneration() << " generation=" << version.mGeneration <<
" revision=" << locked->getNavMeshRevision() << " revision=" << version.mRevision <<
" time=" << std::chrono::duration_cast<FloatMs>(finish - start).count() << "ms" << " time=" << std::chrono::duration_cast<FloatMs>(finish - start).count() << "ms" <<
" thread=" << std::this_thread::get_id(); " thread=" << std::this_thread::get_id();

@ -55,7 +55,7 @@ namespace DetourNavigator
if (dtStatusSucceed(addStatus)) if (dtStatusSucceed(addStatus))
{ {
mUsedTiles[position] = std::make_pair(std::move(cached), std::move(navMeshData)); mUsedTiles[position] = std::make_pair(std::move(cached), std::move(navMeshData));
++mNavMeshRevision; ++mVersion.mRevision;
return UpdateNavMeshStatusBuilder().added(true).removed(removed).getResult(); return UpdateNavMeshStatusBuilder().added(true).removed(removed).getResult();
} }
else else
@ -63,7 +63,7 @@ namespace DetourNavigator
if (removed) if (removed)
{ {
mUsedTiles.erase(position); mUsedTiles.erase(position);
++mNavMeshRevision; ++mVersion.mRevision;
} }
return UpdateNavMeshStatusBuilder().removed(removed).failed((addStatus & DT_OUT_OF_MEMORY) != 0).getResult(); return UpdateNavMeshStatusBuilder().removed(removed).failed((addStatus & DT_OUT_OF_MEMORY) != 0).getResult();
} }
@ -75,7 +75,7 @@ namespace DetourNavigator
if (removed) if (removed)
{ {
mUsedTiles.erase(position); mUsedTiles.erase(position);
++mNavMeshRevision; ++mVersion.mRevision;
} }
return UpdateNavMeshStatusBuilder().removed(removed).getResult(); return UpdateNavMeshStatusBuilder().removed(removed).getResult();
} }

@ -6,6 +6,7 @@
#include "navmeshtilescache.hpp" #include "navmeshtilescache.hpp"
#include "dtstatus.hpp" #include "dtstatus.hpp"
#include "navmeshdata.hpp" #include "navmeshdata.hpp"
#include "version.hpp"
#include <components/misc/guarded.hpp> #include <components/misc/guarded.hpp>
@ -127,7 +128,8 @@ namespace DetourNavigator
{ {
public: public:
NavMeshCacheItem(const NavMeshPtr& impl, std::size_t generation) 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; return *mImpl;
} }
std::size_t getGeneration() const const Version& getVersion() const { return mVersion; }
{
return mGeneration;
}
std::size_t getNavMeshRevision() const
{
return mNavMeshRevision;
}
UpdateNavMeshStatus updateTile(const TilePosition& position, NavMeshTilesCache::Value&& cached, UpdateNavMeshStatus updateTile(const TilePosition& position, NavMeshTilesCache::Value&& cached,
NavMeshData&& navMeshData); NavMeshData&& navMeshData);
@ -153,8 +147,7 @@ namespace DetourNavigator
private: private:
NavMeshPtr mImpl; NavMeshPtr mImpl;
std::size_t mGeneration; Version mVersion;
std::size_t mNavMeshRevision;
std::map<TilePosition, std::pair<NavMeshTilesCache::Value, NavMeshData>> mUsedTiles; std::map<TilePosition, std::pair<NavMeshTilesCache::Value, NavMeshData>> mUsedTiles;
}; };

@ -8,12 +8,32 @@ namespace DetourNavigator
{ {
struct Version struct Version
{ {
std::size_t mGeneration; std::size_t mGeneration = 0;
std::size_t mRevision; 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) 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);
} }
}; };
} }

Loading…
Cancel
Save