From a1549321d759510ac3a73164b7bb10e376ea9593 Mon Sep 17 00:00:00 2001 From: elsid Date: Wed, 14 Jul 2021 17:30:47 +0200 Subject: [PATCH] Move Water struct out of RecastMesh class --- .../detournavigator/navmeshtilescache.cpp | 4 +-- .../detournavigator/navmeshtilescache.cpp | 28 +++++++++---------- .../detournavigator/recastmeshbuilder.cpp | 6 ++-- components/detournavigator/makenavmesh.cpp | 2 +- .../detournavigator/navmeshtilescache.hpp | 2 +- components/detournavigator/recastmesh.hpp | 16 +++++------ .../detournavigator/recastmeshbuilder.cpp | 2 +- .../detournavigator/recastmeshbuilder.hpp | 2 +- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/apps/benchmarks/detournavigator/navmeshtilescache.cpp b/apps/benchmarks/detournavigator/navmeshtilescache.cpp index 030162ab59..1d7358fa02 100644 --- a/apps/benchmarks/detournavigator/navmeshtilescache.cpp +++ b/apps/benchmarks/detournavigator/navmeshtilescache.cpp @@ -83,7 +83,7 @@ namespace std::uniform_real_distribution distribution(0.0, 1.0); std::generate_n(out, count, [&] { const btVector3 shift(distribution(random), distribution(random), distribution(random)); - return RecastMesh::Water {1, btTransform(btMatrix3x3::getIdentity(), shift)}; + return Water {1, btTransform(btMatrix3x3::getIdentity(), shift)}; }); } @@ -108,7 +108,7 @@ namespace const std::size_t generation = std::uniform_int_distribution(0, 100)(random); const std::size_t revision = std::uniform_int_distribution(0, 10000)(random); Mesh mesh = generateMesh(triangles, random); - std::vector water; + std::vector water; generateWater(std::back_inserter(water), 2, random); RecastMesh recastMesh(generation, revision, std::move(mesh), std::move(water)); return Key {agentHalfExtents, tilePosition, std::move(recastMesh)}; diff --git a/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp b/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp index fa607db371..137da9cd88 100644 --- a/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp +++ b/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp @@ -143,12 +143,12 @@ namespace const std::size_t mGeneration = 0; const std::size_t mRevision = 0; const Mesh mMesh {makeMesh()}; - const std::vector mWater {}; + const std::vector mWater {}; const RecastMesh mRecastMesh {mGeneration, mRevision, mMesh, mWater}; std::unique_ptr mPreparedNavMeshData {makePeparedNavMeshData(3)}; const std::size_t mRecastMeshSize = sizeof(mRecastMesh) + getSize(mRecastMesh); - const std::size_t mRecastMeshWithWaterSize = mRecastMeshSize + sizeof(RecastMesh::Water); + const std::size_t mRecastMeshWithWaterSize = mRecastMeshSize + sizeof(Water); const std::size_t mPreparedNavMeshDataSize = sizeof(*mPreparedNavMeshData) + getSize(*mPreparedNavMeshData); }; @@ -231,7 +231,7 @@ namespace { const std::size_t maxSize = 1; NavMeshTilesCache cache(maxSize); - const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, btTransform::getIdentity()}}; const RecastMesh unexistentRecastMesh {mGeneration, mRevision, mMesh, water}; cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData)); @@ -243,7 +243,7 @@ namespace const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; NavMeshTilesCache cache(maxSize); - const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, btTransform::getIdentity()}}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; auto anotherPreparedNavMeshData = makePeparedNavMeshData(3); const auto copy = clone(*anotherPreparedNavMeshData); @@ -261,7 +261,7 @@ namespace const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; NavMeshTilesCache cache(maxSize); - const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, btTransform::getIdentity()}}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; auto anotherPreparedNavMeshData = makePeparedNavMeshData(3); @@ -277,11 +277,11 @@ namespace NavMeshTilesCache cache(maxSize); const auto copy = clone(*mPreparedNavMeshData); - const std::vector leastRecentlySetWater {1, RecastMesh::Water {1, btTransform::getIdentity()}}; + const std::vector leastRecentlySetWater {1, Water {1, btTransform::getIdentity()}}; const RecastMesh leastRecentlySetRecastMesh {mGeneration, mRevision, mMesh, leastRecentlySetWater}; auto leastRecentlySetData = makePeparedNavMeshData(3); - const std::vector mostRecentlySetWater {1, RecastMesh::Water {2, btTransform::getIdentity()}}; + const std::vector mostRecentlySetWater {1, Water {2, btTransform::getIdentity()}}; const RecastMesh mostRecentlySetRecastMesh {mGeneration, mRevision, mMesh, mostRecentlySetWater}; auto mostRecentlySetData = makePeparedNavMeshData(3); @@ -303,12 +303,12 @@ namespace const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize); NavMeshTilesCache cache(maxSize); - const std::vector leastRecentlyUsedWater {1, RecastMesh::Water {1, btTransform::getIdentity()}}; + const std::vector leastRecentlyUsedWater {1, Water {1, btTransform::getIdentity()}}; const RecastMesh leastRecentlyUsedRecastMesh {mGeneration, mRevision, mMesh, leastRecentlyUsedWater}; auto leastRecentlyUsedData = makePeparedNavMeshData(3); const auto leastRecentlyUsedCopy = clone(*leastRecentlyUsedData); - const std::vector mostRecentlyUsedWater {1, RecastMesh::Water {2, btTransform::getIdentity()}}; + const std::vector mostRecentlyUsedWater {1, Water {2, btTransform::getIdentity()}}; const RecastMesh mostRecentlyUsedRecastMesh {mGeneration, mRevision, mMesh, mostRecentlyUsedWater}; auto mostRecentlyUsedData = makePeparedNavMeshData(3); const auto mostRecentlyUsedCopy = clone(*mostRecentlyUsedData); @@ -342,7 +342,7 @@ namespace const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize); NavMeshTilesCache cache(maxSize); - const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, btTransform::getIdentity()}}; const RecastMesh tooLargeRecastMesh {mGeneration, mRevision, mMesh, water}; auto tooLargeData = makePeparedNavMeshData(10); @@ -356,11 +356,11 @@ namespace const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize); NavMeshTilesCache cache(maxSize); - const std::vector anotherWater {1, RecastMesh::Water {1, btTransform::getIdentity()}}; + const std::vector anotherWater {1, Water {1, btTransform::getIdentity()}}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, anotherWater}; auto anotherData = makePeparedNavMeshData(3); - const std::vector tooLargeWater {1, RecastMesh::Water {2, btTransform::getIdentity()}}; + const std::vector tooLargeWater {1, Water {2, btTransform::getIdentity()}}; const RecastMesh tooLargeRecastMesh {mGeneration, mRevision, mMesh, tooLargeWater}; auto tooLargeData = makePeparedNavMeshData(10); @@ -380,7 +380,7 @@ namespace const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; NavMeshTilesCache cache(maxSize); - const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, btTransform::getIdentity()}}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; auto anotherData = makePeparedNavMeshData(3); @@ -399,7 +399,7 @@ namespace const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; NavMeshTilesCache cache(maxSize); - const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, btTransform::getIdentity()}}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; auto anotherData = makePeparedNavMeshData(3); diff --git a/apps/openmw_test_suite/detournavigator/recastmeshbuilder.cpp b/apps/openmw_test_suite/detournavigator/recastmeshbuilder.cpp index 0528205b58..56f94701f0 100644 --- a/apps/openmw_test_suite/detournavigator/recastmeshbuilder.cpp +++ b/apps/openmw_test_suite/detournavigator/recastmeshbuilder.cpp @@ -19,7 +19,7 @@ namespace DetourNavigator { - static inline bool operator ==(const RecastMesh::Water& lhs, const RecastMesh::Water& rhs) + static inline bool operator ==(const Water& lhs, const Water& rhs) { return lhs.mCellSize == rhs.mCellSize && lhs.mTransform == rhs.mTransform; } @@ -404,8 +404,8 @@ namespace RecastMeshBuilder builder(mBounds); builder.addWater(1000, btTransform(btMatrix3x3::getIdentity(), btVector3(100, 200, 300))); const auto recastMesh = std::move(builder).create(mGeneration, mRevision); - EXPECT_EQ(recastMesh->getWater(), std::vector({ - RecastMesh::Water {1000, btTransform(btMatrix3x3::getIdentity(), btVector3(100, 200, 300))} + EXPECT_EQ(recastMesh->getWater(), std::vector({ + Water {1000, btTransform(btMatrix3x3::getIdentity(), btVector3(100, 200, 300))} })); } diff --git a/components/detournavigator/makenavmesh.cpp b/components/detournavigator/makenavmesh.cpp index 0824e9cb86..1e2d4d5167 100644 --- a/components/detournavigator/makenavmesh.cpp +++ b/components/detournavigator/makenavmesh.cpp @@ -34,7 +34,7 @@ namespace osg::Vec3f mMax; }; - WaterBounds getWaterBounds(const RecastMesh::Water& water, const Settings& settings, + WaterBounds getWaterBounds(const Water& water, const Settings& settings, const osg::Vec3f& agentHalfExtents) { if (water.mCellSize == std::numeric_limits::max()) diff --git a/components/detournavigator/navmeshtilescache.hpp b/components/detournavigator/navmeshtilescache.hpp index b6b9391e66..974420c158 100644 --- a/components/detournavigator/navmeshtilescache.hpp +++ b/components/detournavigator/navmeshtilescache.hpp @@ -23,7 +23,7 @@ namespace DetourNavigator struct RecastMeshData { Mesh mMesh; - std::vector mWater; + std::vector mWater; }; inline bool operator <(const RecastMeshData& lhs, const RecastMeshData& rhs) diff --git a/components/detournavigator/recastmesh.hpp b/components/detournavigator/recastmesh.hpp index 9989bab061..c70405c85c 100644 --- a/components/detournavigator/recastmesh.hpp +++ b/components/detournavigator/recastmesh.hpp @@ -45,15 +45,15 @@ namespace DetourNavigator } }; + struct Water + { + int mCellSize; + btTransform mTransform; + }; + class RecastMesh { public: - struct Water - { - int mCellSize; - btTransform mTransform; - }; - RecastMesh(std::size_t generation, std::size_t revision, Mesh mesh, std::vector water); std::size_t getGeneration() const @@ -92,11 +92,11 @@ namespace DetourNavigator friend inline std::size_t getSize(const RecastMesh& value) noexcept { - return getSize(value.mMesh) + value.mWater.size() * sizeof(RecastMesh::Water); + return getSize(value.mMesh) + value.mWater.size() * sizeof(Water); } }; - inline bool operator<(const RecastMesh::Water& lhs, const RecastMesh::Water& rhs) noexcept + inline bool operator<(const Water& lhs, const Water& rhs) noexcept { return std::tie(lhs.mCellSize, lhs.mTransform) < std::tie(rhs.mCellSize, rhs.mTransform); } diff --git a/components/detournavigator/recastmeshbuilder.cpp b/components/detournavigator/recastmeshbuilder.cpp index 81fb6f21cf..ad896c2a57 100644 --- a/components/detournavigator/recastmeshbuilder.cpp +++ b/components/detournavigator/recastmeshbuilder.cpp @@ -160,7 +160,7 @@ namespace DetourNavigator void RecastMeshBuilder::addWater(const int cellSize, const btTransform& transform) { - mWater.push_back(RecastMesh::Water {cellSize, transform}); + mWater.push_back(Water {cellSize, transform}); } std::shared_ptr RecastMeshBuilder::create(std::size_t generation, std::size_t revision) && diff --git a/components/detournavigator/recastmeshbuilder.hpp b/components/detournavigator/recastmeshbuilder.hpp index 66d9128bdd..2692e8f486 100644 --- a/components/detournavigator/recastmeshbuilder.hpp +++ b/components/detournavigator/recastmeshbuilder.hpp @@ -56,7 +56,7 @@ namespace DetourNavigator private: const TileBounds mBounds; std::vector mTriangles; - std::vector mWater; + std::vector mWater; void addObject(const btConcaveShape& shape, const btTransform& transform, btTriangleCallback&& callback);