1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-27 12:40:25 +00:00

Use version instead of generation and revision for recast mesh

This commit is contained in:
elsid 2022-08-30 00:11:34 +02:00
parent 914edd1194
commit 204ab6fea3
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
11 changed files with 56 additions and 69 deletions

View file

@ -140,12 +140,14 @@ namespace
const CollisionShapeType agentShapeType = CollisionShapeType::Aabb; const CollisionShapeType agentShapeType = CollisionShapeType::Aabb;
const osg::Vec3f agentHalfExtents = generateAgentHalfExtents(0.5, 1.5, random); const osg::Vec3f agentHalfExtents = generateAgentHalfExtents(0.5, 1.5, random);
const TilePosition tilePosition = generateVec2i(10000, random); const TilePosition tilePosition = generateVec2i(10000, random);
const std::size_t generation = std::uniform_int_distribution<std::size_t>(0, 100)(random); const Version version {
const std::size_t revision = std::uniform_int_distribution<std::size_t>(0, 10000)(random); .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); Mesh mesh = generateMesh(triangles, random);
std::vector<CellWater> water; std::vector<CellWater> water;
generateWater(std::back_inserter(water), 1, random); 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)}, {}); {generateHeightfield(random)}, {generateFlatHeightfield(random)}, {});
return Key {AgentBounds {agentShapeType, agentHalfExtents}, tilePosition, std::move(recastMesh)}; return Key {AgentBounds {agentShapeType, agentHalfExtents}, tilePosition, std::move(recastMesh)};
} }

View file

@ -53,8 +53,7 @@ namespace MWRender
continue; continue;
} }
if (it->second.mGeneration != tile->second->getGeneration() if (it->second.mVersion != tile->second->getVersion())
|| it->second.mRevision != tile->second->getRevision())
{ {
const auto group = SceneUtil::createRecastMeshGroup(*tile->second, settings.mRecast); const auto group = SceneUtil::createRecastMeshGroup(*tile->second, settings.mRecast);
MWBase::Environment::get().getResourceSystem()->getSceneManager()->recreateShaders(group, "debug"); MWBase::Environment::get().getResourceSystem()->getSceneManager()->recreateShaders(group, "debug");
@ -62,8 +61,7 @@ namespace MWRender
mRootNode->removeChild(it->second.mValue); mRootNode->removeChild(it->second.mValue);
mRootNode->addChild(group); mRootNode->addChild(group);
it->second.mValue = group; it->second.mValue = group;
it->second.mGeneration = tile->second->getGeneration(); it->second.mVersion = tile->second->getVersion();
it->second.mRevision = tile->second->getRevision();
} }
++it; ++it;
@ -76,7 +74,7 @@ namespace MWRender
const auto group = SceneUtil::createRecastMeshGroup(*tile.second, settings.mRecast); const auto group = SceneUtil::createRecastMeshGroup(*tile.second, settings.mRecast);
MWBase::Environment::get().getResourceSystem()->getSceneManager()->recreateShaders(group, "debug"); MWBase::Environment::get().getResourceSystem()->getSceneManager()->recreateShaders(group, "debug");
group->setNodeMask(Mask_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); mRootNode->addChild(group);
} }
} }

View file

@ -2,6 +2,7 @@
#define OPENMW_MWRENDER_RECASTMESH_H #define OPENMW_MWRENDER_RECASTMESH_H
#include <components/detournavigator/recastmeshtiles.hpp> #include <components/detournavigator/recastmeshtiles.hpp>
#include <components/detournavigator/version.hpp>
#include <osg/ref_ptr> #include <osg/ref_ptr>
@ -44,8 +45,7 @@ namespace MWRender
private: private:
struct Group struct Group
{ {
std::size_t mGeneration; DetourNavigator::Version mVersion;
std::size_t mRevision;
osg::ref_ptr<osg::Group> mValue; osg::ref_ptr<osg::Group> mValue;
}; };

View file

