Skip to content

Commit

Permalink
Use version instead of generation and revision for recast mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
elsid committed Sep 6, 2022
1 parent 914edd1 commit 204ab6f
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 69 deletions.
8 changes: 5 additions & 3 deletions apps/benchmarks/detournavigator/navmeshtilescache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ namespace
const CollisionShapeType agentShapeType = CollisionShapeType::Aabb;
const osg::Vec3f agentHalfExtents = generateAgentHalfExtents(0.5, 1.5, random);
const TilePosition tilePosition = generateVec2i(10000, random);
const std::size_t generation = std::uniform_int_distribution<std::size_t>(0, 100)(random);
const std::size_t revision = std::uniform_int_distribution<std::size_t>(0, 10000)(random);
const Version version {
.mGeneration = std::uniform_int_distribution<std::size_t>(0, 100)(random),
.mRevision = std::uniform_int_distribution<std::size_t>(0, 10000)(random),
};
Mesh mesh = generateMesh(triangles, random);
std::vector<CellWater> water;
generateWater(std::back_inserter(water), 1, random);
RecastMesh recastMesh(generation, revision, std::move(mesh), std::move(water),
RecastMesh recastMesh(version, std::move(mesh), std::move(water),
{generateHeightfield(random)}, {generateFlatHeightfield(random)}, {});
return Key {AgentBounds {agentShapeType, agentHalfExtents}, tilePosition, std::move(recastMesh)};
}
Expand Down
8 changes: 3 additions & 5 deletions apps/openmw/mwrender/recastmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,15 @@ namespace MWRender
continue;
}

if (it->second.mGeneration != tile->second->getGeneration()
|| it->second.mRevision != tile->second->getRevision())
if (it->second.mVersion != tile->second->getVersion())
{
const auto group = SceneUtil::createRecastMeshGroup(*tile->second, settings.mRecast);
MWBase::Environment::get().getResourceSystem()->getSceneManager()->recreateShaders(group, "debug");
group->setNodeMask(Mask_Debug);
mRootNode->removeChild(it->second.mValue);
mRootNode->addChild(group);
it->second.mValue = group;
it->second.mGeneration = tile->second->getGeneration();
it->second.mRevision = tile->second->getRevision();
it->second.mVersion = tile->second->getVersion();
}

++it;
Expand All @@ -76,7 +74,7 @@ namespace MWRender
const auto group = SceneUtil::createRecastMeshGroup(*tile.second, settings.mRecast);
MWBase::Environment::get().getResourceSystem()->getSceneManager()->recreateShaders(group, "debug");
group->setNodeMask(Mask_Debug);
mGroups.emplace(tile.first, Group {tile.second->getGeneration(), tile.second->getRevision(), group});
mGroups.emplace(tile.first, Group {tile.second->getVersion(), group});
mRootNode->addChild(group);
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/openmw/mwrender/recastmesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OPENMW_MWRENDER_RECASTMESH_H

#include <components/detournavigator/recastmeshtiles.hpp>
#include <components/detournavigator/version.hpp>

#include <osg/ref_ptr>

Expand Down Expand Up @@ -44,8 +45,7 @@ namespace MWRender
private:
struct Group
{
std::size_t mGeneration;
std::size_t mRevision;
DetourNavigator::Version mVersion;
osg::ref_ptr<osg::Group> mValue;
};

Expand Down
29 changes: 14 additions & 15 deletions apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ namespace
{
const AgentBounds mAgentBounds {CollisionShapeType::Aabb, {1, 2, 3}};
const TilePosition mTilePosition {0, 0};
const std::size_t mGeneration = 0;
const std::size_t mRevision = 0;
const Version mVersion {0, 0};
const Mesh mMesh {makeMesh()};
const std::vector<CellWater> mWater {};
const std::vector<Heightfield> mHeightfields {};
const std::vector<FlatHeightfield> mFlatHeightfields {};
const std::vector<MeshSource> mSources {};
const RecastMesh mRecastMesh {mGeneration, mRevision, mMesh, mWater, mHeightfields, mFlatHeightfields, mSources};
const RecastMesh mRecastMesh {mVersion, mMesh, mWater, mHeightfields, mFlatHeightfields, mSources};
std::unique_ptr<PreparedNavMeshData> mPreparedNavMeshData {makePeparedNavMeshData(3)};

const std::size_t mRecastMeshSize = sizeof(mRecastMesh) + getSize(mRecastMesh);
Expand Down Expand Up @@ -192,7 +191,7 @@ namespace
const std::size_t maxSize = 1;
NavMeshTilesCache cache(maxSize);
const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}});
const RecastMesh unexistentRecastMesh(mGeneration, mRevision, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
const RecastMesh unexistentRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);

cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
EXPECT_FALSE(cache.get(mAgentBounds, mTilePosition, unexistentRecastMesh));
Expand All @@ -204,7 +203,7 @@ namespace
NavMeshTilesCache cache(maxSize);

