mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
507 lines
25 KiB
C++
507 lines
25 KiB
C++
6 years ago
|
|
||
2 years ago
|
#include <components/detournavigator/debug.hpp>
|
||
6 years ago
|
#include <components/detournavigator/settingsutils.hpp>
|
||
2 years ago
|
#include <components/detournavigator/tilecachedrecastmeshmanager.hpp>
|
||
6 years ago
|
|
||
|
#include <BulletCollision/CollisionShapes/btBoxShape.h>
|
||
|
|
||
2 years ago
|
#include <osg/io_utils>
|
||
|
|
||
6 years ago
|
#include <gmock/gmock.h>
|
||
2 years ago
|
#include <gtest/gtest.h>
|
||
6 years ago
|
|
||
|
namespace
|
||
|
{
|
||
|
using namespace testing;
|
||
|
using namespace DetourNavigator;
|
||
|
|
||
|
struct DetourNavigatorTileCachedRecastMeshManagerTest : Test
|
||
|
{
|
||
3 years ago
|
RecastSettings mSettings;
|
||
2 years ago
|
const ObjectTransform mObjectTransform{ ESM::Position{ { 0, 0, 0 }, { 0, 0, 0 } }, 0.0f };
|
||
3 years ago
|
const osg::ref_ptr<const Resource::BulletShape> mShape = new Resource::BulletShape;
|
||
|
const osg::ref_ptr<const Resource::BulletShapeInstance> mInstance = new Resource::BulletShapeInstance(mShape);
|
||
7 months ago
|
const ESM::RefId mWorldspace = ESM::RefId::stringRefId("worldspace");
|
||
6 years ago
|
|
||
|
DetourNavigatorTileCachedRecastMeshManagerTest()
|
||
|
{
|
||
|
mSettings.mBorderSize = 16;
|
||
|
mSettings.mCellSize = 0.2f;
|
||
|
mSettings.mRecastScaleFactor = 0.017647058823529415f;
|
||
|
mSettings.mTileSize = 64;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_empty_should_return_nullptr)
|
||
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr);
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_revision_for_empty_should_return_zero)
|
||
|
{
|
||
|
const TileCachedRecastMeshManager manager(mSettings);
|
||
|
EXPECT_EQ(manager.getRevision(), 0);
|
||
|
}
|
||
|
|
||
6 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_for_new_object_should_return_true)
|
||
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
EXPECT_TRUE(manager.addObject(
|
||
|
ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
|
||
6 years ago
|
}
|
||
|
|
||
3 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_for_existing_object_should_return_false)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
2 years ago
|
EXPECT_FALSE(manager.addObject(
|
||
|
ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_add_tiles)
|
||
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
4 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
ASSERT_TRUE(manager.addObject(
|
||
|
ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
|
||
4 years ago
|
for (int x = -1; x < 1; ++x)
|
||
|
for (int y = -1; y < 1; ++y)
|
||
7 months ago
|
ASSERT_NE(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr);
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_return_add_changed_tiles)
|
||
3 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
const TilesPositionsRange range{
|
||
|
.mBegin = TilePosition(0, 0),
|
||
|
.mEnd = TilePosition(1, 1),
|
||
|
};
|
||
|
manager.setRange(range, nullptr);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
|
EXPECT_THAT(manager.takeChangedTiles(nullptr), ElementsAre(std::pair(TilePosition(0, 0), ChangeType::add)));
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, update_object_for_changed_object_should_add_changed_tiles)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
2 years ago
|
const btTransform transform(
|
||
|
btMatrix3x3::getIdentity(), btVector3(getTileSize(mSettings) / mSettings.mRecastScaleFactor, 0, 0));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
const TilesPositionsRange range{
|
||
|
.mBegin = TilePosition(-1, -1),
|
||
|
.mEnd = TilePosition(2, 2),
|
||
|
};
|
||
|
manager.setRange(range, nullptr);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, nullptr);
|
||
|
manager.takeChangedTiles(nullptr);
|
||
2 years ago
|
EXPECT_TRUE(
|
||
|
manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
|
||
|
EXPECT_THAT(manager.takeChangedTiles(nullptr),
|
||
|
ElementsAre(std::pair(TilePosition(-1, -1), ChangeType::add),
|
||
|
std::pair(TilePosition(-1, 0), ChangeType::add), std::pair(TilePosition(0, -1), ChangeType::update),
|
||
|
std::pair(TilePosition(0, 0), ChangeType::update), std::pair(TilePosition(1, -1), ChangeType::remove),
|
||
|
std::pair(TilePosition(1, 0), ChangeType::remove)));
|
||
6 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
|
||
|
update_object_for_not_changed_object_should_not_add_changed_tiles)
|
||
2 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
|
manager.takeChangedTiles(nullptr);
|
||
2 years ago
|
EXPECT_FALSE(
|
||
|
manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
|
||
2 years ago
|
EXPECT_THAT(manager.takeChangedTiles(nullptr), IsEmpty());
|
||
2 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_object_should_return_add_changed_tiles)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
const TilesPositionsRange range{
|
||
|
.mBegin = TilePosition(0, 0),
|
||
|
.mEnd = TilePosition(1, 1),
|
||
|
};
|
||
|
manager.setRange(range, nullptr);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
|
manager.takeChangedTiles(nullptr);
|
||
|
manager.removeObject(ObjectId(&boxShape), nullptr);
|
||
|
EXPECT_THAT(manager.takeChangedTiles(nullptr), ElementsAre(std::pair(TilePosition(0, 0), ChangeType::remove)));
|
||
6 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
|
||
|
get_mesh_after_add_object_should_return_recast_mesh_for_each_used_tile)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
6 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
7 months ago
|
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);
|
||
6 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(
|
||
|
DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_after_add_object_should_return_nullptr_for_unused_tile)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
6 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
7 months ago
|
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(1, 0)), nullptr);
|
||
6 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
|
||
|
get_mesh_for_moved_object_should_return_recast_mesh_for_each_used_tile)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
2 years ago
|
const TilesPositionsRange range{
|
||
|
.mBegin = TilePosition(-1, -1),
|
||
7 months ago
|
.mEnd = TilePosition(2, 2),
|
||
2 years ago
|
};
|
||
|
manager.setRange(range, nullptr);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
4 years ago
|
|
||
6 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
2 years ago
|
const btTransform transform(
|
||
|
btMatrix3x3::getIdentity(), btVector3(getTileSize(mSettings) / mSettings.mRecastScaleFactor, 0, 0));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
6 years ago
|
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, nullptr);
|
||
7 months ago
|
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);
|
||
6 years ago
|
|
||
2 years ago
|
manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
7 months ago
|
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);
|
||
6 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(
|
||
|
DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_moved_object_should_return_nullptr_for_unused_tile)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
4 years ago
|
|
||
6 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
2 years ago
|
const btTransform transform(
|
||
|
btMatrix3x3::getIdentity(), btVector3(getTileSize(mSettings) / mSettings.mRecastScaleFactor, 0, 0));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
6 years ago
|
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, nullptr);
|
||
7 months ago
|
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr);
|
||
|
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr);
|
||
6 years ago
|
|
||
2 years ago
|
manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
7 months ago
|
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(1, 0)), nullptr);
|
||
|
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(1, -1)), nullptr);
|
||
6 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
|
||
|
get_mesh_for_removed_object_should_return_nullptr_for_all_previously_used_tiles)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
6 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
|
manager.removeObject(ObjectId(&boxShape), nullptr);
|
||
7 months ago
|
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);
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
|
||
|
get_mesh_for_not_changed_object_after_update_should_return_recast_mesh_for_same_tiles)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
6 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
6 years ago
|
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
7 months ago
|
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);
|
||
6 years ago
|
|
||
2 years ago
|
manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
7 months ago
|
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);
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
|
||
|
get_revision_after_add_object_new_should_return_incremented_value)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const auto initialRevision = manager.getRevision();
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
6 years ago
|
EXPECT_EQ(manager.getRevision(), initialRevision + 1);
|
||
|
}
|
||
|
|
||
2 years ago
|
TEST_F(
|
||
|
DetourNavigatorTileCachedRecastMeshManagerTest, get_revision_after_add_object_existing_should_return_same_value)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
6 years ago
|
const auto beforeAddRevision = manager.getRevision();
|
||
2 years ago
|
EXPECT_FALSE(manager.addObject(
|
||
|
ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
|
||
6 years ago
|
EXPECT_EQ(manager.getRevision(), beforeAddRevision);
|
||
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
|
||
|
get_revision_after_update_moved_object_should_return_incremented_value)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
2 years ago
|
const btTransform transform(
|
||
|
btMatrix3x3::getIdentity(), btVector3(getTileSize(mSettings) / mSettings.mRecastScaleFactor, 0, 0));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, nullptr);
|
||
6 years ago
|
const auto beforeUpdateRevision = manager.getRevision();
|
||
2 years ago
|
manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
6 years ago
|
EXPECT_EQ(manager.getRevision(), beforeUpdateRevision + 1);
|
||
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
|
||
|
get_revision_after_update_not_changed_object_should_return_same_value)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
6 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
6 years ago
|
const auto beforeUpdateRevision = manager.getRevision();
|
||
2 years ago
|
manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
6 years ago
|
EXPECT_EQ(manager.getRevision(), beforeUpdateRevision);
|
||
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
|
||
|
get_revision_after_remove_existing_object_should_return_incremented_value)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
6 years ago
|
const auto beforeRemoveRevision = manager.getRevision();
|
||
2 years ago
|
manager.removeObject(ObjectId(&boxShape), nullptr);
|
||
6 years ago
|
EXPECT_EQ(manager.getRevision(), beforeRemoveRevision + 1);
|
||
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
|
||
|
get_revision_after_remove_absent_object_should_return_same_value)
|
||
6 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const auto beforeRemoveRevision = manager.getRevision();
|
||
2 years ago
|
manager.removeObject(ObjectId(&manager), nullptr);
|
||
6 years ago
|
EXPECT_EQ(manager.getRevision(), beforeRemoveRevision);
|
||
|
}
|
||
4 years ago
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_new_water_should_add_changed_tiles)
|
||
4 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const osg::Vec2i cellPosition(0, 0);
|
||
|
const int cellSize = 8192;
|
||
2 years ago
|
manager.addWater(cellPosition, cellSize, 0.0f, nullptr);
|
||
|
const auto changedTiles = manager.takeChangedTiles(nullptr);
|
||
2 years ago
|
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;
|
||
4 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_not_max_int_should_add_new_tiles)
|
||
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
4 years ago
|
const osg::Vec2i cellPosition(0, 0);
|
||
|
const int cellSize = 8192;
|
||
2 years ago
|
manager.addWater(cellPosition, cellSize, 0.0f, nullptr);
|
||
3 years ago
|
for (int x = -1; x < 12; ++x)
|
||
|
for (int y = -1; y < 12; ++y)
|
||
7 months ago
|
ASSERT_NE(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr);
|
||
4 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_max_int_should_not_add_new_tiles)
|
||
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
4 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
ASSERT_TRUE(manager.addObject(
|
||
|
ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
|
||
4 years ago
|
const osg::Vec2i cellPosition(0, 0);
|
||
|
const int cellSize = std::numeric_limits<int>::max();
|
||
2 years ago
|
manager.addWater(cellPosition, cellSize, 0.0f, nullptr);
|
||
4 years ago
|
for (int x = -6; x < 6; ++x)
|
||
|
for (int y = -6; y < 6; ++y)
|
||
7 months ago
|
ASSERT_EQ(manager.getMesh(mWorldspace, TilePosition(x, y)) != nullptr,
|
||
2 years ago
|
-1 <= x && x <= 0 && -1 <= y && y <= 0);
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_absent_cell_should_not_add_changed_tiles)
|
||
4 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
2 years ago
|
manager.removeWater(osg::Vec2i(0, 0), nullptr);
|
||
|
EXPECT_THAT(manager.takeChangedTiles(nullptr), ElementsAre());
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_add_changed_tiles)
|
||
4 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const osg::Vec2i cellPosition(0, 0);
|
||
|
const int cellSize = 8192;
|
||
2 years ago
|
manager.addWater(cellPosition, cellSize, 0.0f, nullptr);
|
||
|
manager.takeChangedTiles(nullptr);
|
||
|
manager.removeWater(cellPosition, nullptr);
|
||
|
const auto changedTiles = manager.takeChangedTiles(nullptr);
|
||
2 years ago
|
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;
|
||
4 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_remove_empty_tiles)
|
||
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
4 years ago
|
const osg::Vec2i cellPosition(0, 0);
|
||
|
const int cellSize = 8192;
|
||
2 years ago
|
manager.addWater(cellPosition, cellSize, 0.0f, nullptr);
|
||
|
manager.removeWater(cellPosition, nullptr);
|
||
4 years ago
|
for (int x = -6; x < 6; ++x)
|
||
|
for (int y = -6; y < 6; ++y)
|
||
7 months ago
|
ASSERT_EQ(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr);
|
||
4 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_leave_not_empty_tiles)
|
||
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
4 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
ASSERT_TRUE(manager.addObject(
|
||
|
ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
|
||
4 years ago
|
const osg::Vec2i cellPosition(0, 0);
|
||
|
const int cellSize = 8192;
|
||
2 years ago
|
manager.addWater(cellPosition, cellSize, 0.0f, nullptr);
|
||
|
manager.removeWater(cellPosition, nullptr);
|
||
4 years ago
|
for (int x = -6; x < 6; ++x)
|
||
|
for (int y = -6; y < 6; ++y)
|
||
7 months ago
|
ASSERT_EQ(manager.getMesh(mWorldspace, TilePosition(x, y)) != nullptr,
|
||
2 years ago
|
-1 <= x && x <= 0 && -1 <= y && y <= 0);
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_object_should_not_remove_tile_with_water)
|
||
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
4 years ago
|
const osg::Vec2i cellPosition(0, 0);
|
||
|
const int cellSize = 8192;
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
3 years ago
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
ASSERT_TRUE(manager.addObject(
|
||
|
ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
|
||
2 years ago
|
manager.addWater(cellPosition, cellSize, 0.0f, nullptr);
|
||
|
manager.removeObject(ObjectId(&boxShape), nullptr);
|
||
3 years ago
|
for (int x = -1; x < 12; ++x)
|
||
|
for (int y = -1; y < 12; ++y)
|
||
7 months ago
|
ASSERT_NE(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr);
|
||
4 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_new_worldspace_should_remove_tiles)
|
||
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
4 years ago
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
|
const CollisionShape shape(nullptr, boxShape, mObjectTransform);
|
||
2 years ago
|
ASSERT_TRUE(manager.addObject(
|
||
|
ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
|
||
7 months ago
|
const ESM::RefId otherWorldspace(ESM::FormId::fromUint32(0x1));
|
||
|
manager.setWorldspace(ESM::FormId::fromUint32(0x1), nullptr);
|
||
4 years ago
|
for (int x = -1; x < 1; ++x)
|
||
|
for (int y = -1; y < 1; ++y)
|
||
7 months ago
|
ASSERT_EQ(manager.getMesh(otherWorldspace, TilePosition(x, y)), nullptr);
|
||
4 years ago
|
}
|
||
3 years ago
|
|
||
7 months ago
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_range_should_add_changed_tiles)
|
||
3 years ago
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
const btBoxShape boxShape(btVector3(20, 20, 100));
|
||
|
const CollisionShape shape(mInstance, boxShape, mObjectTransform);
|
||
2 years ago
|
const TilesPositionsRange range1{
|
||
|
.mBegin = TilePosition(0, 0),
|
||
|
.mEnd = TilePosition(1, 1),
|
||
|
};
|
||
|
manager.setRange(range1, nullptr);
|
||
2 years ago
|
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
|
||
2 years ago
|
const TilesPositionsRange range2{
|
||
|
.mBegin = TilePosition(-1, -1),
|
||
|
.mEnd = TilePosition(0, 0),
|
||
|
};
|
||
2 years ago
|
manager.takeChangedTiles(nullptr);
|
||
2 years ago
|
manager.setRange(range2, nullptr);
|
||
2 years ago
|
EXPECT_THAT(manager.takeChangedTiles(nullptr),
|
||
|
ElementsAre(
|
||
|
std::pair(TilePosition(-1, -1), ChangeType::add), std::pair(TilePosition(0, 0), ChangeType::remove)));
|
||
3 years ago
|
}
|
||
7 months ago
|
|
||
|
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_range_should_remove_cached_recast_meshes_outside_range)
|
||
|
{
|
||
|
TileCachedRecastMeshManager manager(mSettings);
|
||
|
|
||
7 months ago
|
manager.setWorldspace(mWorldspace, nullptr);
|
||
7 months ago
|
|
||
|
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);
|
||
|
|
||
7 months ago
|
ASSERT_EQ(manager.getCachedMesh(mWorldspace, tilePosition), nullptr);
|
||
|
ASSERT_NE(manager.getMesh(mWorldspace, tilePosition), nullptr);
|
||
|
ASSERT_NE(manager.getCachedMesh(mWorldspace, tilePosition), nullptr);
|
||
7 months ago
|
|
||
|
const TilesPositionsRange range2{
|
||
|
.mBegin = TilePosition(-1, -1),
|
||
|
.mEnd = TilePosition(0, 0),
|
||
|
};
|
||
|
manager.takeChangedTiles(nullptr);
|
||
|
manager.setRange(range2, nullptr);
|
||
|
|
||
7 months ago
|
ASSERT_EQ(manager.getCachedMesh(mWorldspace, tilePosition), nullptr);
|
||
7 months ago
|
}
|
||
6 years ago
|
}
|