@ -97,14 +97,13 @@ namespace
{ {
const AgentBounds mAgentBounds {CollisionShapeType::Aabb, {1, 2, 3}}; const AgentBounds mAgentBounds {CollisionShapeType::Aabb, {1, 2, 3}};
const TilePosition mTilePosition {0, 0}; const TilePosition mTilePosition {0, 0};
const std::size_t mGeneration = 0; const Version mVersion {0, 0};
const std::size_t mRevision = 0;
const Mesh mMesh {makeMesh()}; const Mesh mMesh {makeMesh()};
const std::vector<CellWater> mWater {}; const std::vector<CellWater> mWater {};
const std::vector<Heightfield> mHeightfields {}; const std::vector<Heightfield> mHeightfields {};
const std::vector<FlatHeightfield> mFlatHeightfields {}; const std::vector<FlatHeightfield> mFlatHeightfields {};
const std::vector<MeshSource> mSources {}; 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)}; std::unique_ptr<PreparedNavMeshData> mPreparedNavMeshData {makePeparedNavMeshData(3)};
const std::size_t mRecastMeshSize = sizeof(mRecastMesh) + getSize(mRecastMesh); const std::size_t mRecastMeshSize = sizeof(mRecastMesh) + getSize(mRecastMesh);
@ -192,7 +191,7 @@ namespace
const std::size_t maxSize = 1; const std::size_t maxSize = 1;
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}}); 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)); cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
EXPECT_FALSE(cache.get(mAgentBounds, mTilePosition, unexistentRecastMesh)); EXPECT_FALSE(cache.get(mAgentBounds, mTilePosition, unexistentRecastMesh));
@ -204,7 +203,7 @@ namespace
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}}); 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); auto anotherPreparedNavMeshData = makePeparedNavMeshData(3);
const auto copy = clone(*anotherPreparedNavMeshData); const auto copy = clone(*anotherPreparedNavMeshData);
@ -222,7 +221,7 @@ namespace
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}}); 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); auto anotherPreparedNavMeshData = makePeparedNavMeshData(3);
const auto value = cache.set(mAgentBounds, mTilePosition, mRecastMesh, const auto value = cache.set(mAgentBounds, mTilePosition, mRecastMesh,
@ -238,12 +237,12 @@ namespace
const auto copy = clone(*mPreparedNavMeshData); const auto copy = clone(*mPreparedNavMeshData);
const std::vector<CellWater> leastRecentlySetWater(1, CellWater {osg::Vec2i(), Water {1, 0.0f}}); 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); mHeightfields, mFlatHeightfields, mSources);
auto leastRecentlySetData = makePeparedNavMeshData(3); auto leastRecentlySetData = makePeparedNavMeshData(3);
const std::vector<CellWater> mostRecentlySetWater(1, CellWater {osg::Vec2i(), Water {2, 0.0f}}); 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); mHeightfields, mFlatHeightfields, mSources);
auto mostRecentlySetData = makePeparedNavMeshData(3); auto mostRecentlySetData = makePeparedNavMeshData(3);
@ -266,13 +265,13 @@ namespace
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<CellWater> leastRecentlyUsedWater(1, CellWater {osg::Vec2i(), Water {1, 0.0f}}); 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); mHeightfields, mFlatHeightfields, mSources);
auto leastRecentlyUsedData = makePeparedNavMeshData(3); auto leastRecentlyUsedData = makePeparedNavMeshData(3);
const auto leastRecentlyUsedCopy = clone(*leastRecentlyUsedData); const auto leastRecentlyUsedCopy = clone(*leastRecentlyUsedData);
const std::vector<CellWater> mostRecentlyUsedWater(1, CellWater {osg::Vec2i(), Water {2, 0.0f}}); 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); mHeightfields, mFlatHeightfields, mSources);
auto mostRecentlyUsedData = makePeparedNavMeshData(3); auto mostRecentlyUsedData = makePeparedNavMeshData(3);
const auto mostRecentlyUsedCopy = clone(*mostRecentlyUsedData); const auto mostRecentlyUsedCopy = clone(*mostRecentlyUsedData);
@ -307,7 +306,7 @@ namespace
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}}); 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); mHeightfields, mFlatHeightfields, mSources);
auto tooLargeData = makePeparedNavMeshData(10); auto tooLargeData = makePeparedNavMeshData(10);
@ -322,12 +321,12 @@ namespace
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<CellWater> anotherWater(1, CellWater {osg::Vec2i(), Water {1, 0.0f}}); 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); mHeightfields, mFlatHeightfields, mSources);
auto anotherData = makePeparedNavMeshData(3); auto anotherData = makePeparedNavMeshData(3);
const std::vector<CellWater> tooLargeWater(1, CellWater {osg::Vec2i(), Water {2, 0.0f}}); 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); mHeightfields, mFlatHeightfields, mSources);
auto tooLargeData = makePeparedNavMeshData(10); auto tooLargeData = makePeparedNavMeshData(10);
@ -348,7 +347,7 @@ namespace
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}}); 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); auto anotherData = makePeparedNavMeshData(3);
const auto firstCopy = cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData)); const auto firstCopy = cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
@ -367,7 +366,7 @@ namespace
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<CellWater> water(1, CellWater {osg::Vec2i(), Water {1, 0.0f}}); 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); auto anotherData = makePeparedNavMeshData(3);
cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData)); cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));

