mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-31 17:06:41 +00:00
Replace generation and revision by version
This commit is contained in:
parent
3ea4305a60
commit
6b7363bd59
8 changed files with 47 additions and 44 deletions
|
@ -18,8 +18,6 @@ namespace MWRender
|
|||
: mRootNode(root)
|
||||
, mEnabled(enabled)
|
||||
, mId(std::numeric_limits<std::size_t>::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);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef OPENMW_MWRENDER_NAVMESH_H
|
||||
#define OPENMW_MWRENDER_NAVMESH_H
|
||||
|
||||
#include <components/detournavigator/version.hpp>
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include <cstddef>
|
||||
|
@ -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<osg::Group> mRootNode;
|
||||
bool mEnabled;
|
||||
std::size_t mId;
|
||||
std::size_t mGeneration;
|
||||
std::size_t mRevision;
|
||||
DetourNavigator::Version mVersion;
|
||||
osg::ref_ptr<osg::Group> mGroup;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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}));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<float, std::milli>;
|
||||
|
||||
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<FloatMs>(finish - start).count() << "ms" <<
|
||||
" thread=" << std::this_thread::get_id();
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "navmeshtilescache.hpp"
|
||||
#include "dtstatus.hpp"
|
||||
#include "navmeshdata.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
#include <components/misc/guarded.hpp>
|
||||
|
||||
|
@ -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<TilePosition, std::pair<NavMeshTilesCache::Value, NavMeshData>> mUsedTiles;
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue