diff --git a/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp b/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp index 51580906ce..6209ec9c2a 100644 --- a/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp @@ -38,12 +38,6 @@ namespace EXPECT_EQ(manager.getMesh(TilePosition(0, 0)), nullptr); } - TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, has_tile_for_empty_should_return_false) - { - TileCachedRecastMeshManager manager(mSettings); - EXPECT_FALSE(manager.hasTile(TilePosition(0, 0))); - } - TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_revision_for_empty_should_return_zero) { const TileCachedRecastMeshManager manager(mSettings); @@ -83,7 +77,7 @@ namespace ASSERT_TRUE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground)); for (int x = -1; x < 1; ++x) for (int y = -1; y < 1; ++y) - ASSERT_TRUE(manager.hasTile(TilePosition(x, y))); + ASSERT_NE(manager.getMesh(TilePosition(x, y)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, update_object_for_changed_object_should_return_changed_tiles) @@ -281,7 +275,7 @@ namespace ASSERT_TRUE(manager.addWater(cellPosition, cellSize, osg::Vec3f())); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) - ASSERT_TRUE(manager.hasTile(TilePosition(x, y))); + ASSERT_NE(manager.getMesh(TilePosition(x, y)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_max_int_should_not_add_new_tiles) @@ -295,7 +289,7 @@ namespace ASSERT_TRUE(manager.addWater(cellPosition, cellSize, osg::Vec3f())); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) - ASSERT_EQ(manager.hasTile(TilePosition(x, y)), -1 <= x && x <= 0 && -1 <= y && y <= 0); + ASSERT_EQ(manager.getMesh(TilePosition(x, y)) != nullptr, -1 <= x && x <= 0 && -1 <= y && y <= 0); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_absent_cell_should_return_nullopt) @@ -324,7 +318,7 @@ namespace ASSERT_TRUE(manager.removeWater(cellPosition)); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) - ASSERT_FALSE(manager.hasTile(TilePosition(x, y))); + ASSERT_EQ(manager.getMesh(TilePosition(x, y)), nullptr); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_leave_not_empty_tiles) @@ -339,7 +333,7 @@ namespace ASSERT_TRUE(manager.removeWater(cellPosition)); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) - ASSERT_EQ(manager.hasTile(TilePosition(x, y)), -1 <= x && x <= 0 && -1 <= y && y <= 0); + ASSERT_EQ(manager.getMesh(TilePosition(x, y)) != nullptr, -1 <= x && x <= 0 && -1 <= y && y <= 0); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_object_should_not_remove_tile_with_water) @@ -354,6 +348,6 @@ namespace ASSERT_TRUE(manager.removeObject(ObjectId(&boxShape))); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) - ASSERT_TRUE(manager.hasTile(TilePosition(x, y))); + ASSERT_NE(manager.getMesh(TilePosition(x, y)), nullptr); } } diff --git a/components/detournavigator/recastmeshmanager.cpp b/components/detournavigator/recastmeshmanager.cpp index e4e5b76449..2eeb90a9b5 100644 --- a/components/detournavigator/recastmeshmanager.cpp +++ b/components/detournavigator/recastmeshmanager.cpp @@ -117,7 +117,7 @@ namespace DetourNavigator return result; } - std::shared_ptr RecastMeshManager::getMesh() + std::shared_ptr RecastMeshManager::getMesh() const { TileBounds tileBounds = mTileBounds; tileBounds.mMin /= mSettings.mRecastScaleFactor; diff --git a/components/detournavigator/recastmeshmanager.hpp b/components/detournavigator/recastmeshmanager.hpp index 1cd35ca467..e1c1567cb3 100644 --- a/components/detournavigator/recastmeshmanager.hpp +++ b/components/detournavigator/recastmeshmanager.hpp @@ -52,7 +52,7 @@ namespace DetourNavigator std::optional removeHeightfield(const osg::Vec2i& cellPosition); - std::shared_ptr getMesh(); + std::shared_ptr getMesh() const; bool isEmpty() const; diff --git a/components/detournavigator/tilecachedrecastmeshmanager.cpp b/components/detournavigator/tilecachedrecastmeshmanager.cpp index 2b8c85b8a3..38314f08a5 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.cpp @@ -190,11 +190,11 @@ namespace DetourNavigator return result; } - std::shared_ptr TileCachedRecastMeshManager::getMesh(const TilePosition& tilePosition) + std::shared_ptr TileCachedRecastMeshManager::getMesh(const TilePosition& tilePosition) const { const auto manager = [&] () -> std::shared_ptr { - const auto tiles = mTiles.lock(); + const auto tiles = mTiles.lockConst(); const auto it = tiles->find(tilePosition); if (it == tiles->end()) return nullptr; @@ -205,19 +205,14 @@ namespace DetourNavigator return manager->getMesh(); } - bool TileCachedRecastMeshManager::hasTile(const TilePosition& tilePosition) - { - return mTiles.lockConst()->count(tilePosition); - } - std::size_t TileCachedRecastMeshManager::getRevision() const { return mRevision; } - void TileCachedRecastMeshManager::reportNavMeshChange(const TilePosition& tilePosition, Version recastMeshVersion, Version navMeshVersion) + void TileCachedRecastMeshManager::reportNavMeshChange(const TilePosition& tilePosition, Version recastMeshVersion, Version navMeshVersion) const { - const auto tiles = mTiles.lock(); + const auto tiles = mTiles.lockConst(); const auto it = tiles->find(tilePosition); if (it == tiles->end()) return; diff --git a/components/detournavigator/tilecachedrecastmeshmanager.hpp b/components/detournavigator/tilecachedrecastmeshmanager.hpp index f8cb5a8b0e..f6bc40d668 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.hpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.hpp @@ -86,20 +86,18 @@ namespace DetourNavigator std::optional removeHeightfield(const osg::Vec2i& cellPosition); - std::shared_ptr getMesh(const TilePosition& tilePosition); - - bool hasTile(const TilePosition& tilePosition); + std::shared_ptr getMesh(const TilePosition& tilePosition) const; template - void forEachTile(Function&& function) + void forEachTile(Function&& function) const { - for (auto& [tilePosition, recastMeshManager] : *mTiles.lock()) + for (auto& [tilePosition, recastMeshManager] : *mTiles.lockConst()) function(tilePosition, *recastMeshManager); } std::size_t getRevision() const; - void reportNavMeshChange(const TilePosition& tilePosition, Version recastMeshVersion, Version navMeshVersion); + void reportNavMeshChange(const TilePosition& tilePosition, Version recastMeshVersion, Version navMeshVersion) const; private: using TilesMap = std::map>;