From 9854d42d56e92d550ac07cf5a157fbeafc52db72 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 19 May 2024 14:26:28 +0200 Subject: [PATCH] Use ESM::RefId for worldspace type --- apps/navmeshtool/navmesh.cpp | 14 +-- apps/navmeshtool/worldspacedata.cpp | 9 +- apps/navmeshtool/worldspacedata.hpp | 4 +- apps/openmw/mwworld/scene.cpp | 10 +- .../detournavigator/asyncnavmeshupdater.cpp | 21 ++-- .../detournavigator/navmeshdb.cpp | 17 ++- .../tilecachedrecastmeshmanager.cpp | 117 +++++++++--------- .../detournavigator/asyncnavmeshupdater.cpp | 5 +- .../detournavigator/asyncnavmeshupdater.hpp | 6 +- .../detournavigator/generatenavmeshtile.cpp | 6 +- .../detournavigator/generatenavmeshtile.hpp | 14 +-- components/detournavigator/makenavmesh.cpp | 5 +- components/detournavigator/makenavmesh.hpp | 7 +- components/detournavigator/navigator.hpp | 2 +- components/detournavigator/navigatorimpl.cpp | 2 +- components/detournavigator/navigatorimpl.hpp | 3 +- components/detournavigator/navigatorstub.hpp | 2 +- components/detournavigator/navmeshdb.cpp | 26 ++-- components/detournavigator/navmeshdb.hpp | 23 ++-- components/detournavigator/navmeshmanager.cpp | 2 +- components/detournavigator/navmeshmanager.hpp | 4 +- components/detournavigator/recastcontext.cpp | 4 +- components/detournavigator/recastcontext.hpp | 5 +- .../detournavigator/recastmeshprovider.hpp | 2 +- .../tilecachedrecastmeshmanager.cpp | 8 +- .../tilecachedrecastmeshmanager.hpp | 12 +- 26 files changed, 161 insertions(+), 169 deletions(-) diff --git a/apps/navmeshtool/navmesh.cpp b/apps/navmeshtool/navmesh.cpp index 384c965466..fe03376557 100644 --- a/apps/navmeshtool/navmesh.cpp +++ b/apps/navmeshtool/navmesh.cpp @@ -106,8 +106,8 @@ namespace NavMeshTool return DetourNavigator::resolveMeshSource(mDb, source, mNextShapeId); } - std::optional find(std::string_view worldspace, const TilePosition& tilePosition, - const std::vector& input) override + std::optional find( + ESM::RefId worldspace, const TilePosition& tilePosition, const std::vector& input) override { std::optional result; std::lock_guard lock(mMutex); @@ -121,7 +121,7 @@ namespace NavMeshTool return result; } - void ignore(std::string_view worldspace, const TilePosition& tilePosition) override + void ignore(ESM::RefId worldspace, const TilePosition& tilePosition) override { if (mRemoveUnusedTiles) { @@ -131,7 +131,7 @@ namespace NavMeshTool report(); } - void identity(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t tileId) override + void identity(ESM::RefId worldspace, const TilePosition& tilePosition, std::int64_t tileId) override { if (mRemoveUnusedTiles) { @@ -142,7 +142,7 @@ namespace NavMeshTool report(); } - void insert(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t version, + void insert(ESM::RefId worldspace, const TilePosition& tilePosition, std::int64_t version, const std::vector& input, PreparedNavMeshData& data) override { { @@ -158,7 +158,7 @@ namespace NavMeshTool report(); } - void update(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t tileId, + void update(ESM::RefId worldspace, const TilePosition& tilePosition, std::int64_t tileId, std::int64_t version, PreparedNavMeshData& data) override { data.mUserId = static_cast(tileId); @@ -217,7 +217,7 @@ namespace NavMeshTool mDb.vacuum(); } - void removeTilesOutsideRange(std::string_view worldspace, const TilesPositionsRange& range) + void removeTilesOutsideRange(ESM::RefId worldspace, const TilesPositionsRange& range) { const std::lock_guard lock(mMutex); mTransaction.commit(); diff --git a/apps/navmeshtool/worldspacedata.cpp b/apps/navmeshtool/worldspacedata.cpp index 0b3a1202d0..5c8468d7c6 100644 --- a/apps/navmeshtool/worldspacedata.cpp +++ b/apps/navmeshtool/worldspacedata.cpp @@ -234,8 +234,8 @@ namespace NavMeshTool } WorldspaceNavMeshInput::WorldspaceNavMeshInput( - std::string worldspace, const DetourNavigator::RecastSettings& settings) - : mWorldspace(std::move(worldspace)) + ESM::RefId worldspace, const DetourNavigator::RecastSettings& settings) + : mWorldspace(worldspace) , mTileCachedRecastMeshManager(settings) { mAabb.m_min = btVector3(0, 0, 0); @@ -248,7 +248,7 @@ namespace NavMeshTool { Log(Debug::Info) << "Processing " << esmData.mCells.size() << " cells..."; - std::map> navMeshInputs; + std::unordered_map> navMeshInputs; WorldspaceData data; std::size_t objectsCounter = 0; @@ -276,8 +276,7 @@ namespace NavMeshTool const osg::Vec2i cellPosition(cell.mData.mX, cell.mData.mY); const std::size_t cellObjectsBegin = data.mObjects.size(); - const auto cellWorldspace = Misc::StringUtils::lowerCase( - (cell.isExterior() ? ESM::Cell::sDefaultWorldspaceId : cell.mId).serializeText()); + const ESM::RefId cellWorldspace = cell.isExterior() ? ESM::Cell::sDefaultWorldspaceId : cell.mId; WorldspaceNavMeshInput& navMeshInput = [&]() -> WorldspaceNavMeshInput& { auto it = navMeshInputs.find(cellWorldspace); if (it == navMeshInputs.end()) diff --git a/apps/navmeshtool/worldspacedata.hpp b/apps/navmeshtool/worldspacedata.hpp index b6ccce6733..7096cf95ed 100644 --- a/apps/navmeshtool/worldspacedata.hpp +++ b/apps/navmeshtool/worldspacedata.hpp @@ -48,12 +48,12 @@ namespace NavMeshTool struct WorldspaceNavMeshInput { - std::string mWorldspace; + ESM::RefId mWorldspace; TileCachedRecastMeshManager mTileCachedRecastMeshManager; btAABB mAabb; bool mAabbInitialized = false; - explicit WorldspaceNavMeshInput(std::string worldspace, const DetourNavigator::RecastSettings& settings); + explicit WorldspaceNavMeshInput(ESM::RefId worldspace, const DetourNavigator::RecastSettings& settings); }; class BulletObject diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 169e4bfd21..e3b9419035 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -591,9 +591,7 @@ namespace MWWorld else unloadCell(cell, navigatorUpdateGuard.get()); } - mNavigator.setWorldspace( - mWorld.getWorldModel().getExterior(playerCellIndex).getCell()->getWorldSpace().serializeText(), - navigatorUpdateGuard.get()); + mNavigator.setWorldspace(playerCellIndex.mWorldspace, navigatorUpdateGuard.get()); mNavigator.updateBounds(pos, navigatorUpdateGuard.get()); mCurrentGridCenter = osg::Vec2i(playerCellX, playerCellY); @@ -696,7 +694,7 @@ namespace MWWorld CellStore& cell = mWorld.getWorldModel().getExterior( ESM::ExteriorCellLocation(it->mData.mX, it->mData.mY, ESM::Cell::sDefaultWorldspaceId)); - mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get()); + mNavigator.setWorldspace(cell.getCell()->getWorldSpace(), navigatorUpdateGuard.get()); const osg::Vec3f position = osg::Vec3f(it->mData.mX + 0.5f, it->mData.mY + 0.5f, 0) * Constants::CellSizeInUnits; mNavigator.updateBounds(position, navigatorUpdateGuard.get()); @@ -753,7 +751,7 @@ namespace MWWorld + std::to_string(cells.getIntSize()) + ")..."); CellStore& cell = mWorld.getWorldModel().getInterior(it->mName); - mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get()); + mNavigator.setWorldspace(cell.getCell()->getWorldSpace(), navigatorUpdateGuard.get()); ESM::Position position; mWorld.findInteriorPosition(it->mName, position); mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get()); @@ -906,7 +904,7 @@ namespace MWWorld loadingListener->setProgressRange(cell.count()); - mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get()); + mNavigator.setWorldspace(cell.getCell()->getWorldSpace(), navigatorUpdateGuard.get()); mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get()); // Load cell. diff --git a/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp b/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp index 51ab37b123..4eb56d63e0 100644 --- a/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp +++ b/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp @@ -52,7 +52,7 @@ namespace OffMeshConnectionsManager mOffMeshConnectionsManager{ mSettings.mRecast }; const AgentBounds mAgentBounds{ CollisionShapeType::Aabb, { 29, 29, 66 } }; const TilePosition mPlayerTile{ 0, 0 }; - const std::string mWorldspace = "sys::default"; + const ESM::RefId mWorldspace = ESM::RefId::stringRefId("sys::default"); const btBoxShape mBox{ btVector3(100, 100, 20) }; Loading::Listener mListener; }; @@ -310,7 +310,7 @@ namespace AsyncNavMeshUpdater updater(mSettings, mRecastMeshManager, mOffMeshConnectionsManager, std::move(db)); const TileId nextTileId(dbPtr->getMaxTileId() + 1); - ASSERT_EQ(dbPtr->insertTile(nextTileId, "worldspace", TilePosition{}, TileVersion{ 1 }, {}, {}), 1); + ASSERT_EQ(dbPtr->insertTile(nextTileId, mWorldspace, TilePosition{}, TileVersion{ 1 }, {}, {}), 1); const auto navMeshCacheItem = std::make_shared(1, mSettings); const TilePosition tilePosition{ 0, 0 }; @@ -385,7 +385,7 @@ namespace const AgentBounds mAgentBounds{ CollisionShapeType::Aabb, osg::Vec3f(1, 1, 1) }; const std::shared_ptr mNavMeshCacheItemPtr; const std::weak_ptr mNavMeshCacheItem = mNavMeshCacheItemPtr; - const std::string_view mWorldspace = "worldspace"; + const ESM::RefId mWorldspace = ESM::RefId::stringRefId("worldspace"); const TilePosition mChangedTile{ 0, 0 }; const std::chrono::steady_clock::time_point mProcessTime{}; const TilePosition mPlayerTile{ 0, 0 }; @@ -397,20 +397,23 @@ namespace std::list jobs; SpatialJobQueue queue; - queue.push(jobs.emplace(jobs.end(), mAgentBounds, mNavMeshCacheItem, "worldspace1", mChangedTile, - ChangeType::remove, mProcessTime)); - queue.push(jobs.emplace(jobs.end(), mAgentBounds, mNavMeshCacheItem, "worldspace2", mChangedTile, - ChangeType::update, mProcessTime)); + const ESM::RefId worldspace1 = ESM::RefId::stringRefId("worldspace1"); + const ESM::RefId worldspace2 = ESM::RefId::stringRefId("worldspace2"); + + queue.push(jobs.emplace( + jobs.end(), mAgentBounds, mNavMeshCacheItem, worldspace1, mChangedTile, ChangeType::remove, mProcessTime)); + queue.push(jobs.emplace( + jobs.end(), mAgentBounds, mNavMeshCacheItem, worldspace2, mChangedTile, ChangeType::update, mProcessTime)); ASSERT_EQ(queue.size(), 2); const auto job1 = queue.pop(mChangedTile); ASSERT_TRUE(job1.has_value()); - EXPECT_EQ((*job1)->mWorldspace, "worldspace1"); + EXPECT_EQ((*job1)->mWorldspace, worldspace1); const auto job2 = queue.pop(mChangedTile); ASSERT_TRUE(job2.has_value()); - EXPECT_EQ((*job2)->mWorldspace, "worldspace2"); + EXPECT_EQ((*job2)->mWorldspace, worldspace2); EXPECT_EQ(queue.size(), 0); } diff --git a/apps/openmw_test_suite/detournavigator/navmeshdb.cpp b/apps/openmw_test_suite/detournavigator/navmeshdb.cpp index 4cf88f5711..cd74983b0e 100644 --- a/apps/openmw_test_suite/detournavigator/navmeshdb.cpp +++ b/apps/openmw_test_suite/detournavigator/navmeshdb.cpp @@ -8,7 +8,6 @@ #include #include -#include #include namespace @@ -19,7 +18,7 @@ namespace struct Tile { - std::string mWorldspace; + ESM::RefId mWorldspace; TilePosition mTilePosition; std::vector mInput; std::vector mData; @@ -39,12 +38,12 @@ namespace Tile insertTile(TileId tileId, TileVersion version) { - std::string worldspace = "sys::default"; + const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const TilePosition tilePosition{ 3, 4 }; std::vector input = generateData(); std::vector data = generateData(); EXPECT_EQ(mDb.insertTile(tileId, worldspace, tilePosition, version, input, data), 1); - return { std::move(worldspace), tilePosition, std::move(input), std::move(data) }; + return { worldspace, tilePosition, std::move(input), std::move(data) }; } }; @@ -89,7 +88,7 @@ namespace { const TileId tileId{ 53 }; const TileVersion version{ 1 }; - const std::string worldspace = "sys::default"; + const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const TilePosition tilePosition{ 3, 4 }; const std::vector input = generateData(); const std::vector data = generateData(); @@ -101,7 +100,7 @@ namespace { const TileId tileId{ 53 }; const TileVersion version{ 1 }; - const std::string worldspace = "sys::default"; + const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const TilePosition tilePosition{ 3, 4 }; const std::vector input = generateData(); const std::vector data = generateData(); @@ -113,7 +112,7 @@ namespace TEST_F(DetourNavigatorNavMeshDbTest, delete_tiles_at_should_remove_all_tiles_with_given_worldspace_and_position) { const TileVersion version{ 1 }; - const std::string worldspace = "sys::default"; + const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const TilePosition tilePosition{ 3, 4 }; const std::vector input1 = generateData(); const std::vector input2 = generateData(); @@ -130,7 +129,7 @@ namespace const TileId leftTileId{ 53 }; const TileId removedTileId{ 54 }; const TileVersion version{ 1 }; - const std::string worldspace = "sys::default"; + const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const TilePosition tilePosition{ 3, 4 }; const std::vector leftInput = generateData(); const std::vector removedInput = generateData(); @@ -148,7 +147,7 @@ namespace { TileId tileId{ 1 }; const TileVersion version{ 1 }; - const std::string worldspace = "sys::default"; + const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const std::vector input = generateData(); const std::vector data = generateData(); for (int x = -2; x <= 2; ++x) diff --git a/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp b/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp index 904b6a02f0..7585e405e5 100644 --- a/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp @@ -21,6 +21,7 @@ namespace const ObjectTransform mObjectTransform{ ESM::Position{ { 0, 0, 0 }, { 0, 0, 0 } }, 0.0f }; const osg::ref_ptr mShape = new Resource::BulletShape; const osg::ref_ptr mInstance = new Resource::BulletShapeInstance(mShape); + const ESM::RefId mWorldspace = ESM::RefId::stringRefId("worldspace"); DetourNavigatorTileCachedRecastMeshManagerTest() { @@ -34,7 +35,7 @@ namespace TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_empty_should_return_nullptr) { TileCachedRecastMeshManager manager(mSettings); - EXPECT_EQ(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr); + EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_revision_for_empty_should_return_zero) @@ -65,14 +66,14 @@ namespace TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_add_tiles) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const CollisionShape shape(mInstance, boxShape, mObjectTransform); ASSERT_TRUE(manager.addObject( ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr)); for (int x = -1; x < 1; ++x) for (int y = -1; y < 1; ++y) - ASSERT_NE(manager.getMesh("worldspace", TilePosition(x, y)), nullptr); + ASSERT_NE(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_return_add_changed_tiles) @@ -145,25 +146,25 @@ namespace get_mesh_after_add_object_should_return_recast_mesh_for_each_used_tile) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const CollisionShape shape(mInstance, boxShape, mObjectTransform); manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); } TEST_F( DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_after_add_object_should_return_nullptr_for_unused_tile) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const CollisionShape shape(mInstance, boxShape, mObjectTransform); manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); - EXPECT_EQ(manager.getMesh("worldspace", TilePosition(1, 0)), nullptr); + EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(1, 0)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, @@ -175,7 +176,7 @@ namespace .mEnd = TilePosition(1, 1), }; manager.setRange(range, nullptr); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const btTransform transform( @@ -183,23 +184,23 @@ namespace const CollisionShape shape(mInstance, boxShape, mObjectTransform); manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(1, 0)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(1, -1)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(1, 0)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(1, -1)), nullptr); manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); } TEST_F( DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_moved_object_should_return_nullptr_for_unused_tile) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const btTransform transform( @@ -207,48 +208,48 @@ namespace const CollisionShape shape(mInstance, boxShape, mObjectTransform); manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, nullptr); - EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr); - EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr); + EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); + EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); - EXPECT_EQ(manager.getMesh("worldspace", TilePosition(1, 0)), nullptr); - EXPECT_EQ(manager.getMesh("worldspace", TilePosition(1, -1)), nullptr); + EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(1, 0)), nullptr); + EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(1, -1)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_removed_object_should_return_nullptr_for_all_previously_used_tiles) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const CollisionShape shape(mInstance, boxShape, mObjectTransform); manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); manager.removeObject(ObjectId(&boxShape), nullptr); - EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr); - EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr); - EXPECT_EQ(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr); - EXPECT_EQ(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr); + EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); + EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); + EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); + EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_not_changed_object_after_update_should_return_recast_mesh_for_same_tiles) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const CollisionShape shape(mInstance, boxShape, mObjectTransform); manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr); - EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); + EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, @@ -293,7 +294,7 @@ namespace get_revision_after_update_not_changed_object_should_return_same_value) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const CollisionShape shape(mInstance, boxShape, mObjectTransform); manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); @@ -339,19 +340,19 @@ namespace TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_not_max_int_should_add_new_tiles) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const osg::Vec2i cellPosition(0, 0); const int cellSize = 8192; manager.addWater(cellPosition, cellSize, 0.0f, nullptr); for (int x = -1; x < 12; ++x) for (int y = -1; y < 12; ++y) - ASSERT_NE(manager.getMesh("worldspace", TilePosition(x, y)), nullptr); + ASSERT_NE(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_max_int_should_not_add_new_tiles) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const CollisionShape shape(mInstance, boxShape, mObjectTransform); ASSERT_TRUE(manager.addObject( @@ -361,7 +362,7 @@ namespace manager.addWater(cellPosition, cellSize, 0.0f, nullptr); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) - ASSERT_EQ(manager.getMesh("worldspace", TilePosition(x, y)) != nullptr, + ASSERT_EQ(manager.getMesh(mWorldspace, TilePosition(x, y)) != nullptr, -1 <= x && x <= 0 && -1 <= y && y <= 0); } @@ -390,20 +391,20 @@ namespace TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_remove_empty_tiles) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const osg::Vec2i cellPosition(0, 0); const int cellSize = 8192; manager.addWater(cellPosition, cellSize, 0.0f, nullptr); manager.removeWater(cellPosition, nullptr); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) - ASSERT_EQ(manager.getMesh("worldspace", TilePosition(x, y)), nullptr); + ASSERT_EQ(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_leave_not_empty_tiles) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const CollisionShape shape(mInstance, boxShape, mObjectTransform); ASSERT_TRUE(manager.addObject( @@ -414,14 +415,14 @@ namespace manager.removeWater(cellPosition, nullptr); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) - ASSERT_EQ(manager.getMesh("worldspace", TilePosition(x, y)) != nullptr, + ASSERT_EQ(manager.getMesh(mWorldspace, TilePosition(x, y)) != nullptr, -1 <= x && x <= 0 && -1 <= y && y <= 0); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_object_should_not_remove_tile_with_water) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const osg::Vec2i cellPosition(0, 0); const int cellSize = 8192; const btBoxShape boxShape(btVector3(20, 20, 100)); @@ -432,21 +433,22 @@ namespace manager.removeObject(ObjectId(&boxShape), nullptr); for (int x = -1; x < 12; ++x) for (int y = -1; y < 12; ++y) - ASSERT_NE(manager.getMesh("worldspace", TilePosition(x, y)), nullptr); + ASSERT_NE(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_new_worldspace_should_remove_tiles) { TileCachedRecastMeshManager manager(mSettings); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const CollisionShape shape(nullptr, boxShape, mObjectTransform); ASSERT_TRUE(manager.addObject( ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr)); - manager.setWorldspace("other", nullptr); + const ESM::RefId otherWorldspace(ESM::FormId::fromUint32(0x1)); + manager.setWorldspace(ESM::FormId::fromUint32(0x1), nullptr); for (int x = -1; x < 1; ++x) for (int y = -1; y < 1; ++y) - ASSERT_EQ(manager.getMesh("other", TilePosition(x, y)), nullptr); + ASSERT_EQ(manager.getMesh(otherWorldspace, TilePosition(x, y)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_range_should_add_changed_tiles) @@ -475,8 +477,7 @@ namespace { TileCachedRecastMeshManager manager(mSettings); - const std::string_view worldspace = "worldspace"; - manager.setWorldspace(worldspace, nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(100, 100, 20)); const CollisionShape shape(mInstance, boxShape, mObjectTransform); @@ -489,9 +490,9 @@ namespace const TilePosition tilePosition(0, 0); - ASSERT_EQ(manager.getCachedMesh(worldspace, tilePosition), nullptr); - ASSERT_NE(manager.getMesh(worldspace, tilePosition), nullptr); - ASSERT_NE(manager.getCachedMesh(worldspace, tilePosition), nullptr); + ASSERT_EQ(manager.getCachedMesh(mWorldspace, tilePosition), nullptr); + ASSERT_NE(manager.getMesh(mWorldspace, tilePosition), nullptr); + ASSERT_NE(manager.getCachedMesh(mWorldspace, tilePosition), nullptr); const TilesPositionsRange range2{ .mBegin = TilePosition(-1, -1), @@ -500,6 +501,6 @@ namespace manager.takeChangedTiles(nullptr); manager.setRange(range2, nullptr); - ASSERT_EQ(manager.getCachedMesh(worldspace, tilePosition), nullptr); + ASSERT_EQ(manager.getCachedMesh(mWorldspace, tilePosition), nullptr); } } diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index fe6d0625f5..24d7cc0d32 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -91,7 +91,7 @@ namespace DetourNavigator } Job::Job(const AgentBounds& agentBounds, std::weak_ptr navMeshCacheItem, - std::string_view worldspace, const TilePosition& changedTile, ChangeType changeType, + ESM::RefId worldspace, const TilePosition& changedTile, ChangeType changeType, std::chrono::steady_clock::time_point processTime) : mId(getNextJobId()) , mAgentBounds(agentBounds) @@ -261,8 +261,7 @@ namespace DetourNavigator } void AsyncNavMeshUpdater::post(const AgentBounds& agentBounds, const SharedNavMeshCacheItem& navMeshCacheItem, - const TilePosition& playerTile, std::string_view worldspace, - const std::map& changedTiles) + const TilePosition& playerTile, ESM::RefId worldspace, const std::map& changedTiles) { bool playerTileChanged = false; { diff --git a/components/detournavigator/asyncnavmeshupdater.hpp b/components/detournavigator/asyncnavmeshupdater.hpp index f3d624a8a6..a4c446afc9 100644 --- a/components/detournavigator/asyncnavmeshupdater.hpp +++ b/components/detournavigator/asyncnavmeshupdater.hpp @@ -50,7 +50,7 @@ namespace DetourNavigator const std::size_t mId; const AgentBounds mAgentBounds; const std::weak_ptr mNavMeshCacheItem; - const std::string mWorldspace; + const ESM::RefId mWorldspace; const TilePosition mChangedTile; std::chrono::steady_clock::time_point mProcessTime; ChangeType mChangeType; @@ -61,7 +61,7 @@ namespace DetourNavigator std::unique_ptr mGeneratedNavMeshData; Job(const AgentBounds& agentBounds, std::weak_ptr navMeshCacheItem, - std::string_view worldspace, const TilePosition& changedTile, ChangeType changeType, + ESM::RefId worldspace, const TilePosition& changedTile, ChangeType changeType, std::chrono::steady_clock::time_point processTime); }; @@ -199,7 +199,7 @@ namespace DetourNavigator ~AsyncNavMeshUpdater(); void post(const AgentBounds& agentBounds, const SharedNavMeshCacheItem& navMeshCacheItem, - const TilePosition& playerTile, std::string_view worldspace, + const TilePosition& playerTile, ESM::RefId worldspace, const std::map& changedTiles); void wait(WaitConditionType waitConditionType, Loading::Listener* listener); diff --git a/components/detournavigator/generatenavmeshtile.cpp b/components/detournavigator/generatenavmeshtile.cpp index a96a554302..118114181e 100644 --- a/components/detournavigator/generatenavmeshtile.cpp +++ b/components/detournavigator/generatenavmeshtile.cpp @@ -22,7 +22,7 @@ namespace DetourNavigator { struct Ignore { - std::string_view mWorldspace; + ESM::RefId mWorldspace; const TilePosition& mTilePosition; std::shared_ptr mConsumer; @@ -34,10 +34,10 @@ namespace DetourNavigator }; } - GenerateNavMeshTile::GenerateNavMeshTile(std::string worldspace, const TilePosition& tilePosition, + GenerateNavMeshTile::GenerateNavMeshTile(ESM::RefId worldspace, const TilePosition& tilePosition, RecastMeshProvider recastMeshProvider, const AgentBounds& agentBounds, const DetourNavigator::Settings& settings, std::weak_ptr consumer) - : mWorldspace(std::move(worldspace)) + : mWorldspace(worldspace) , mTilePosition(tilePosition) , mRecastMeshProvider(recastMeshProvider) , mAgentBounds(agentBounds) diff --git a/components/detournavigator/generatenavmeshtile.hpp b/components/detournavigator/generatenavmeshtile.hpp index c132ef6160..76ef55ce56 100644 --- a/components/detournavigator/generatenavmeshtile.hpp +++ b/components/detournavigator/generatenavmeshtile.hpp @@ -35,18 +35,18 @@ namespace DetourNavigator virtual std::int64_t resolveMeshSource(const MeshSource& source) = 0; virtual std::optional find( - std::string_view worldspace, const TilePosition& tilePosition, const std::vector& input) + ESM::RefId worldspace, const TilePosition& tilePosition, const std::vector& input) = 0; - virtual void ignore(std::string_view worldspace, const TilePosition& tilePosition) = 0; + virtual void ignore(ESM::RefId worldspace, const TilePosition& tilePosition) = 0; - virtual void identity(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t tileId) = 0; + virtual void identity(ESM::RefId worldspace, const TilePosition& tilePosition, std::int64_t tileId) = 0; - virtual void insert(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t version, + virtual void insert(ESM::RefId worldspace, const TilePosition& tilePosition, std::int64_t version, const std::vector& input, PreparedNavMeshData& data) = 0; - virtual void update(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t tileId, + virtual void update(ESM::RefId worldspace, const TilePosition& tilePosition, std::int64_t tileId, std::int64_t version, PreparedNavMeshData& data) = 0; @@ -56,14 +56,14 @@ namespace DetourNavigator class GenerateNavMeshTile final : public SceneUtil::WorkItem { public: - GenerateNavMeshTile(std::string worldspace, const TilePosition& tilePosition, + GenerateNavMeshTile(ESM::RefId worldspace, const TilePosition& tilePosition, RecastMeshProvider recastMeshProvider, const AgentBounds& agentBounds, const Settings& settings, std::weak_ptr consumer); void doWork() final; private: - const std::string mWorldspace; + const ESM::RefId mWorldspace; const TilePosition mTilePosition; const RecastMeshProvider mRecastMeshProvider; const AgentBounds mAgentBounds; diff --git a/components/detournavigator/makenavmesh.cpp b/components/detournavigator/makenavmesh.cpp index e143bf1837..f037da69f8 100644 --- a/components/detournavigator/makenavmesh.cpp +++ b/components/detournavigator/makenavmesh.cpp @@ -520,9 +520,8 @@ namespace DetourNavigator } } - std::unique_ptr prepareNavMeshTileData(const RecastMesh& recastMesh, - std::string_view worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds, - const RecastSettings& settings) + std::unique_ptr prepareNavMeshTileData(const RecastMesh& recastMesh, ESM::RefId worldspace, + const TilePosition& tilePosition, const AgentBounds& agentBounds, const RecastSettings& settings) { RecastContext context(worldspace, tilePosition, agentBounds); diff --git a/components/detournavigator/makenavmesh.hpp b/components/detournavigator/makenavmesh.hpp index 25bbca6d3c..d78f946230 100644 --- a/components/detournavigator/makenavmesh.hpp +++ b/components/detournavigator/makenavmesh.hpp @@ -4,6 +4,8 @@ #include "recastmesh.hpp" #include "tileposition.hpp" +#include + #include #include @@ -41,9 +43,8 @@ namespace DetourNavigator && recastMesh.getHeightfields().empty() && recastMesh.getFlatHeightfields().empty(); } - std::unique_ptr prepareNavMeshTileData(const RecastMesh& recastMesh, - std::string_view worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds, - const RecastSettings& settings); + std::unique_ptr prepareNavMeshTileData(const RecastMesh& recastMesh, ESM::RefId worldspace, + const TilePosition& tilePosition, const AgentBounds& agentBounds, const RecastSettings& settings); NavMeshData makeNavMeshTileData(const PreparedNavMeshData& data, const std::vector& offMeshConnections, const AgentBounds& agentBounds, diff --git a/components/detournavigator/navigator.hpp b/components/detournavigator/navigator.hpp index 378af081d0..7bab0af4d1 100644 --- a/components/detournavigator/navigator.hpp +++ b/components/detournavigator/navigator.hpp @@ -91,7 +91,7 @@ namespace DetourNavigator * @brief setWorldspace should be called before adding object from new worldspace * @param worldspace */ - virtual void setWorldspace(std::string_view worldspace, const UpdateGuard* guard) = 0; + virtual void setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard) = 0; /** * @brief updateBounds should be called before adding object from loading cell diff --git a/components/detournavigator/navigatorimpl.cpp b/components/detournavigator/navigatorimpl.cpp index 514a70b336..443a98a678 100644 --- a/components/detournavigator/navigatorimpl.cpp +++ b/components/detournavigator/navigatorimpl.cpp @@ -33,7 +33,7 @@ namespace DetourNavigator --it->second; } - void NavigatorImpl::setWorldspace(std::string_view worldspace, const UpdateGuard* guard) + void NavigatorImpl::setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard) { mNavMeshManager.setWorldspace(worldspace, guard); } diff --git a/components/detournavigator/navigatorimpl.hpp b/components/detournavigator/navigatorimpl.hpp index 1439a89f28..e9f7276172 100644 --- a/components/detournavigator/navigatorimpl.hpp +++ b/components/detournavigator/navigatorimpl.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include namespace DetourNavigator @@ -28,7 +27,7 @@ namespace DetourNavigator void removeAgent(const AgentBounds& agentBounds) override; - void setWorldspace(std::string_view worldspace, const UpdateGuard* guard) override; + void setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard) override; void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard) override; diff --git a/components/detournavigator/navigatorstub.hpp b/components/detournavigator/navigatorstub.hpp index 7b93811c15..bc14e2274c 100644 --- a/components/detournavigator/navigatorstub.hpp +++ b/components/detournavigator/navigatorstub.hpp @@ -24,7 +24,7 @@ namespace DetourNavigator void removeAgent(const AgentBounds& /*agentBounds*/) override {} - void setWorldspace(std::string_view /*worldspace*/, const UpdateGuard* /*guard*/) override {} + void setWorldspace(ESM::RefId /*worldspace*/, const UpdateGuard* /*guard*/) override {} void addObject(const ObjectId /*id*/, const ObjectShapes& /*shapes*/, const btTransform& /*transform*/, const UpdateGuard* /*guard*/) override diff --git a/components/detournavigator/navmeshdb.cpp b/components/detournavigator/navmeshdb.cpp index d5c6fdb46b..76f0811f16 100644 --- a/components/detournavigator/navmeshdb.cpp +++ b/components/detournavigator/navmeshdb.cpp @@ -200,34 +200,35 @@ namespace DetourNavigator } std::optional NavMeshDb::findTile( - std::string_view worldspace, const TilePosition& tilePosition, const std::vector& input) + ESM::RefId worldspace, const TilePosition& tilePosition, const std::vector& input) { Tile result; auto row = std::tie(result.mTileId, result.mVersion); const std::vector compressedInput = Misc::compress(input); - if (&row == request(*mDb, mFindTile, &row, 1, worldspace, tilePosition, compressedInput)) + if (&row == request(*mDb, mFindTile, &row, 1, worldspace.serializeText(), tilePosition, compressedInput)) return {}; return result; } std::optional NavMeshDb::getTileData( - std::string_view worldspace, const TilePosition& tilePosition, const std::vector& input) + ESM::RefId worldspace, const TilePosition& tilePosition, const std::vector& input) { TileData result; auto row = std::tie(result.mTileId, result.mVersion, result.mData); const std::vector compressedInput = Misc::compress(input); - if (&row == request(*mDb, mGetTileData, &row, 1, worldspace, tilePosition, compressedInput)) + if (&row == request(*mDb, mGetTileData, &row, 1, worldspace.serializeText(), tilePosition, compressedInput)) return {}; result.mData = Misc::decompress(result.mData); return result; } - int NavMeshDb::insertTile(TileId tileId, std::string_view worldspace, const TilePosition& tilePosition, + int NavMeshDb::insertTile(TileId tileId, ESM::RefId worldspace, const TilePosition& tilePosition, TileVersion version, const std::vector& input, const std::vector& data) { const std::vector compressedInput = Misc::compress(input); const std::vector compressedData = Misc::compress(data); - return execute(*mDb, mInsertTile, tileId, worldspace, tilePosition, version, compressedInput, compressedData); + return execute(*mDb, mInsertTile, tileId, worldspace.serializeText(), tilePosition, version, compressedInput, + compressedData); } int NavMeshDb::updateTile(TileId tileId, TileVersion version, const std::vector& data) @@ -236,20 +237,19 @@ namespace DetourNavigator return execute(*mDb, mUpdateTile, tileId, version, compressedData); } - int NavMeshDb::deleteTilesAt(std::string_view worldspace, const TilePosition& tilePosition) + int NavMeshDb::deleteTilesAt(ESM::RefId worldspace, const TilePosition& tilePosition) { - return execute(*mDb, mDeleteTilesAt, worldspace, tilePosition); + return execute(*mDb, mDeleteTilesAt, worldspace.serializeText(), tilePosition); } - int NavMeshDb::deleteTilesAtExcept( - std::string_view worldspace, const TilePosition& tilePosition, TileId excludeTileId) + int NavMeshDb::deleteTilesAtExcept(ESM::RefId worldspace, const TilePosition& tilePosition, TileId excludeTileId) { - return execute(*mDb, mDeleteTilesAtExcept, worldspace, tilePosition, excludeTileId); + return execute(*mDb, mDeleteTilesAtExcept, worldspace.serializeText(), tilePosition, excludeTileId); } - int NavMeshDb::deleteTilesOutsideRange(std::string_view worldspace, const TilesPositionsRange& range) + int NavMeshDb::deleteTilesOutsideRange(ESM::RefId worldspace, const TilesPositionsRange& range) { - return execute(*mDb, mDeleteTilesOutsideRange, worldspace, range); + return execute(*mDb, mDeleteTilesOutsideRange, worldspace.serializeText(), range); } ShapeId NavMeshDb::getMaxShapeId() diff --git a/components/detournavigator/navmeshdb.hpp b/components/detournavigator/navmeshdb.hpp index 3cf1bdcdca..9918dca9f5 100644 --- a/components/detournavigator/navmeshdb.hpp +++ b/components/detournavigator/navmeshdb.hpp @@ -2,10 +2,10 @@ #define OPENMW_COMPONENTS_DETOURNAVIGATOR_NAVMESHDB_H #include "tileposition.hpp" +#include "tilespositionsrange.hpp" -#include +#include #include - #include #include #include @@ -13,13 +13,8 @@ #include #include -#include -#include #include -#include #include -#include -#include #include struct sqlite3; @@ -148,21 +143,21 @@ namespace DetourNavigator TileId getMaxTileId(); std::optional findTile( - std::string_view worldspace, const TilePosition& tilePosition, const std::vector& input); + ESM::RefId worldspace, const TilePosition& tilePosition, const std::vector& input); std::optional getTileData( - std::string_view worldspace, const TilePosition& tilePosition, const std::vector& input); + ESM::RefId worldspace, const TilePosition& tilePosition, const std::vector& input); - int insertTile(TileId tileId, std::string_view worldspace, const TilePosition& tilePosition, - TileVersion version, const std::vector& input, const std::vector& data); + int insertTile(TileId tileId, ESM::RefId worldspace, const TilePosition& tilePosition, TileVersion version, + const std::vector& input, const std::vector& data); int updateTile(TileId tileId, TileVersion version, const std::vector& data); - int deleteTilesAt(std::string_view worldspace, const TilePosition& tilePosition); + int deleteTilesAt(ESM::RefId worldspace, const TilePosition& tilePosition); - int deleteTilesAtExcept(std::string_view worldspace, const TilePosition& tilePosition, TileId excludeTileId); + int deleteTilesAtExcept(ESM::RefId worldspace, const TilePosition& tilePosition, TileId excludeTileId); - int deleteTilesOutsideRange(std::string_view worldspace, const TilesPositionsRange& range); + int deleteTilesOutsideRange(ESM::RefId worldspace, const TilesPositionsRange& range); ShapeId getMaxShapeId(); diff --git a/components/detournavigator/navmeshmanager.cpp b/components/detournavigator/navmeshmanager.cpp index bb0a8e3451..7a2fd74714 100644 --- a/components/detournavigator/navmeshmanager.cpp +++ b/components/detournavigator/navmeshmanager.cpp @@ -58,7 +58,7 @@ namespace DetourNavigator { } - void NavMeshManager::setWorldspace(std::string_view worldspace, const UpdateGuard* guard) + void NavMeshManager::setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard) { if (worldspace == mWorldspace) return; diff --git a/components/detournavigator/navmeshmanager.hpp b/components/detournavigator/navmeshmanager.hpp index b50d6fb9f2..6c25cc599f 100644 --- a/components/detournavigator/navmeshmanager.hpp +++ b/components/detournavigator/navmeshmanager.hpp @@ -24,7 +24,7 @@ namespace DetourNavigator ScopedUpdateGuard makeUpdateGuard() { return mRecastMeshManager.makeUpdateGuard(); } - void setWorldspace(std::string_view worldspace, const UpdateGuard* guard); + void setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard); void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard); @@ -67,7 +67,7 @@ namespace DetourNavigator private: const Settings& mSettings; - std::string mWorldspace; + ESM::RefId mWorldspace; TileCachedRecastMeshManager mRecastMeshManager; OffMeshConnectionsManager mOffMeshConnectionsManager; AsyncNavMeshUpdater mAsyncNavMeshUpdater; diff --git a/components/detournavigator/recastcontext.cpp b/components/detournavigator/recastcontext.cpp index 7ac7bcb66e..225f251f4d 100644 --- a/components/detournavigator/recastcontext.cpp +++ b/components/detournavigator/recastcontext.cpp @@ -24,7 +24,7 @@ namespace DetourNavigator } std::string formatPrefix( - std::string_view worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds) + ESM::RefId worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds) { std::ostringstream stream; stream << "Worldspace: " << worldspace << "; tile position: " << tilePosition.x() << ", " @@ -34,7 +34,7 @@ namespace DetourNavigator } RecastContext::RecastContext( - std::string_view worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds) + ESM::RefId worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds) : mPrefix(formatPrefix(worldspace, tilePosition, agentBounds)) { } diff --git a/components/detournavigator/recastcontext.hpp b/components/detournavigator/recastcontext.hpp index 3d65bbe95a..8e75f50b34 100644 --- a/components/detournavigator/recastcontext.hpp +++ b/components/detournavigator/recastcontext.hpp @@ -3,6 +3,8 @@ #include "tileposition.hpp" +#include + #include #include @@ -14,8 +16,7 @@ namespace DetourNavigator class RecastContext final : public rcContext { public: - explicit RecastContext( - std::string_view worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds); + explicit RecastContext(ESM::RefId worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds); const std::string& getPrefix() const { return mPrefix; } diff --git a/components/detournavigator/recastmeshprovider.hpp b/components/detournavigator/recastmeshprovider.hpp index d0cba1c348..6759daa65a 100644 --- a/components/detournavigator/recastmeshprovider.hpp +++ b/components/detournavigator/recastmeshprovider.hpp @@ -20,7 +20,7 @@ namespace DetourNavigator { } - std::shared_ptr getMesh(std::string_view worldspace, const TilePosition& tilePosition) const + std::shared_ptr getMesh(ESM::RefId worldspace, const TilePosition& tilePosition) const { return mImpl.get().getNewMesh(worldspace, tilePosition); } diff --git a/components/detournavigator/tilecachedrecastmeshmanager.cpp b/components/detournavigator/tilecachedrecastmeshmanager.cpp index a34ac8e795..5cb95fed64 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.cpp @@ -142,7 +142,7 @@ namespace DetourNavigator return {}; } - void TileCachedRecastMeshManager::setWorldspace(std::string_view worldspace, const UpdateGuard* guard) + void TileCachedRecastMeshManager::setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard) { const MaybeLockGuard lock(mMutex, guard); if (mWorldspace == worldspace) @@ -351,7 +351,7 @@ namespace DetourNavigator } std::shared_ptr TileCachedRecastMeshManager::getMesh( - std::string_view worldspace, const TilePosition& tilePosition) + ESM::RefId worldspace, const TilePosition& tilePosition) { { const std::lock_guard lock(mMutex); @@ -375,7 +375,7 @@ namespace DetourNavigator } std::shared_ptr TileCachedRecastMeshManager::getCachedMesh( - std::string_view worldspace, const TilePosition& tilePosition) const + ESM::RefId worldspace, const TilePosition& tilePosition) const { const std::lock_guard lock(mMutex); if (mWorldspace != worldspace) @@ -387,7 +387,7 @@ namespace DetourNavigator } std::shared_ptr TileCachedRecastMeshManager::getNewMesh( - std::string_view worldspace, const TilePosition& tilePosition) const + ESM::RefId worldspace, const TilePosition& tilePosition) const { { const std::lock_guard lock(mMutex); diff --git a/components/detournavigator/tilecachedrecastmeshmanager.hpp b/components/detournavigator/tilecachedrecastmeshmanager.hpp index 553e664a5f..fc4ace118d 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.hpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.hpp @@ -25,8 +25,6 @@ #include #include #include -#include -#include #include namespace DetourNavigator @@ -49,7 +47,7 @@ namespace DetourNavigator TilesPositionsRange getLimitedObjectsRange() const; - void setWorldspace(std::string_view worldspace, const UpdateGuard* guard); + void setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard); bool addObject(ObjectId id, const CollisionShape& shape, const btTransform& transform, AreaType areaType, const UpdateGuard* guard); @@ -67,11 +65,11 @@ namespace DetourNavigator void removeHeightfield(const osg::Vec2i& cellPosition, const UpdateGuard* guard); - std::shared_ptr getMesh(std::string_view worldspace, const TilePosition& tilePosition); + std::shared_ptr getMesh(ESM::RefId worldspace, const TilePosition& tilePosition); - std::shared_ptr getCachedMesh(std::string_view worldspace, const TilePosition& tilePosition) const; + std::shared_ptr getCachedMesh(ESM::RefId worldspace, const TilePosition& tilePosition) const; - std::shared_ptr getNewMesh(std::string_view worldspace, const TilePosition& tilePosition) const; + std::shared_ptr getNewMesh(ESM::RefId worldspace, const TilePosition& tilePosition) const; std::size_t getRevision() const { return mRevision; } @@ -130,7 +128,7 @@ namespace DetourNavigator const RecastSettings& mSettings; TilesPositionsRange mRange; - std::string mWorldspace; + ESM::RefId mWorldspace; std::unordered_map> mObjects; boost::geometry::index::rtree> mObjectIndex; std::map mWater;