const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}});
const RecastMesh anotherRecastMesh(mGeneration, mRevision, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
const RecastMesh anotherRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
auto anotherPreparedNavMeshData = makePeparedNavMeshData(3);
const auto copy = clone(*anotherPreparedNavMeshData);

Expand All @@ -222,7 +221,7 @@ namespace
NavMeshTilesCache cache(maxSize);

const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}});
const RecastMesh anotherRecastMesh(mGeneration, mRevision, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
const RecastMesh anotherRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
auto anotherPreparedNavMeshData = makePeparedNavMeshData(3);

const auto value = cache.set(mAgentBounds, mTilePosition, mRecastMesh,
Expand All @@ -238,12 +237,12 @@ namespace
const auto copy = clone(*mPreparedNavMeshData);

const std::vector<CellWater> leastRecentlySetWater(1, CellWater {osg::Vec2i(), Water {1, 0.0f}});
const RecastMesh leastRecentlySetRecastMesh(mGeneration, mRevision, mMesh, leastRecentlySetWater,
const RecastMesh leastRecentlySetRecastMesh(mVersion, mMesh, leastRecentlySetWater,
mHeightfields, mFlatHeightfields, mSources);
auto leastRecentlySetData = makePeparedNavMeshData(3);

const std::vector<CellWater> mostRecentlySetWater(1, CellWater {osg::Vec2i(), Water {2, 0.0f}});
const RecastMesh mostRecentlySetRecastMesh(mGeneration, mRevision, mMesh, mostRecentlySetWater,
const RecastMesh mostRecentlySetRecastMesh(mVersion, mMesh, mostRecentlySetWater,
mHeightfields, mFlatHeightfields, mSources);
auto mostRecentlySetData = makePeparedNavMeshData(3);

Expand All @@ -266,13 +265,13 @@ namespace
NavMeshTilesCache cache(maxSize);

const std::vector<CellWater> leastRecentlyUsedWater(1, CellWater {osg::Vec2i(), Water {1, 0.0f}});
const RecastMesh leastRecentlyUsedRecastMesh(mGeneration, mRevision, mMesh, leastRecentlyUsedWater,
const RecastMesh leastRecentlyUsedRecastMesh(mVersion, mMesh, leastRecentlyUsedWater,
mHeightfields, mFlatHeightfields, mSources);
auto leastRecentlyUsedData = makePeparedNavMeshData(3);
const auto leastRecentlyUsedCopy = clone(*leastRecentlyUsedData);

const std::vector<CellWater> mostRecentlyUsedWater(1, CellWater {osg::Vec2i(), Water {2, 0.0f}});
const RecastMesh mostRecentlyUsedRecastMesh(mGeneration, mRevision, mMesh, mostRecentlyUsedWater,
const RecastMesh mostRecentlyUsedRecastMesh(mVersion, mMesh, mostRecentlyUsedWater,
mHeightfields, mFlatHeightfields, mSources);
auto mostRecentlyUsedData = makePeparedNavMeshData(3);
const auto mostRecentlyUsedCopy = clone(*mostRecentlyUsedData);
Expand Down Expand Up @@ -307,7 +306,7 @@ namespace
NavMeshTilesCache cache(maxSize);

const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}});
const RecastMesh tooLargeRecastMesh(mGeneration, mRevision, mMesh, water,
const RecastMesh tooLargeRecastMesh(mVersion, mMesh, water,
mHeightfields, mFlatHeightfields, mSources);
auto tooLargeData = makePeparedNavMeshData(10);

Expand All @@ -322,12 +321,12 @@ namespace
NavMeshTilesCache cache(maxSize);

const std::vector<CellWater> anotherWater(1, CellWater {osg::Vec2i(), Water {1, 0.0f}});
const RecastMesh anotherRecastMesh(mGeneration, mRevision, mMesh, anotherWater,
const RecastMesh anotherRecastMesh(mVersion, mMesh, anotherWater,
mHeightfields, mFlatHeightfields, mSources);
auto anotherData = makePeparedNavMeshData(3);

const std::vector<CellWater> tooLargeWater(1, CellWater {osg::Vec2i(), Water {2, 0.0f}});
const RecastMesh tooLargeRecastMesh(mGeneration, mRevision, mMesh, tooLargeWater,
const RecastMesh tooLargeRecastMesh(mVersion, mMesh, tooLargeWater,
mHeightfields, mFlatHeightfields, mSources);
auto tooLargeData = makePeparedNavMeshData(10);

Expand All @@ -348,7 +347,7 @@ namespace
NavMeshTilesCache cache(maxSize);

const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}});
const RecastMesh anotherRecastMesh(mGeneration, mRevision, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
const RecastMesh anotherRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
auto anotherData = makePeparedNavMeshData(3);

const auto firstCopy = cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
Expand All @@ -367,7 +366,7 @@ namespace
NavMeshTilesCache cache(maxSize);

const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}});
const RecastMesh anotherRecastMesh(mGeneration, mRevision, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
const RecastMesh anotherRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
auto anotherData = makePeparedNavMeshData(3);

cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
Expand Down
Loading

0 comments on commit 204ab6f

Please sign in to comment.