1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-28 17:39:42 +00:00

Remove recast mesh tiles outside active range

This commit is contained in:
elsid 2024-05-19 13:47:58 +02:00
parent 4f5bdbb4fb
commit 5d28164416
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
2 changed files with 38 additions and 1 deletions

View file

@ -449,7 +449,7 @@ namespace
ASSERT_EQ(manager.getMesh("other", TilePosition(x, y)), nullptr); ASSERT_EQ(manager.getMesh("other", TilePosition(x, y)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_bounds_should_add_changed_tiles) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_range_should_add_changed_tiles)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
@ -470,4 +470,36 @@ namespace
ElementsAre( ElementsAre(
std::pair(TilePosition(-1, -1), ChangeType::add), std::pair(TilePosition(0, 0), ChangeType::remove))); std::pair(TilePosition(-1, -1), ChangeType::add), std::pair(TilePosition(0, 0), ChangeType::remove)));
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_range_should_remove_cached_recast_meshes_outside_range)
{
TileCachedRecastMeshManager manager(mSettings);
const std::string_view worldspace = "worldspace";
manager.setWorldspace(worldspace, nullptr);
const btBoxShape boxShape(btVector3(100, 100, 20));
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
const TilesPositionsRange range1{
.mBegin = TilePosition(0, 0),
.mEnd = TilePosition(1, 1),
};
manager.setRange(range1, nullptr);
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
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);
const TilesPositionsRange range2{
.mBegin = TilePosition(-1, -1),
.mEnd = TilePosition(0, 0),
};
manager.takeChangedTiles(nullptr);
manager.setRange(range2, nullptr);
ASSERT_EQ(manager.getCachedMesh(worldspace, tilePosition), nullptr);
}
} }

View file

@ -100,6 +100,11 @@ namespace DetourNavigator
} }
}); });
} }
getTilesPositions(mRange, [&](const TilePosition& v) {
if (!isInTilesPositionsRange(range, v))
mCache.erase(v);
});
} }
if (changed) if (changed)