From b4ab1534184d16fedd92cb731f84b34c810bbffb Mon Sep 17 00:00:00 2001 From: elsid Date: Thu, 29 Dec 2022 23:21:30 +0100 Subject: [PATCH] Use ESM::RefId for worldspace in detournavigator --- apps/navmeshtool/main.cpp | 1 + apps/navmeshtool/navmesh.cpp | 12 +- apps/navmeshtool/worldspacedata.cpp | 16 +-- apps/navmeshtool/worldspacedata.hpp | 5 +- .../detournavigator/asyncnavmeshupdater.cpp | 3 +- .../detournavigator/navigator.cpp | 2 - .../detournavigator/navmeshdb.cpp | 15 +-- .../tilecachedrecastmeshmanager.cpp | 107 +++++++++--------- .../detournavigator/asyncnavmeshupdater.cpp | 5 +- .../detournavigator/asyncnavmeshupdater.hpp | 8 +- .../detournavigator/generatenavmeshtile.cpp | 5 +- .../detournavigator/generatenavmeshtile.hpp | 15 +-- components/detournavigator/navigator.hpp | 2 - components/detournavigator/navigatorimpl.cpp | 7 +- components/detournavigator/navigatorimpl.hpp | 2 - components/detournavigator/navigatorstub.hpp | 1 - components/detournavigator/navmeshdb.cpp | 32 ++++-- components/detournavigator/navmeshdb.hpp | 17 ++- components/detournavigator/navmeshmanager.cpp | 3 +- components/detournavigator/navmeshmanager.hpp | 6 +- .../detournavigator/recastmeshprovider.hpp | 2 +- .../tilecachedrecastmeshmanager.cpp | 9 +- .../tilecachedrecastmeshmanager.hpp | 12 +- 23 files changed, 153 insertions(+), 134 deletions(-) diff --git a/apps/navmeshtool/main.cpp b/apps/navmeshtool/main.cpp index 808f393b49..774826e4f2 100644 --- a/apps/navmeshtool/main.cpp +++ b/apps/navmeshtool/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/apps/navmeshtool/navmesh.cpp b/apps/navmeshtool/navmesh.cpp index 384c965466..8b85533170 100644 --- a/apps/navmeshtool/navmesh.cpp +++ b/apps/navmeshtool/navmesh.cpp @@ -106,7 +106,7 @@ namespace NavMeshTool return DetourNavigator::resolveMeshSource(mDb, source, mNextShapeId); } - std::optional find(std::string_view worldspace, const TilePosition& tilePosition, + std::optional find(const ESM::RefId& worldspace, const TilePosition& tilePosition, const std::vector& input) override { std::optional result; @@ -121,7 +121,7 @@ namespace NavMeshTool return result; } - void ignore(std::string_view worldspace, const TilePosition& tilePosition) override + void ignore(const 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(const 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(const 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(const 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(const 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 4bf915254c..6f27bef93d 100644 --- a/apps/navmeshtool/worldspacedata.cpp +++ b/apps/navmeshtool/worldspacedata.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,6 @@ #include #include -#include #include #include #include @@ -37,6 +37,7 @@ #include #include #include + namespace NavMeshTool { namespace @@ -221,7 +222,7 @@ namespace NavMeshTool } WorldspaceNavMeshInput::WorldspaceNavMeshInput( - std::string worldspace, const DetourNavigator::RecastSettings& settings) + ESM::RefId worldspace, const DetourNavigator::RecastSettings& settings) : mWorldspace(std::move(worldspace)) , mTileCachedRecastMeshManager(settings) { @@ -235,7 +236,7 @@ namespace NavMeshTool { Log(Debug::Info) << "Processing " << esmData.mCells.size() << " cells..."; - std::map> navMeshInputs; + std::map> navMeshInputs; WorldspaceData data; std::size_t objectsCounter = 0; @@ -263,16 +264,15 @@ namespace NavMeshTool const osg::Vec2i cellPosition(cell.mData.mX, cell.mData.mY); const std::size_t cellObjectsBegin = data.mObjects.size(); - const auto cellNameLowerCase = Misc::StringUtils::lowerCase(cell.mCellId.mWorldspace.getRefIdString()); WorldspaceNavMeshInput& navMeshInput = [&]() -> WorldspaceNavMeshInput& { - auto it = navMeshInputs.find(cellNameLowerCase); + auto it = navMeshInputs.find(cell.mCellId.mWorldspace); if (it == navMeshInputs.end()) { it = navMeshInputs - .emplace(cellNameLowerCase, - std::make_unique(cellNameLowerCase, settings.mRecast)) + .emplace(cell.mCellId.mWorldspace, + std::make_unique(cell.mCellId.mWorldspace, settings.mRecast)) .first; - it->second->mTileCachedRecastMeshManager.setWorldspace(cellNameLowerCase, nullptr); + it->second->mTileCachedRecastMeshManager.setWorldspace(cell.mCellId.mWorldspace, nullptr); } return *it->second; }(); diff --git a/apps/navmeshtool/worldspacedata.hpp b/apps/navmeshtool/worldspacedata.hpp index b6ccce6733..3aaf9f9ca0 100644 --- a/apps/navmeshtool/worldspacedata.hpp +++ b/apps/navmeshtool/worldspacedata.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -48,12 +49,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_test_suite/detournavigator/asyncnavmeshupdater.cpp b/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp index 1fa868f133..406c9d96be 100644 --- a/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp +++ b/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,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; }; diff --git a/apps/openmw_test_suite/detournavigator/navigator.cpp b/apps/openmw_test_suite/detournavigator/navigator.cpp index 10083ddfa0..1593ec8493 100644 --- a/apps/openmw_test_suite/detournavigator/navigator.cpp +++ b/apps/openmw_test_suite/detournavigator/navigator.cpp @@ -40,7 +40,6 @@ namespace Settings mSettings = makeSettings(); std::unique_ptr mNavigator; const osg::Vec3f mPlayerPosition; - const std::string mWorldspace; const AgentBounds mAgentBounds{ CollisionShapeType::Aabb, { 29, 29, 66 } }; osg::Vec3f mStart; osg::Vec3f mEnd; @@ -57,7 +56,6 @@ namespace DetourNavigatorNavigatorTest() : mPlayerPosition(256, 256, 0) - , mWorldspace("sys::default") , mStart(52, 460, 1) , mEnd(460, 52, 1) , mOut(mPath) diff --git a/apps/openmw_test_suite/detournavigator/navmeshdb.cpp b/apps/openmw_test_suite/detournavigator/navmeshdb.cpp index 4cf88f5711..75b7e26f7c 100644 --- a/apps/openmw_test_suite/detournavigator/navmeshdb.cpp +++ b/apps/openmw_test_suite/detournavigator/navmeshdb.cpp @@ -1,6 +1,7 @@ #include "generate.hpp" #include +#include #include @@ -19,7 +20,7 @@ namespace struct Tile { - std::string mWorldspace; + ESM::RefId mWorldspace; TilePosition mTilePosition; std::vector mInput; std::vector mData; @@ -39,7 +40,7 @@ namespace Tile insertTile(TileId tileId, TileVersion version) { - std::string worldspace = "sys::default"; + ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const TilePosition tilePosition{ 3, 4 }; std::vector input = generateData(); std::vector data = generateData(); @@ -89,7 +90,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 +102,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 +114,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 +131,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 +149,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 f88a7c5aa0..9bd812f9e4 100644 --- a/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp @@ -1,6 +1,7 @@ #include #include +#include #include @@ -20,6 +21,8 @@ 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"); + const ESM::RefId mOtherWorldspace = ESM::RefId::stringRefId("other"); DetourNavigatorTileCachedRecastMeshManagerTest() { @@ -33,7 +36,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) @@ -64,14 +67,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) @@ -141,25 +144,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, @@ -170,7 +173,7 @@ namespace bounds.mMin = osg::Vec2f(-1000, -1000); bounds.mMax = osg::Vec2f(1000, 1000); manager.setBounds(bounds, nullptr); - manager.setWorldspace("worldspace", nullptr); + manager.setWorldspace(mWorldspace, nullptr); const btBoxShape boxShape(btVector3(20, 20, 100)); const btTransform transform( @@ -178,23 +181,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( @@ -202,48 +205,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, @@ -288,7 +291,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); @@ -334,19 +337,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( @@ -356,7 +359,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); } @@ -385,20 +388,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( @@ -409,14 +412,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)); @@ -427,21 +430,21 @@ 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); + manager.setWorldspace(mOtherWorldspace, 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(mOtherWorldspace, TilePosition(x, y)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_bounds_should_add_changed_tiles) diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index 1f2ba8895b..7df9d5d59b 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -8,6 +8,7 @@ #include "version.hpp" #include +#include #include #include @@ -135,7 +136,7 @@ namespace DetourNavigator } Job::Job(const AgentBounds& agentBounds, std::weak_ptr navMeshCacheItem, - std::string_view worldspace, const TilePosition& changedTile, ChangeType changeType, int distanceToPlayer, + const ESM::RefId& worldspace, const TilePosition& changedTile, ChangeType changeType, int distanceToPlayer, std::chrono::steady_clock::time_point processTime) : mId(getNextJobId()) , mAgentBounds(agentBounds) @@ -168,7 +169,7 @@ namespace DetourNavigator } void AsyncNavMeshUpdater::post(const AgentBounds& agentBounds, const SharedNavMeshCacheItem& navMeshCacheItem, - const TilePosition& playerTile, std::string_view worldspace, + const TilePosition& playerTile, const ESM::RefId& worldspace, const std::map& changedTiles) { bool playerTileChanged = false; diff --git a/components/detournavigator/asyncnavmeshupdater.hpp b/components/detournavigator/asyncnavmeshupdater.hpp index 1991da15b7..931d14ecbd 100644 --- a/components/detournavigator/asyncnavmeshupdater.hpp +++ b/components/detournavigator/asyncnavmeshupdater.hpp @@ -14,6 +14,8 @@ #include "tileposition.hpp" #include "waitconditiontype.hpp" +#include + #include #include @@ -49,7 +51,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; const std::chrono::steady_clock::time_point mProcessTime; unsigned mTryNumber = 0; @@ -63,7 +65,7 @@ namespace DetourNavigator std::unique_ptr mGeneratedNavMeshData; Job(const AgentBounds& agentBounds, std::weak_ptr navMeshCacheItem, - std::string_view worldspace, const TilePosition& changedTile, ChangeType changeType, int distanceToPlayer, + const ESM::RefId& worldspace, const TilePosition& changedTile, ChangeType changeType, int distanceToPlayer, std::chrono::steady_clock::time_point processTime); }; @@ -148,7 +150,7 @@ namespace DetourNavigator ~AsyncNavMeshUpdater(); void post(const AgentBounds& agentBounds, const SharedNavMeshCacheItem& navMeshCacheItem, - const TilePosition& playerTile, std::string_view worldspace, + const TilePosition& playerTile, const 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 3e3c88e694..175eb7e9cb 100644 --- a/components/detournavigator/generatenavmeshtile.cpp +++ b/components/detournavigator/generatenavmeshtile.cpp @@ -7,6 +7,7 @@ #include "settings.hpp" #include +#include #include #include @@ -23,7 +24,7 @@ namespace DetourNavigator { struct Ignore { - std::string_view mWorldspace; + const ESM::RefId& mWorldspace; const TilePosition& mTilePosition; std::shared_ptr mConsumer; @@ -35,7 +36,7 @@ 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)) diff --git a/components/detournavigator/generatenavmeshtile.hpp b/components/detournavigator/generatenavmeshtile.hpp index ad06ea071c..b8b4ecc8b1 100644 --- a/components/detournavigator/generatenavmeshtile.hpp +++ b/components/detournavigator/generatenavmeshtile.hpp @@ -5,6 +5,7 @@ #include "recastmeshprovider.hpp" #include "tileposition.hpp" +#include #include #include @@ -38,18 +39,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) + const 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(const 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(const 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(const 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(const ESM::RefId& worldspace, const TilePosition& tilePosition, std::int64_t tileId, std::int64_t version, PreparedNavMeshData& data) = 0; @@ -59,14 +60,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/navigator.hpp b/components/detournavigator/navigator.hpp index 2015730de4..acec287953 100644 --- a/components/detournavigator/navigator.hpp +++ b/components/detournavigator/navigator.hpp @@ -90,8 +90,6 @@ 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(const ESM::RefId& worldspace, const UpdateGuard* guard) = 0; /** diff --git a/components/detournavigator/navigatorimpl.cpp b/components/detournavigator/navigatorimpl.cpp index 9bcee95d1d..00ec06b3cb 100644 --- a/components/detournavigator/navigatorimpl.cpp +++ b/components/detournavigator/navigatorimpl.cpp @@ -33,14 +33,9 @@ namespace DetourNavigator --it->second; } - void NavigatorImpl::setWorldspace(std::string_view worldspace, const UpdateGuard* guard) - { - mNavMeshManager.setWorldspace(worldspace, getImpl(guard)); - } - void NavigatorImpl::setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) { - setWorldspace(Misc::StringUtils::lowerCase(worldspace.getRefIdString()), guard); + mNavMeshManager.setWorldspace(worldspace, getImpl(guard)); } void NavigatorImpl::updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard) diff --git a/components/detournavigator/navigatorimpl.hpp b/components/detournavigator/navigatorimpl.hpp index ddced1c3e9..a28985d466 100644 --- a/components/detournavigator/navigatorimpl.hpp +++ b/components/detournavigator/navigatorimpl.hpp @@ -27,8 +27,6 @@ namespace DetourNavigator void removeAgent(const AgentBounds& agentBounds) override; - void setWorldspace(std::string_view worldspace, const UpdateGuard* guard) override; - void setWorldspace(const 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 ad7f866797..79a6e2a5d1 100644 --- a/components/detournavigator/navigatorstub.hpp +++ b/components/detournavigator/navigatorstub.hpp @@ -23,7 +23,6 @@ namespace DetourNavigator void removeAgent(const AgentBounds& /*agentBounds*/) override {} - void setWorldspace(std::string_view /*worldspace*/, const UpdateGuard* /*guard*/) override {} void setWorldspace(const ESM::RefId& /*worldspace*/, const UpdateGuard* /*guard*/) override {} void addObject(const ObjectId /*id*/, const ObjectShapes& /*shapes*/, const btTransform& /*transform*/, diff --git a/components/detournavigator/navmeshdb.cpp b/components/detournavigator/navmeshdb.cpp index d5c6fdb46b..6c64fe200b 100644 --- a/components/detournavigator/navmeshdb.cpp +++ b/components/detournavigator/navmeshdb.cpp @@ -1,8 +1,10 @@ #include "navmeshdb.hpp" #include +#include #include #include +#include #include #include @@ -152,6 +154,11 @@ namespace DetourNavigator if (const int ec = sqlite3_exec(&db, query.c_str(), nullptr, nullptr, nullptr); ec != SQLITE_OK) throw std::runtime_error("Failed set max page count: " + std::string(sqlite3_errmsg(&db))); } + + std::string toLowerCaseString(const ESM::RefId& refId) + { + return Misc::StringUtils::lowerCase(refId.getRefIdString()); + } } std::ostream& operator<<(std::ostream& stream, ShapeType value) @@ -200,34 +207,35 @@ namespace DetourNavigator } std::optional NavMeshDb::findTile( - std::string_view worldspace, const TilePosition& tilePosition, const std::vector& input) + const 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, toLowerCaseString(worldspace), tilePosition, compressedInput)) return {}; return result; } std::optional NavMeshDb::getTileData( - std::string_view worldspace, const TilePosition& tilePosition, const std::vector& input) + const 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, toLowerCaseString(worldspace), 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, const 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, toLowerCaseString(worldspace), tilePosition, version, compressedInput, + compressedData); } int NavMeshDb::updateTile(TileId tileId, TileVersion version, const std::vector& data) @@ -236,20 +244,20 @@ namespace DetourNavigator return execute(*mDb, mUpdateTile, tileId, version, compressedData); } - int NavMeshDb::deleteTilesAt(std::string_view worldspace, const TilePosition& tilePosition) + int NavMeshDb::deleteTilesAt(const ESM::RefId& worldspace, const TilePosition& tilePosition) { - return execute(*mDb, mDeleteTilesAt, worldspace, tilePosition); + return execute(*mDb, mDeleteTilesAt, toLowerCaseString(worldspace), tilePosition); } int NavMeshDb::deleteTilesAtExcept( - std::string_view worldspace, const TilePosition& tilePosition, TileId excludeTileId) + const ESM::RefId& worldspace, const TilePosition& tilePosition, TileId excludeTileId) { - return execute(*mDb, mDeleteTilesAtExcept, worldspace, tilePosition, excludeTileId); + return execute(*mDb, mDeleteTilesAtExcept, toLowerCaseString(worldspace), tilePosition, excludeTileId); } - int NavMeshDb::deleteTilesOutsideRange(std::string_view worldspace, const TilesPositionsRange& range) + int NavMeshDb::deleteTilesOutsideRange(const ESM::RefId& worldspace, const TilesPositionsRange& range) { - return execute(*mDb, mDeleteTilesOutsideRange, worldspace, range); + return execute(*mDb, mDeleteTilesOutsideRange, toLowerCaseString(worldspace), range); } ShapeId NavMeshDb::getMaxShapeId() diff --git a/components/detournavigator/navmeshdb.hpp b/components/detournavigator/navmeshdb.hpp index 3cf1bdcdca..b6fc93f562 100644 --- a/components/detournavigator/navmeshdb.hpp +++ b/components/detournavigator/navmeshdb.hpp @@ -25,6 +25,11 @@ struct sqlite3; struct sqlite3_stmt; +namespace ESM +{ + struct RefId; +} + namespace DetourNavigator { using TileId = Misc::StrongTypedef; @@ -148,21 +153,21 @@ namespace DetourNavigator TileId getMaxTileId(); std::optional findTile( - std::string_view worldspace, const TilePosition& tilePosition, const std::vector& input); + const ESM::RefId& worldspace, const TilePosition& tilePosition, const std::vector& input); std::optional getTileData( - std::string_view worldspace, const TilePosition& tilePosition, const std::vector& input); + const ESM::RefId& worldspace, const TilePosition& tilePosition, const std::vector& input); - int insertTile(TileId tileId, std::string_view worldspace, const TilePosition& tilePosition, + int insertTile(TileId tileId, const 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(const ESM::RefId& worldspace, const TilePosition& tilePosition); - int deleteTilesAtExcept(std::string_view worldspace, const TilePosition& tilePosition, TileId excludeTileId); + int deleteTilesAtExcept(const ESM::RefId& worldspace, const TilePosition& tilePosition, TileId excludeTileId); - int deleteTilesOutsideRange(std::string_view worldspace, const TilesPositionsRange& range); + int deleteTilesOutsideRange(const ESM::RefId& worldspace, const TilesPositionsRange& range); ShapeId getMaxShapeId(); diff --git a/components/detournavigator/navmeshmanager.cpp b/components/detournavigator/navmeshmanager.cpp index 41fb4fe191..e4fbbafdac 100644 --- a/components/detournavigator/navmeshmanager.cpp +++ b/components/detournavigator/navmeshmanager.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -59,7 +60,7 @@ namespace DetourNavigator { } - void NavMeshManager::setWorldspace(std::string_view worldspace, const UpdateGuard* guard) + void NavMeshManager::setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) { if (worldspace == mWorldspace) return; diff --git a/components/detournavigator/navmeshmanager.hpp b/components/detournavigator/navmeshmanager.hpp index 332d9e25f7..b971694f7c 100644 --- a/components/detournavigator/navmeshmanager.hpp +++ b/components/detournavigator/navmeshmanager.hpp @@ -8,6 +8,8 @@ #include "recastmeshtiles.hpp" #include "waitconditiontype.hpp" +#include + #include #include @@ -39,7 +41,7 @@ namespace DetourNavigator explicit NavMeshManager(const Settings& settings, std::unique_ptr&& db); - void setWorldspace(std::string_view worldspace, const UpdateGuard* guard); + void setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard); void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard); @@ -82,7 +84,7 @@ namespace DetourNavigator private: const Settings& mSettings; - std::string mWorldspace; + ESM::RefId mWorldspace; TileCachedRecastMeshManager mRecastMeshManager; OffMeshConnectionsManager mOffMeshConnectionsManager; AsyncNavMeshUpdater mAsyncNavMeshUpdater; diff --git a/components/detournavigator/recastmeshprovider.hpp b/components/detournavigator/recastmeshprovider.hpp index d0cba1c348..6d7a3a0f64 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(const 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 069798933d..88e44da0b3 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.cpp @@ -5,6 +5,7 @@ #include "settingsutils.hpp" #include +#include #include #include @@ -112,7 +113,7 @@ namespace DetourNavigator }; } - void TileCachedRecastMeshManager::setWorldspace(std::string_view worldspace, const UpdateGuard* guard) + void TileCachedRecastMeshManager::setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) { const MaybeLockGuard lock(mMutex, guard); if (mWorldspace == worldspace) @@ -321,7 +322,7 @@ namespace DetourNavigator } std::shared_ptr TileCachedRecastMeshManager::getMesh( - std::string_view worldspace, const TilePosition& tilePosition) + const ESM::RefId& worldspace, const TilePosition& tilePosition) { { const std::lock_guard lock(mMutex); @@ -345,7 +346,7 @@ namespace DetourNavigator } std::shared_ptr TileCachedRecastMeshManager::getCachedMesh( - std::string_view worldspace, const TilePosition& tilePosition) const + const ESM::RefId& worldspace, const TilePosition& tilePosition) const { const std::lock_guard lock(mMutex); if (mWorldspace != worldspace) @@ -357,7 +358,7 @@ namespace DetourNavigator } std::shared_ptr TileCachedRecastMeshManager::getNewMesh( - std::string_view worldspace, const TilePosition& tilePosition) const + 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 22c1fb649b..372fbbae10 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.hpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.hpp @@ -12,6 +12,8 @@ #include "tileposition.hpp" #include "version.hpp" +#include + #include #include #include @@ -46,7 +48,7 @@ namespace DetourNavigator TilesPositionsRange getRange() const; - void setWorldspace(std::string_view worldspace, const UpdateGuard* guard); + void setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard); bool addObject(ObjectId id, const CollisionShape& shape, const btTransform& transform, AreaType areaType, const UpdateGuard* guard); @@ -64,11 +66,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(const ESM::RefId& worldspace, const TilePosition& tilePosition); - std::shared_ptr getCachedMesh(std::string_view worldspace, const TilePosition& tilePosition) const; + std::shared_ptr getCachedMesh(const ESM::RefId& worldspace, const TilePosition& tilePosition) const; - std::shared_ptr getNewMesh(std::string_view worldspace, const TilePosition& tilePosition) const; + std::shared_ptr getNewMesh(const ESM::RefId& worldspace, const TilePosition& tilePosition) const; std::size_t getRevision() const { return mRevision; } @@ -126,7 +128,7 @@ namespace DetourNavigator const RecastSettings& mSettings; TileBounds mBounds; TilesPositionsRange mRange; - std::string mWorldspace; + ESM::RefId mWorldspace; std::unordered_map> mObjects; boost::geometry::index::rtree> mObjectIndex; std::map mWater;