|
|
|
@ -5,6 +5,8 @@
|
|
|
|
|
|
|
|
|
|
#include <BulletCollision/CollisionShapes/btBoxShape.h>
|
|
|
|
|
|
|
|
|
|
#include <osg/io_utils>
|
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
|
|
|
|
@ -16,8 +18,6 @@ namespace
|
|
|
|
|
struct DetourNavigatorTileCachedRecastMeshManagerTest : Test
|
|
|
|
|
{
|
|
|
|
|
RecastSettings mSettings;
|
|
|
|
|
std::vector<TilePosition> mAddedTiles;
|
|
|
|
|
std::vector<std::pair<TilePosition, ChangeType>> mChangedTiles;
|
|
|
|
|
const ObjectTransform mObjectTransform {ESM::Position {{0, 0, 0}, {0, 0, 0}}, 0.0f};
|
|
|
|
|
const osg::ref_ptr<const Resource::BulletShape> mShape = new Resource::BulletShape;
|
|
|
|
|
const osg::ref_ptr<const Resource::BulletShapeInstance> mInstance = new Resource::BulletShapeInstance(mShape);
|
|
|
|
@ -29,16 +29,6 @@ namespace
|
|
|
|
|
mSettings.mRecastScaleFactor = 0.017647058823529415f;
|
|
|
|
|
mSettings.mTileSize = 64;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onAddedTile(const TilePosition& tilePosition)
|
|
|
|
|
{
|
|
|
|
|
mAddedTiles.push_back(tilePosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onChangedTile(const TilePosition& tilePosition, ChangeType changeType)
|
|
|
|
|
{
|
|
|
|
|
mChangedTiles.emplace_back(tilePosition, changeType);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_empty_should_return_nullptr)
|
|
|
|
@ -66,7 +56,7 @@ namespace
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
EXPECT_TRUE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {}));
|
|
|
|
|
EXPECT_TRUE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_for_existing_object_should_return_false)
|
|
|
|
@ -74,8 +64,8 @@ namespace
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
EXPECT_FALSE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {}));
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
EXPECT_FALSE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_add_tiles)
|
|
|
|
@ -84,13 +74,13 @@ namespace
|
|
|
|
|
manager.setWorldspace("worldspace");
|
|
|
|
|
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, [] (auto) {}));
|
|
|
|
|
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_NE(manager.getMesh("worldspace", TilePosition(x, y)), nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_return_added_tiles)
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_return_add_changed_tiles)
|
|
|
|
|
{
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
@ -99,12 +89,11 @@ namespace
|
|
|
|
|
bounds.mMin = osg::Vec2f(182, 182);
|
|
|
|
|
bounds.mMax = osg::Vec2f(1000, 1000);
|
|
|
|
|
manager.setBounds(bounds);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground,
|
|
|
|
|
[&] (const auto& v) { onAddedTile(v); });
|
|
|
|
|
EXPECT_THAT(mAddedTiles, ElementsAre(TilePosition(0, 0)));
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
EXPECT_THAT(manager.takeChangedTiles(), ElementsAre(std::pair(TilePosition(0, 0), ChangeType::add)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, update_object_for_changed_object_should_return_changed_tiles)
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, update_object_for_changed_object_should_add_changed_tiles)
|
|
|
|
|
{
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
@ -114,10 +103,10 @@ namespace
|
|
|
|
|
bounds.mMin = osg::Vec2f(-1000, -1000);
|
|
|
|
|
bounds.mMax = osg::Vec2f(1000, 1000);
|
|
|
|
|
manager.setBounds(bounds);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
EXPECT_TRUE(manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground,
|
|
|
|
|
[&] (const auto& ... v) { onChangedTile(v ...); }));
|
|
|
|
|
EXPECT_THAT(mChangedTiles, ElementsAre(
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground);
|
|
|
|
|
manager.takeChangedTiles();
|
|
|
|
|
EXPECT_TRUE(manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground));
|
|
|
|
|
EXPECT_THAT(manager.takeChangedTiles(), ElementsAre(
|
|
|
|
|
std::pair(TilePosition(-1, -1), ChangeType::add),
|
|
|
|
|
std::pair(TilePosition(-1, 0), ChangeType::add),
|
|
|
|
|
std::pair(TilePosition(0, -1), ChangeType::update),
|
|
|
|
@ -127,15 +116,30 @@ namespace
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, update_object_for_not_changed_object_should_return_empty)
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, update_object_for_not_changed_object_should_not_add_changed_tiles)
|
|
|
|
|
{
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
manager.takeChangedTiles();
|
|
|
|
|
EXPECT_FALSE(manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground));
|
|
|
|
|
EXPECT_THAT(manager.takeChangedTiles(), IsEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_object_should_return_add_changed_tiles)
|
|
|
|
|
{
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
EXPECT_FALSE(manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground,
|
|
|
|
|
[&] (const auto& ... v) { onChangedTile(v ...); }));
|
|
|
|
|
EXPECT_THAT(mChangedTiles, IsEmpty());
|
|
|
|
|
TileBounds bounds;
|
|
|
|
|
bounds.mMin = osg::Vec2f(182, 182);
|
|
|
|
|
bounds.mMax = osg::Vec2f(1000, 1000);
|
|
|
|
|
manager.setBounds(bounds);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
manager.takeChangedTiles();
|
|
|
|
|
manager.removeObject(ObjectId(&boxShape));
|
|
|
|
|
EXPECT_THAT(manager.takeChangedTiles(), ElementsAre(std::pair(TilePosition(0, 0), ChangeType::remove)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_after_add_object_should_return_recast_mesh_for_each_used_tile)
|
|
|
|
@ -144,7 +148,7 @@ namespace
|
|
|
|
|
manager.setWorldspace("worldspace");
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
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);
|
|
|
|
@ -157,7 +161,7 @@ namespace
|
|
|
|
|
manager.setWorldspace("worldspace");
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
EXPECT_EQ(manager.getMesh("worldspace", TilePosition(1, 0)), nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -174,13 +178,13 @@ namespace
|
|
|
|
|
const btTransform transform(btMatrix3x3::getIdentity(), btVector3(getTileSize(mSettings) / mSettings.mRecastScaleFactor, 0, 0));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto, auto) {});
|
|
|
|
|
manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
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);
|
|
|
|
@ -196,11 +200,11 @@ namespace
|
|
|
|
|
const btTransform transform(btMatrix3x3::getIdentity(), btVector3(getTileSize(mSettings) / mSettings.mRecastScaleFactor, 0, 0));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground);
|
|
|
|
|
EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr);
|
|
|
|
|
EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr);
|
|
|
|
|
|
|
|
|
|
manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto, auto) {});
|
|
|
|
|
manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
EXPECT_EQ(manager.getMesh("worldspace", TilePosition(1, 0)), nullptr);
|
|
|
|
|
EXPECT_EQ(manager.getMesh("worldspace", TilePosition(1, -1)), nullptr);
|
|
|
|
|
}
|
|
|
|
@ -211,7 +215,7 @@ namespace
|
|
|
|
|
manager.setWorldspace("worldspace");
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
manager.removeObject(ObjectId(&boxShape));
|
|
|
|
|
EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr);
|
|
|
|
|
EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr);
|
|
|
|
@ -226,13 +230,13 @@ namespace
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto, auto) {});
|
|
|
|
|
manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
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);
|
|
|
|
@ -245,7 +249,7 @@ namespace
|
|
|
|
|
const auto initialRevision = manager.getRevision();
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
EXPECT_EQ(manager.getRevision(), initialRevision + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -254,9 +258,9 @@ namespace
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
const auto beforeAddRevision = manager.getRevision();
|
|
|
|
|
EXPECT_FALSE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {}));
|
|
|
|
|
EXPECT_FALSE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground));
|
|
|
|
|
EXPECT_EQ(manager.getRevision(), beforeAddRevision);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -266,9 +270,9 @@ namespace
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const btTransform transform(btMatrix3x3::getIdentity(), btVector3(getTileSize(mSettings) / mSettings.mRecastScaleFactor, 0, 0));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground);
|
|
|
|
|
const auto beforeUpdateRevision = manager.getRevision();
|
|
|
|
|
manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto, auto) {});
|
|
|
|
|
manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
EXPECT_EQ(manager.getRevision(), beforeUpdateRevision + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -278,9 +282,9 @@ namespace
|
|
|
|
|
manager.setWorldspace("worldspace");
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
const auto beforeUpdateRevision = manager.getRevision();
|
|
|
|
|
manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto, auto) {});
|
|
|
|
|
manager.updateObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
EXPECT_EQ(manager.getRevision(), beforeUpdateRevision);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -289,7 +293,7 @@ namespace
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
const auto beforeRemoveRevision = manager.getRevision();
|
|
|
|
|
manager.removeObject(ObjectId(&boxShape));
|
|
|
|
|
EXPECT_EQ(manager.getRevision(), beforeRemoveRevision + 1);
|
|
|
|
@ -303,12 +307,17 @@ namespace
|
|
|
|
|
EXPECT_EQ(manager.getRevision(), beforeRemoveRevision);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_new_water_should_return_true)
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_new_water_should_add_changed_tiles)
|
|
|
|
|
{
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const osg::Vec2i cellPosition(0, 0);
|
|
|
|
|
const int cellSize = 8192;
|
|
|
|
|
EXPECT_TRUE(manager.addWater(cellPosition, cellSize, 0.0f));
|
|
|
|
|
manager.addWater(cellPosition, cellSize, 0.0f);
|
|
|
|
|
const auto changedTiles = manager.takeChangedTiles();
|
|
|
|
|
EXPECT_EQ(changedTiles.begin()->first, TilePosition(-1, -1));
|
|
|
|
|
EXPECT_EQ(changedTiles.rbegin()->first, TilePosition(11, 11));
|
|
|
|
|
for (const auto& [k, v] : changedTiles)
|
|
|
|
|
EXPECT_EQ(v, ChangeType::add) << k;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_not_max_int_should_add_new_tiles)
|
|
|
|
@ -317,7 +326,7 @@ namespace
|
|
|
|
|
manager.setWorldspace("worldspace");
|
|
|
|
|
const osg::Vec2i cellPosition(0, 0);
|
|
|
|
|
const int cellSize = 8192;
|
|
|
|
|
ASSERT_TRUE(manager.addWater(cellPosition, cellSize, 0.0f));
|
|
|
|
|
manager.addWater(cellPosition, cellSize, 0.0f);
|
|
|
|
|
for (int x = -1; x < 12; ++x)
|
|
|
|
|
for (int y = -1; y < 12; ++y)
|
|
|
|
|
ASSERT_NE(manager.getMesh("worldspace", TilePosition(x, y)), nullptr);
|
|
|
|
@ -329,30 +338,35 @@ namespace
|
|
|
|
|
manager.setWorldspace("worldspace");
|
|
|
|
|
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, [] (auto) {}));
|
|
|
|
|
ASSERT_TRUE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground));
|
|
|
|
|
const osg::Vec2i cellPosition(0, 0);
|
|
|
|
|
const int cellSize = std::numeric_limits<int>::max();
|
|
|
|
|
ASSERT_TRUE(manager.addWater(cellPosition, cellSize, 0.0f));
|
|
|
|
|
manager.addWater(cellPosition, cellSize, 0.0f);
|
|
|
|
|
for (int x = -6; x < 6; ++x)
|
|
|
|
|
for (int y = -6; y < 6; ++y)
|
|
|
|
|
ASSERT_EQ(manager.getMesh("worldspace", TilePosition(x, y)) != nullptr, -1 <= x && x <= 0 && -1 <= y && y <= 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_absent_cell_should_return_nullopt)
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_absent_cell_should_not_add_changed_tiles)
|
|
|
|
|
{
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
EXPECT_EQ(manager.removeWater(osg::Vec2i(0, 0)), std::nullopt);
|
|
|
|
|
manager.removeWater(osg::Vec2i(0, 0));
|
|
|
|
|
EXPECT_THAT(manager.takeChangedTiles(), ElementsAre());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_return_removed_water)
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_add_changed_tiles)
|
|
|
|
|
{
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const osg::Vec2i cellPosition(0, 0);
|
|
|
|
|
const int cellSize = 8192;
|
|
|
|
|
ASSERT_TRUE(manager.addWater(cellPosition, cellSize, 0.0f));
|
|
|
|
|
const auto result = manager.removeWater(cellPosition);
|
|
|
|
|
ASSERT_TRUE(result.has_value());
|
|
|
|
|
EXPECT_EQ(result->mCellSize, cellSize);
|
|
|
|
|
manager.addWater(cellPosition, cellSize, 0.0f);
|
|
|
|
|
manager.takeChangedTiles();
|
|
|
|
|
manager.removeWater(cellPosition);
|
|
|
|
|
const auto changedTiles = manager.takeChangedTiles();
|
|
|
|
|
EXPECT_EQ(changedTiles.begin()->first, TilePosition(-1, -1));
|
|
|
|
|
EXPECT_EQ(changedTiles.rbegin()->first, TilePosition(11, 11));
|
|
|
|
|
for (const auto& [k, v] : changedTiles)
|
|
|
|
|
EXPECT_EQ(v, ChangeType::remove) << k;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_remove_empty_tiles)
|
|
|
|
@ -361,8 +375,8 @@ namespace
|
|
|
|
|
manager.setWorldspace("worldspace");
|
|
|
|
|
const osg::Vec2i cellPosition(0, 0);
|
|
|
|
|
const int cellSize = 8192;
|
|
|
|
|
ASSERT_TRUE(manager.addWater(cellPosition, cellSize, 0.0f));
|
|
|
|
|
ASSERT_TRUE(manager.removeWater(cellPosition));
|
|
|
|
|
manager.addWater(cellPosition, cellSize, 0.0f);
|
|
|
|
|
manager.removeWater(cellPosition);
|
|
|
|
|
for (int x = -6; x < 6; ++x)
|
|
|
|
|
for (int y = -6; y < 6; ++y)
|
|
|
|
|
ASSERT_EQ(manager.getMesh("worldspace", TilePosition(x, y)), nullptr);
|
|
|
|
@ -374,11 +388,11 @@ namespace
|
|
|
|
|
manager.setWorldspace("worldspace");
|
|
|
|
|
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, [] (auto) {}));
|
|
|
|
|
ASSERT_TRUE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground));
|
|
|
|
|
const osg::Vec2i cellPosition(0, 0);
|
|
|
|
|
const int cellSize = 8192;
|
|
|
|
|
ASSERT_TRUE(manager.addWater(cellPosition, cellSize, 0.0f));
|
|
|
|
|
ASSERT_TRUE(manager.removeWater(cellPosition));
|
|
|
|
|
manager.addWater(cellPosition, cellSize, 0.0f);
|
|
|
|
|
manager.removeWater(cellPosition);
|
|
|
|
|
for (int x = -6; x < 6; ++x)
|
|
|
|
|
for (int y = -6; y < 6; ++y)
|
|
|
|
|
ASSERT_EQ(manager.getMesh("worldspace", TilePosition(x, y)) != nullptr, -1 <= x && x <= 0 && -1 <= y && y <= 0);
|
|
|
|
@ -392,9 +406,9 @@ namespace
|
|
|
|
|
const int cellSize = 8192;
|
|
|
|
|
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, [] (auto) {}));
|
|
|
|
|
ASSERT_TRUE(manager.addWater(cellPosition, cellSize, 0.0f));
|
|
|
|
|
ASSERT_TRUE(manager.removeObject(ObjectId(&boxShape)));
|
|
|
|
|
ASSERT_TRUE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground));
|
|
|
|
|
manager.addWater(cellPosition, cellSize, 0.0f);
|
|
|
|
|
manager.removeObject(ObjectId(&boxShape));
|
|
|
|
|
for (int x = -1; x < 12; ++x)
|
|
|
|
|
for (int y = -1; y < 12; ++y)
|
|
|
|
|
ASSERT_NE(manager.getMesh("worldspace", TilePosition(x, y)), nullptr);
|
|
|
|
@ -406,14 +420,14 @@ namespace
|
|
|
|
|
manager.setWorldspace("worldspace");
|
|
|
|
|
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, [] (auto) {}));
|
|
|
|
|
ASSERT_TRUE(manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground));
|
|
|
|
|
manager.setWorldspace("other");
|
|
|
|
|
for (int x = -1; x < 1; ++x)
|
|
|
|
|
for (int y = -1; y < 1; ++y)
|
|
|
|
|
ASSERT_EQ(manager.getMesh("other", TilePosition(x, y)), nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_bounds_should_return_changed_tiles)
|
|
|
|
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_bounds_should_add_changed_tiles)
|
|
|
|
|
{
|
|
|
|
|
TileCachedRecastMeshManager manager(mSettings);
|
|
|
|
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
|
|
|
@ -422,10 +436,12 @@ namespace
|
|
|
|
|
bounds.mMin = osg::Vec2f(182, 0);
|
|
|
|
|
bounds.mMax = osg::Vec2f(1000, 1000);
|
|
|
|
|
manager.setBounds(bounds);
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, [] (auto) {});
|
|
|
|
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground);
|
|
|
|
|
bounds.mMin = osg::Vec2f(-1000, -1000);
|
|
|
|
|
bounds.mMax = osg::Vec2f(0, -182);
|
|
|
|
|
EXPECT_THAT(manager.setBounds(bounds), ElementsAre(
|
|
|
|
|
manager.takeChangedTiles();
|
|
|
|
|
manager.setBounds(bounds);
|
|
|
|
|
EXPECT_THAT(manager.takeChangedTiles(), ElementsAre(
|
|
|
|
|
std::pair(TilePosition(-1, -1), ChangeType::add),
|
|
|
|
|
std::pair(TilePosition(0, 0), ChangeType::remove)
|
|
|
|
|
));
|
|
|
|
|