View file

@ -58,8 +58,7 @@ namespace
struct DetourNavigatorRecastMeshBuilderTest : Test struct DetourNavigatorRecastMeshBuilderTest : Test
{ {
TileBounds mBounds; TileBounds mBounds;
const std::size_t mGeneration = 0; const Version mVersion {0, 0};
const std::size_t mRevision = 0;
const osg::ref_ptr<const Resource::BulletShape> mSource {nullptr}; const osg::ref_ptr<const Resource::BulletShape> mSource {nullptr};
const ObjectTransform mObjectTransform {ESM::Position {{0, 0, 0}, {0, 0, 0}}, 0.0f}; const ObjectTransform mObjectTransform {ESM::Position {{0, 0, 0}, {0, 0, 0}}, 0.0f};
@ -75,7 +74,7 @@ namespace
TEST_F(DetourNavigatorRecastMeshBuilderTest, create_for_empty_should_return_empty) TEST_F(DetourNavigatorRecastMeshBuilderTest, create_for_empty_should_return_empty)
{ {
RecastMeshBuilder builder(mBounds); RecastMeshBuilder builder(mBounds);
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>()); EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>());
EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>()); EXPECT_EQ(recastMesh->getMesh().getIndices(), std::vector<int>());
EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>()); EXPECT_EQ(recastMesh->getMesh().getAreaTypes(), std::vector<AreaType>());
@ -90,7 +89,7 @@ namespace
RecastMeshBuilder builder(mBounds); RecastMeshBuilder builder(mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(),
AreaType_ground, mSource, mObjectTransform); AreaType_ground, mSource, mObjectTransform);
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
-1, -1, 0, -1, -1, 0,
-1, 1, 0, -1, 1, 0,
@ -111,7 +110,7 @@ namespace
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)), btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
AreaType_ground, mSource, mObjectTransform AreaType_ground, mSource, mObjectTransform
); );
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
0, 0, 3, 0, 0, 3,
0, 4, 3, 0, 4, 3,
@ -128,7 +127,7 @@ namespace
RecastMeshBuilder builder(mBounds); RecastMeshBuilder builder(mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(),
AreaType_ground, mSource, mObjectTransform); AreaType_ground, mSource, mObjectTransform);
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
-0.5, -0.5, 0, -0.5, -0.5, 0,
-0.5, 0.5, 0, -0.5, 0.5, 0,
@ -145,7 +144,7 @@ namespace
RecastMeshBuilder builder(mBounds); RecastMeshBuilder builder(mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(),
AreaType_ground, mSource, mObjectTransform); AreaType_ground, mSource, mObjectTransform);
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
-1, -1, -2, -1, -1, -2,
-1, -1, 2, -1, -1, 2,
@ -192,7 +191,7 @@ namespace
btTransform::getIdentity(), btTransform::getIdentity(),
AreaType_ground, mSource, mObjectTransform AreaType_ground, mSource, mObjectTransform
); );
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
-1, -1, -2, -1, -1, -2,
-1, -1, 0, -1, -1, 0,
@ -239,7 +238,7 @@ namespace
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)), btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
AreaType_ground, mSource, mObjectTransform AreaType_ground, mSource, mObjectTransform
); );
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
0, 0, 3, 0, 0, 3,
0, 4, 3, 0, 4, 3,
@ -263,7 +262,7 @@ namespace
btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)), btTransform(btMatrix3x3::getIdentity().scaled(btVector3(1, 2, 3)), btVector3(1, 2, 3)),
AreaType_ground, mSource, mObjectTransform AreaType_ground, mSource, mObjectTransform
); );
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
1, 2, 12, 1, 2, 12,
1, 10, 12, 1, 10, 12,
@ -285,7 +284,7 @@ namespace
btTransform::getIdentity(), btTransform::getIdentity(),
AreaType_ground, mSource, mObjectTransform AreaType_ground, mSource, mObjectTransform
); );
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
-3, -3, 0, -3, -3, 0,
-3, -2, 0, -3, -2, 0,
@ -312,7 +311,7 @@ namespace
btTransform::getIdentity(), btTransform::getIdentity(),
AreaType_ground, mSource, mObjectTransform AreaType_ground, mSource, mObjectTransform
); );
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
-3, -3, 0, -3, -3, 0,
-3, -2, 0, -3, -2, 0,
@ -337,7 +336,7 @@ namespace
static_cast<btScalar>(-osg::PI_4))), static_cast<btScalar>(-osg::PI_4))),
AreaType_ground, mSource, mObjectTransform AreaType_ground, mSource, mObjectTransform
); );
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_THAT(recastMesh->getMesh().getVertices(), Pointwise(FloatNear(1e-5f), std::vector<float>({ EXPECT_THAT(recastMesh->getMesh().getVertices(), Pointwise(FloatNear(1e-5f), std::vector<float>({
0, -4.24264049530029296875f, 4.44089209850062616169452667236328125e-16f, 0, -4.24264049530029296875f, 4.44089209850062616169452667236328125e-16f,
0, -3.535533905029296875f, -0.707106769084930419921875f, 0, -3.535533905029296875f, -0.707106769084930419921875f,
@ -362,7 +361,7 @@ namespace
static_cast<btScalar>(osg::PI_4))), static_cast<btScalar>(osg::PI_4))),
AreaType_ground, mSource, mObjectTransform AreaType_ground, mSource, mObjectTransform
); );
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_THAT(recastMesh->getMesh().getVertices(), Pointwise(FloatNear(1e-5f), std::vector<float>({ EXPECT_THAT(recastMesh->getMesh().getVertices(), Pointwise(FloatNear(1e-5f), std::vector<float>({
-4.24264049530029296875f, 0, 4.44089209850062616169452667236328125e-16f, -4.24264049530029296875f, 0, 4.44089209850062616169452667236328125e-16f,
-3.535533905029296875f, 0, -0.707106769084930419921875f, -3.535533905029296875f, 0, -0.707106769084930419921875f,
@ -387,7 +386,7 @@ namespace
static_cast<btScalar>(osg::PI_4))), static_cast<btScalar>(osg::PI_4))),
AreaType_ground, mSource, mObjectTransform AreaType_ground, mSource, mObjectTransform
); );
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_THAT(recastMesh->getMesh().getVertices(), Pointwise(FloatNear(1e-5f), std::vector<float>({ EXPECT_THAT(recastMesh->getMesh().getVertices(), Pointwise(FloatNear(1e-5f), std::vector<float>({
-1.41421353816986083984375f, -1.1102230246251565404236316680908203125e-16f, 0, -1.41421353816986083984375f, -1.1102230246251565404236316680908203125e-16f, 0,
1.1102230246251565404236316680908203125e-16f, -1.41421353816986083984375f, 0, 1.1102230246251565404236316680908203125e-16f, -1.41421353816986083984375f, 0,
@ -416,7 +415,7 @@ namespace
btTransform::getIdentity(), btTransform::getIdentity(),
AreaType_null, mSource, mObjectTransform AreaType_null, mSource, mObjectTransform
); );
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
-3, -3, 0, -3, -3, 0,
-3, -2, 0, -3, -2, 0,
@ -433,7 +432,7 @@ namespace
{ {
RecastMeshBuilder builder(mBounds); RecastMeshBuilder builder(mBounds);
builder.addWater(osg::Vec2i(1, 2), Water {1000, 300.0f}); builder.addWater(osg::Vec2i(1, 2), Water {1000, 300.0f});
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getWater(), std::vector<CellWater>({ EXPECT_EQ(recastMesh->getWater(), std::vector<CellWater>({
CellWater {osg::Vec2i(1, 2), Water {1000, 300.0f}} CellWater {osg::Vec2i(1, 2), Water {1000, 300.0f}}
})); }));
@ -448,7 +447,7 @@ namespace
RecastMeshBuilder builder(mBounds); RecastMeshBuilder builder(mBounds);
builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), AreaType_ground, mSource, mObjectTransform); builder.addObject(static_cast<const btCollisionShape&>(shape), btTransform::getIdentity(), AreaType_ground, mSource, mObjectTransform);
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({ EXPECT_EQ(recastMesh->getMesh().getVertices(), std::vector<float>({
-1, -1, 0, -1, -1, 0,
-1, 1, 0, -1, 1, 0,
@ -467,7 +466,7 @@ namespace
mBounds.mMin = osg::Vec2f(100, 100); mBounds.mMin = osg::Vec2f(100, 100);
RecastMeshBuilder builder(mBounds); RecastMeshBuilder builder(mBounds);
builder.addHeightfield(cellPosition, cellSize, height); builder.addHeightfield(cellPosition, cellSize, height);
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
EXPECT_EQ(recastMesh->getFlatHeightfields(), std::vector<FlatHeightfield>({ EXPECT_EQ(recastMesh->getFlatHeightfields(), std::vector<FlatHeightfield>({
FlatHeightfield {cellPosition, cellSize, height}, FlatHeightfield {cellPosition, cellSize, height},
})); }));
@ -487,7 +486,7 @@ namespace
const float maxHeight = 8; const float maxHeight = 8;
RecastMeshBuilder builder(mBounds); RecastMeshBuilder builder(mBounds);
builder.addHeightfield(cellPosition, cellSize, heights.data(), size, minHeight, maxHeight); builder.addHeightfield(cellPosition, cellSize, heights.data(), size, minHeight, maxHeight);
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
Heightfield expected; Heightfield expected;
expected.mCellPosition = cellPosition; expected.mCellPosition = cellPosition;
expected.mCellSize = cellSize; expected.mCellSize = cellSize;
@ -519,7 +518,7 @@ namespace
const float maxHeight = 8; const float maxHeight = 8;
RecastMeshBuilder builder(maxCellTileBounds(cellPosition, cellSize)); RecastMeshBuilder builder(maxCellTileBounds(cellPosition, cellSize));
builder.addHeightfield(cellPosition, cellSize, heights.data(), size, minHeight, maxHeight); builder.addHeightfield(cellPosition, cellSize, heights.data(), size, minHeight, maxHeight);
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
Heightfield expected; Heightfield expected;
expected.mCellPosition = cellPosition; expected.mCellPosition = cellPosition;
expected.mCellSize = cellSize; expected.mCellSize = cellSize;
@ -552,7 +551,7 @@ namespace
mBounds.mMin = osg::Vec2f(750, 750); mBounds.mMin = osg::Vec2f(750, 750);
RecastMeshBuilder builder(mBounds); RecastMeshBuilder builder(mBounds);
builder.addHeightfield(cellPosition, cellSize, heights.data(), size, minHeight, maxHeight); builder.addHeightfield(cellPosition, cellSize, heights.data(), size, minHeight, maxHeight);
const auto recastMesh = std::move(builder).create(mGeneration, mRevision); const auto recastMesh = std::move(builder).create(mVersion);
Heightfield expected; Heightfield expected;
expected.mCellPosition = cellPosition; expected.mCellPosition = cellPosition;
expected.mCellSize = cellSize; expected.mCellSize = cellSize;

View file

@ -513,9 +513,7 @@ namespace DetourNavigator
const Job& job, const GuardedNavMeshCacheItem& navMeshCacheItem, const RecastMesh& recastMesh) const Job& job, const GuardedNavMeshCacheItem& navMeshCacheItem, const RecastMesh& recastMesh)
{ {
const Version navMeshVersion = navMeshCacheItem.lockConst()->getVersion(); const Version navMeshVersion = navMeshCacheItem.lockConst()->getVersion();
mRecastMeshManager.get().reportNavMeshChange(job.mChangedTile, mRecastMeshManager.get().reportNavMeshChange(job.mChangedTile, recastMesh.getVersion(), navMeshVersion);
Version {recastMesh.getGeneration(), recastMesh.getRevision()},
navMeshVersion);
if (status == UpdateNavMeshStatus::removed || status == UpdateNavMeshStatus::lost) if (status == UpdateNavMeshStatus::removed || status == UpdateNavMeshStatus::lost)
{ {

View file

@ -18,11 +18,10 @@ namespace DetourNavigator
mAreaTypes = std::move(areaTypes); mAreaTypes = std::move(areaTypes);
} }
RecastMesh::RecastMesh(std::size_t generation, std::size_t revision, Mesh mesh, std::vector<CellWater> water, RecastMesh::RecastMesh(const Version& version, Mesh mesh, std::vector<CellWater> water,
std::vector<Heightfield> heightfields, std::vector<FlatHeightfield> flatHeightfields, std::vector<Heightfield> heightfields, std::vector<FlatHeightfield> flatHeightfields,
std::vector<MeshSource> meshSources) std::vector<MeshSource> meshSources)
: mGeneration(generation) : mVersion(version)
, mRevision(revision)
, mMesh(std::move(mesh)) , mMesh(std::move(mesh))
, mWater(std::move(water)) , mWater(std::move(water))
, mHeightfields(std::move(heightfields)) , mHeightfields(std::move(heightfields))

View file

@ -3,6 +3,7 @@
#include "areatype.hpp" #include "areatype.hpp"
#include "objecttransform.hpp" #include "objecttransform.hpp"
#include "version.hpp"
#include <components/bullethelpers/operators.hpp> #include <components/bullethelpers/operators.hpp>
#include <components/resource/bulletshape.hpp> #include <components/resource/bulletshape.hpp>
@ -129,19 +130,11 @@ namespace DetourNavigator
class RecastMesh class RecastMesh
{ {
public: public:
RecastMesh(std::size_t generation, std::size_t revision, Mesh mesh, std::vector<CellWater> water, explicit RecastMesh(const Version& version, Mesh mesh, std::vector<CellWater> water,
std::vector<Heightfield> heightfields, std::vector<FlatHeightfield> flatHeightfields, std::vector<Heightfield> heightfields, std::vector<FlatHeightfield> flatHeightfields,
std::vector<MeshSource> sources); std::vector<MeshSource> sources);
std::size_t getGeneration() const const Version& getVersion() const noexcept { return mVersion; }
{
return mGeneration;
}
std::size_t getRevision() const
{
return mRevision;
}
const Mesh& getMesh() const noexcept { return mMesh; } const Mesh& getMesh() const noexcept { return mMesh; }
@ -163,8 +156,7 @@ namespace DetourNavigator
const std::vector<MeshSource>& getMeshSources() const noexcept { return mMeshSources; } const std::vector<MeshSource>& getMeshSources() const noexcept { return mMeshSources; }
private: private:
std::size_t mGeneration; Version mVersion;
std::size_t mRevision;
Mesh mMesh; Mesh mMesh;
std::vector<CellWater> mWater; std::vector<CellWater> mWater;
std::vector<Heightfield> mHeightfields; std::vector<Heightfield> mHeightfields;

View file

@ -272,13 +272,13 @@ namespace DetourNavigator
mHeightfields.push_back(std::move(heightfield)); mHeightfields.push_back(std::move(heightfield));
} }
std::shared_ptr<RecastMesh> RecastMeshBuilder::create(std::size_t generation, std::size_t revision) && std::shared_ptr<RecastMesh> RecastMeshBuilder::create(const Version& version) &&
{ {
mTriangles.erase(std::remove_if(mTriangles.begin(), mTriangles.end(), isNan), mTriangles.end()); mTriangles.erase(std::remove_if(mTriangles.begin(), mTriangles.end(), isNan), mTriangles.end());
std::sort(mTriangles.begin(), mTriangles.end()); std::sort(mTriangles.begin(), mTriangles.end());
std::sort(mWater.begin(), mWater.end()); std::sort(mWater.begin(), mWater.end());
Mesh mesh = makeMesh(std::move(mTriangles)); Mesh mesh = makeMesh(std::move(mTriangles));
return std::make_shared<RecastMesh>(generation, revision, std::move(mesh), std::move(mWater), return std::make_shared<RecastMesh>(version, std::move(mesh), std::move(mWater),
std::move(mHeightfields), std::move(mFlatHeightfields), std::move(mHeightfields), std::move(mFlatHeightfields),
std::move(mSources)); std::move(mSources));
} }

View file

@ -58,7 +58,7 @@ namespace DetourNavigator
void addHeightfield(const osg::Vec2i& cellPosition, int cellSize, const float* heights, std::size_t size, void addHeightfield(const osg::Vec2i& cellPosition, int cellSize, const float* heights, std::size_t size,
float minHeight, float maxHeight); float minHeight, float maxHeight);
std::shared_ptr<RecastMesh> create(std::size_t generation, std::size_t revision) &&; std::shared_ptr<RecastMesh> create(const Version& version) &&;
private: private:
const TileBounds mBounds; const TileBounds mBounds;

View file

@ -143,7 +143,7 @@ namespace DetourNavigator
} }
for (const auto& [instance, objectTransform, shape, transform, areaType] : objects) for (const auto& [instance, objectTransform, shape, transform, areaType] : objects)
builder.addObject(shape, transform, areaType, instance->getSource(), objectTransform); builder.addObject(shape, transform, areaType, instance->getSource(), objectTransform);
return std::move(builder).create(mGeneration, revision); return std::move(builder).create(Version {.mGeneration = mGeneration, .mRevision = revision});
} }
bool RecastMeshManager::isEmpty() const bool RecastMeshManager::isEmpty() const