From 73734fc04da2901bc78d7c421498ac34ac9089d8 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 22 Feb 2019 11:34:53 +0300 Subject: [PATCH] Fix update navmesh for not changed objects When update method is called for not changed object befor this change all object tiles were considered as not object tiles and were removed. Also this marked those tiles as changed. This lead to alternation between remove and add each tile update method was called. Problem was detected by using Animated Containers mod. --- .../tilecachedrecastmeshmanager.cpp | 18 ++++++++++++++++++ .../tilecachedrecastmeshmanager.cpp | 4 +--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp b/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp index 0443fc9ce..b84f7a22e 100644 --- a/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp @@ -120,4 +120,22 @@ namespace EXPECT_EQ(manager.getMesh(TilePosition(0, -1)), nullptr); EXPECT_EQ(manager.getMesh(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); + const btBoxShape boxShape(btVector3(20, 20, 100)); + + manager.addObject(ObjectId(1ul), boxShape, btTransform::getIdentity(), AreaType::AreaType_ground); + EXPECT_NE(manager.getMesh(TilePosition(-1, -1)), nullptr); + EXPECT_NE(manager.getMesh(TilePosition(-1, 0)), nullptr); + EXPECT_NE(manager.getMesh(TilePosition(0, -1)), nullptr); + EXPECT_NE(manager.getMesh(TilePosition(0, 0)), nullptr); + + manager.updateObject(ObjectId(1ul), boxShape, btTransform::getIdentity(), AreaType::AreaType_ground); + EXPECT_NE(manager.getMesh(TilePosition(-1, -1)), nullptr); + EXPECT_NE(manager.getMesh(TilePosition(-1, 0)), nullptr); + EXPECT_NE(manager.getMesh(TilePosition(0, -1)), nullptr); + EXPECT_NE(manager.getMesh(TilePosition(0, 0)), nullptr); + } } diff --git a/components/detournavigator/tilecachedrecastmeshmanager.cpp b/components/detournavigator/tilecachedrecastmeshmanager.cpp index 7070603c7..b878c2d3e 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.cpp @@ -47,11 +47,9 @@ namespace DetourNavigator { if (currentTiles.count(tilePosition)) { + newTiles.insert(tilePosition); if (updateTile(id, transform, areaType, tilePosition, tiles.get())) - { - newTiles.insert(tilePosition); changedTiles.push_back(tilePosition); - } } else if (addTile(id, shape, transform, areaType, tilePosition, border, tiles.get())) {