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.
371 lines
17 KiB
C++
371 lines
17 KiB
C++
4 years ago
|
#include "generate.hpp"
|
||
6 years ago
|
|
||
2 years ago
|
#include <components/detournavigator/navmeshtilescache.hpp>
|
||
4 years ago
|
#include <components/detournavigator/preparednavmeshdata.hpp>
|
||
3 years ago
|
#include <components/detournavigator/recast.hpp>
|
||
2 years ago
|
#include <components/detournavigator/recastmesh.hpp>
|
||
4 years ago
|
|
||
4 years ago
|
#include <osg/Vec3f>
|
||
6 years ago
|
|
||
4 years ago
|
#include <RecastAlloc.h>
|
||
6 years ago
|
|
||
|
#include <gtest/gtest.h>
|
||
|
|
||
4 years ago
|
#include <random>
|
||
|
#include <stdexcept>
|
||
6 years ago
|
|
||
|
namespace
|
||
|
{
|
||
|
using namespace testing;
|
||
|
using namespace DetourNavigator;
|
||
4 years ago
|
using namespace DetourNavigator::Tests;
|
||
6 years ago
|
|
||
4 years ago
|
template <class T, class Random>
|
||
|
void generateRecastArray(T*& values, int size, Random& random)
|
||
4 years ago
|
{
|
||
|
values = static_cast<T*>(permRecastAlloc(size * sizeof(T)));
|
||
4 years ago
|
generateRange(values, values + static_cast<std::ptrdiff_t>(size), random);
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
template <class Random>
|
||
|
void generate(rcPolyMesh& value, int size, Random& random)
|
||
4 years ago
|
{
|
||
|
value.nverts = size;
|
||
|
value.maxpolys = size;
|
||
|
value.nvp = size;
|
||
|
value.npolys = size;
|
||
|
rcVcopy(value.bmin, osg::Vec3f(-1, -2, -3).ptr());
|
||
|
rcVcopy(value.bmax, osg::Vec3f(3, 2, 1).ptr());
|
||
4 years ago
|
generateValue(value.cs, random);
|
||
|
generateValue(value.ch, random);
|
||
|
generateValue(value.borderSize, random);
|
||
|
generateValue(value.maxEdgeError, random);
|
||
|
generateRecastArray(value.verts, getVertsLength(value), random);
|
||
|
generateRecastArray(value.polys, getPolysLength(value), random);
|
||
|
generateRecastArray(value.regs, getRegsLength(value), random);
|
||
|
generateRecastArray(value.flags, getFlagsLength(value), random);
|
||
|
generateRecastArray(value.areas, getAreasLength(value), random);
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
template <class Random>
|
||
|
void generate(rcPolyMeshDetail& value, int size, Random& random)
|
||
4 years ago
|
{
|
||
|
value.nmeshes = size;
|
||
|
value.nverts = size;
|
||
|
value.ntris = size;
|
||
4 years ago
|
generateRecastArray(value.meshes, getMeshesLength(value), random);
|
||
|
generateRecastArray(value.verts, getVertsLength(value), random);
|
||
|
generateRecastArray(value.tris, getTrisLength(value), random);
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
template <class Random>
|
||
|
void generate(PreparedNavMeshData& value, int size, Random& random)
|
||
4 years ago
|
{
|
||
4 years ago
|
generateValue(value.mUserId, random);
|
||
|
generateValue(value.mCellHeight, random);
|
||
|
generateValue(value.mCellSize, random);
|
||
|
generate(value.mPolyMesh, size, random);
|
||
|
generate(value.mPolyMeshDetail, size, random);
|
||
4 years ago
|
}
|
||
|
|
||
|
std::unique_ptr<PreparedNavMeshData> makePeparedNavMeshData(int size)
|
||
|
{
|
||
4 years ago
|
std::minstd_rand random;
|
||
4 years ago
|
auto result = std::make_unique<PreparedNavMeshData>();
|
||
4 years ago
|
generate(*result, size, random);
|
||
4 years ago
|
return result;
|
||
|
}
|
||
|
|
||
|
std::unique_ptr<PreparedNavMeshData> clone(const PreparedNavMeshData& value)
|
||
|
{
|
||
3 years ago
|
return std::make_unique<PreparedNavMeshData>(value);
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
Mesh makeMesh()
|
||
|
{
|
||
2 years ago
|
std::vector<int> indices{ { 0, 1, 2 } };
|
||
|
std::vector<float> vertices{ { 0, 0, 0, 1, 0, 0, 1, 1, 0 } };
|
||
|
std::vector<AreaType> areaTypes{ 1, AreaType_ground };
|
||
4 years ago
|
return Mesh(std::move(indices), std::move(vertices), std::move(areaTypes));
|
||
|
}
|
||
|
|
||
6 years ago
|
struct DetourNavigatorNavMeshTilesCacheTest : Test
|
||
|
{
|
||
2 years ago
|
const AgentBounds mAgentBounds{ CollisionShapeType::Aabb, { 1, 2, 3 } };
|
||
|
const TilePosition mTilePosition{ 0, 0 };
|
||
|
const Version mVersion{ 0, 0 };
|
||
|
const Mesh mMesh{ makeMesh() };
|
||
|
const std::vector<CellWater> mWater{};
|
||
|
const std::vector<Heightfield> mHeightfields{};
|
||
|
const std::vector<FlatHeightfield> mFlatHeightfields{};
|
||
|
const std::vector<MeshSource> mSources{};
|
||
|
const RecastMesh mRecastMesh{ mVersion, mMesh, mWater, mHeightfields, mFlatHeightfields, mSources };
|
||
|
std::unique_ptr<PreparedNavMeshData> mPreparedNavMeshData{ makePeparedNavMeshData(3) };
|
||
6 years ago
|
|
||
4 years ago
|
const std::size_t mRecastMeshSize = sizeof(mRecastMesh) + getSize(mRecastMesh);
|
||
3 years ago
|
const std::size_t mRecastMeshWithWaterSize = mRecastMeshSize + sizeof(CellWater);
|
||
4 years ago
|
const std::size_t mPreparedNavMeshDataSize = sizeof(*mPreparedNavMeshData) + getSize(*mPreparedNavMeshData);
|
||
6 years ago
|
};
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, get_for_empty_cache_should_return_empty_value)
|
||
|
{
|
||
|
const std::size_t maxSize = 0;
|
||
|
NavMeshTilesCache cache(maxSize);
|
||
|
|
||
3 years ago
|
EXPECT_FALSE(cache.get(mAgentBounds, mTilePosition, mRecastMesh));
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, set_for_not_enought_cache_size_should_return_empty_value)
|
||
|
{
|
||
|
const std::size_t maxSize = 0;
|
||
|
NavMeshTilesCache cache(maxSize);
|
||
|
|
||
3 years ago
|
EXPECT_FALSE(cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData)));
|
||
4 years ago
|
EXPECT_NE(mPreparedNavMeshData, nullptr);
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, set_should_return_cached_value)
|
||
|
{
|
||
4 years ago
|
const std::size_t maxSize = mRecastMeshSize + mPreparedNavMeshDataSize;
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
4 years ago
|
const auto copy = clone(*mPreparedNavMeshData);
|
||
|
ASSERT_EQ(*mPreparedNavMeshData, *copy);
|
||
6 years ago
|
|
||
3 years ago
|
const auto result = cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
6 years ago
|
ASSERT_TRUE(result);
|
||
4 years ago
|
EXPECT_EQ(result.get(), *copy);
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, set_existing_element_should_return_cached_element)
|
||
6 years ago
|
{
|
||
4 years ago
|
const std::size_t maxSize = 2 * (mRecastMeshSize + mPreparedNavMeshDataSize);
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
4 years ago
|
auto copy = clone(*mPreparedNavMeshData);
|
||
|
const auto sameCopy = clone(*mPreparedNavMeshData);
|
||
6 years ago
|
|
||
3 years ago
|
cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
4 years ago
|
EXPECT_EQ(mPreparedNavMeshData, nullptr);
|
||
3 years ago
|
const auto result = cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(copy));
|
||
4 years ago
|
ASSERT_TRUE(result);
|
||
4 years ago
|
EXPECT_EQ(result.get(), *sameCopy);
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, get_should_return_cached_value)
|
||
|
{
|
||
4 years ago
|
const std::size_t maxSize = mRecastMeshSize + mPreparedNavMeshDataSize;
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
4 years ago
|
const auto copy = clone(*mPreparedNavMeshData);
|
||
6 years ago
|
|
||
3 years ago
|
cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
|
const auto result = cache.get(mAgentBounds, mTilePosition, mRecastMesh);
|
||
6 years ago
|
ASSERT_TRUE(result);
|
||
4 years ago
|
EXPECT_EQ(result.get(), *copy);
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, get_for_cache_miss_by_agent_half_extents_should_return_empty_value)
|
||
|
{
|
||
|
const std::size_t maxSize = 1;
|
||
|
NavMeshTilesCache cache(maxSize);
|
||
2 years ago
|
const AgentBounds absentAgentBounds{ CollisionShapeType::Aabb, { 1, 1, 1 } };
|
||
6 years ago
|
|
||
3 years ago
|
cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
|
EXPECT_FALSE(cache.get(absentAgentBounds, mTilePosition, mRecastMesh));
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, get_for_cache_miss_by_tile_position_should_return_empty_value)
|
||
|
{
|
||
|
const std::size_t maxSize = 1;
|
||
|
NavMeshTilesCache cache(maxSize);
|
||
2 years ago
|
const TilePosition unexistentTilePosition{ 1, 1 };
|
||
6 years ago
|
|
||
3 years ago
|
cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
|
EXPECT_FALSE(cache.get(mAgentBounds, unexistentTilePosition, mRecastMesh));
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, get_for_cache_miss_by_recast_mesh_should_return_empty_value)
|
||
|
{
|
||
|
const std::size_t maxSize = 1;
|
||
|
NavMeshTilesCache cache(maxSize);
|
||
2 years ago
|
const std::vector<CellWater> water(1, CellWater{ osg::Vec2i(), Water{ 1, 0.0f } });
|
||
2 years ago
|
const RecastMesh unexistentRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
|
||
6 years ago
|
|
||
3 years ago
|
cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
|
EXPECT_FALSE(cache.get(mAgentBounds, mTilePosition, unexistentRecastMesh));
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, set_should_replace_unused_value)
|
||
|
{
|
||
4 years ago
|
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
|
|
||
2 years ago
|
const std::vector<CellWater> water(1, CellWater{ osg::Vec2i(), Water{ 1, 0.0f } });
|
||
2 years ago
|
const RecastMesh anotherRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto anotherPreparedNavMeshData = makePeparedNavMeshData(3);
|
||
|
const auto copy = clone(*anotherPreparedNavMeshData);
|
||
6 years ago
|
|
||
3 years ago
|
cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
2 years ago
|
const auto result
|
||
|
= cache.set(mAgentBounds, mTilePosition, anotherRecastMesh, std::move(anotherPreparedNavMeshData));
|
||
6 years ago
|
ASSERT_TRUE(result);
|
||
4 years ago
|
EXPECT_EQ(result.get(), *copy);
|
||
3 years ago
|
EXPECT_FALSE(cache.get(mAgentBounds, mTilePosition, mRecastMesh));
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, set_should_not_replace_used_value)
|
||
|
{
|
||
4 years ago
|
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
|
|
||
2 years ago
|
const std::vector<CellWater> water(1, CellWater{ osg::Vec2i(), Water{ 1, 0.0f } });
|
||
2 years ago
|
const RecastMesh anotherRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto anotherPreparedNavMeshData = makePeparedNavMeshData(3);
|
||
6 years ago
|
|
||
2 years ago
|
const auto value = cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
|
EXPECT_FALSE(cache.set(mAgentBounds, mTilePosition, anotherRecastMesh, std::move(anotherPreparedNavMeshData)));
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, set_should_replace_unused_least_recently_set_value)
|
||
|
{
|
||
4 years ago
|
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
4 years ago
|
const auto copy = clone(*mPreparedNavMeshData);
|
||
6 years ago
|
|
||
2 years ago
|
const std::vector<CellWater> leastRecentlySetWater(1, CellWater{ osg::Vec2i(), Water{ 1, 0.0f } });
|
||
|
const RecastMesh leastRecentlySetRecastMesh(
|
||
|
mVersion, mMesh, leastRecentlySetWater, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto leastRecentlySetData = makePeparedNavMeshData(3);
|
||
6 years ago
|
|
||
2 years ago
|
const std::vector<CellWater> mostRecentlySetWater(1, CellWater{ osg::Vec2i(), Water{ 2, 0.0f } });
|
||
|
const RecastMesh mostRecentlySetRecastMesh(
|
||
|
mVersion, mMesh, mostRecentlySetWater, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto mostRecentlySetData = makePeparedNavMeshData(3);
|
||
6 years ago
|
|
||
2 years ago
|
ASSERT_TRUE(
|
||
|
cache.set(mAgentBounds, mTilePosition, leastRecentlySetRecastMesh, std::move(leastRecentlySetData)));
|
||
|
ASSERT_TRUE(cache.set(mAgentBounds, mTilePosition, mostRecentlySetRecastMesh, std::move(mostRecentlySetData)));
|
||
6 years ago
|
|
||
2 years ago
|
const auto result = cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
4 years ago
|
EXPECT_EQ(result.get(), *copy);
|
||
6 years ago
|
|
||
3 years ago
|
EXPECT_FALSE(cache.get(mAgentBounds, mTilePosition, leastRecentlySetRecastMesh));
|
||
|
EXPECT_TRUE(cache.get(mAgentBounds, mTilePosition, mostRecentlySetRecastMesh));
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, set_should_replace_unused_least_recently_used_value)
|
||
|
{
|
||
4 years ago
|
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
|
|
||
2 years ago
|
const std::vector<CellWater> leastRecentlyUsedWater(1, CellWater{ osg::Vec2i(), Water{ 1, 0.0f } });
|
||
|
const RecastMesh leastRecentlyUsedRecastMesh(
|
||
|
mVersion, mMesh, leastRecentlyUsedWater, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto leastRecentlyUsedData = makePeparedNavMeshData(3);
|
||
|
const auto leastRecentlyUsedCopy = clone(*leastRecentlyUsedData);
|
||
6 years ago
|
|
||
2 years ago
|
const std::vector<CellWater> mostRecentlyUsedWater(1, CellWater{ osg::Vec2i(), Water{ 2, 0.0f } });
|
||
|
const RecastMesh mostRecentlyUsedRecastMesh(
|
||
|
mVersion, mMesh, mostRecentlyUsedWater, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto mostRecentlyUsedData = makePeparedNavMeshData(3);
|
||
|
const auto mostRecentlyUsedCopy = clone(*mostRecentlyUsedData);
|
||
6 years ago
|
|
||
3 years ago
|
cache.set(mAgentBounds, mTilePosition, leastRecentlyUsedRecastMesh, std::move(leastRecentlyUsedData));
|
||
|
cache.set(mAgentBounds, mTilePosition, mostRecentlyUsedRecastMesh, std::move(mostRecentlyUsedData));
|
||
6 years ago
|
|
||
|
{
|
||
3 years ago
|
const auto value = cache.get(mAgentBounds, mTilePosition, leastRecentlyUsedRecastMesh);
|
||
6 years ago
|
ASSERT_TRUE(value);
|
||
4 years ago
|
ASSERT_EQ(value.get(), *leastRecentlyUsedCopy);
|
||
6 years ago
|
}
|
||
|
|
||
|
{
|
||
3 years ago
|
const auto value = cache.get(mAgentBounds, mTilePosition, mostRecentlyUsedRecastMesh);
|
||
6 years ago
|
ASSERT_TRUE(value);
|
||
4 years ago
|
ASSERT_EQ(value.get(), *mostRecentlyUsedCopy);
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
const auto copy = clone(*mPreparedNavMeshData);
|
||
2 years ago
|
const auto result = cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
4 years ago
|
EXPECT_EQ(result.get(), *copy);
|
||
6 years ago
|
|
||
3 years ago
|
EXPECT_FALSE(cache.get(mAgentBounds, mTilePosition, leastRecentlyUsedRecastMesh));
|
||
|
EXPECT_TRUE(cache.get(mAgentBounds, mTilePosition, mostRecentlyUsedRecastMesh));
|
||
6 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest,
|
||
|
set_should_not_replace_unused_least_recently_used_value_when_item_does_not_not_fit_cache_max_size)
|
||
6 years ago
|
{
|
||
4 years ago
|
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
|
|
||
2 years ago
|
const std::vector<CellWater> water(1, CellWater{ osg::Vec2i(), Water{ 1, 0.0f } });
|
||
|
const RecastMesh tooLargeRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto tooLargeData = makePeparedNavMeshData(10);
|
||
6 years ago
|
|
||
3 years ago
|
cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
|
EXPECT_FALSE(cache.set(mAgentBounds, mTilePosition, tooLargeRecastMesh, std::move(tooLargeData)));
|
||
|
EXPECT_TRUE(cache.get(mAgentBounds, mTilePosition, mRecastMesh));
|
||
6 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest,
|
||
|
set_should_not_replace_unused_least_recently_used_value_when_item_does_not_not_fit_size_of_unused_items)
|
||
6 years ago
|
{
|
||
4 years ago
|
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
|
|
||
2 years ago
|
const std::vector<CellWater> anotherWater(1, CellWater{ osg::Vec2i(), Water{ 1, 0.0f } });
|
||
|
const RecastMesh anotherRecastMesh(mVersion, mMesh, anotherWater, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto anotherData = makePeparedNavMeshData(3);
|
||
6 years ago
|
|
||
2 years ago
|
const std::vector<CellWater> tooLargeWater(1, CellWater{ osg::Vec2i(), Water{ 2, 0.0f } });
|
||
|
const RecastMesh tooLargeRecastMesh(mVersion, mMesh, tooLargeWater, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto tooLargeData = makePeparedNavMeshData(10);
|
||
6 years ago
|
|
||
2 years ago
|
const auto value = cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
6 years ago
|
ASSERT_TRUE(value);
|
||
2 years ago
|
ASSERT_TRUE(cache.set(mAgentBounds, mTilePosition, anotherRecastMesh, std::move(anotherData)));
|
||
|
EXPECT_FALSE(cache.set(mAgentBounds, mTilePosition, tooLargeRecastMesh, std::move(tooLargeData)));
|
||
3 years ago
|
EXPECT_TRUE(cache.get(mAgentBounds, mTilePosition, mRecastMesh));
|
||
|
EXPECT_TRUE(cache.get(mAgentBounds, mTilePosition, anotherRecastMesh));
|
||
6 years ago
|
}
|
||
|
|
||
2 years ago
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest,
|
||
|
release_used_after_set_then_used_by_get_item_should_left_this_item_available)
|
||
6 years ago
|
{
|
||
4 years ago
|
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
|
|
||
2 years ago
|
const std::vector<CellWater> water(1, CellWater{ osg::Vec2i(), Water{ 1, 0.0f } });
|
||
2 years ago
|
const RecastMesh anotherRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto anotherData = makePeparedNavMeshData(3);
|
||
6 years ago
|
|
||
3 years ago
|
const auto firstCopy = cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
6 years ago
|
ASSERT_TRUE(firstCopy);
|
||
|
{
|
||
3 years ago
|
const auto secondCopy = cache.get(mAgentBounds, mTilePosition, mRecastMesh);
|
||
6 years ago
|
ASSERT_TRUE(secondCopy);
|
||
|
}
|
||
3 years ago
|
EXPECT_FALSE(cache.set(mAgentBounds, mTilePosition, anotherRecastMesh, std::move(anotherData)));
|
||
|
EXPECT_TRUE(cache.get(mAgentBounds, mTilePosition, mRecastMesh));
|
||
6 years ago
|
}
|
||
|
|
||
|
TEST_F(DetourNavigatorNavMeshTilesCacheTest, release_twice_used_item_should_left_this_item_available)
|
||
|
{
|
||
4 years ago
|
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
|
||
6 years ago
|
NavMeshTilesCache cache(maxSize);
|
||
|
|
||
2 years ago
|
const std::vector<CellWater> water(1, CellWater{ osg::Vec2i(), Water{ 1, 0.0f } });
|
||
2 years ago
|
const RecastMesh anotherRecastMesh(mVersion, mMesh, water, mHeightfields, mFlatHeightfields, mSources);
|
||
4 years ago
|
auto anotherData = makePeparedNavMeshData(3);
|
||
6 years ago
|
|
||
3 years ago
|
cache.set(mAgentBounds, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
|
||
|
const auto firstCopy = cache.get(mAgentBounds, mTilePosition, mRecastMesh);
|
||
6 years ago
|
ASSERT_TRUE(firstCopy);
|
||
|
{
|
||
3 years ago
|
const auto secondCopy = cache.get(mAgentBounds, mTilePosition, mRecastMesh);
|
||
6 years ago
|
ASSERT_TRUE(secondCopy);
|
||
|
}
|
||
3 years ago
|
EXPECT_FALSE(cache.set(mAgentBounds, mTilePosition, anotherRecastMesh, std::move(anotherData)));
|
||
|
EXPECT_TRUE(cache.get(mAgentBounds, mTilePosition, mRecastMesh));
|
||
6 years ago
|
}
|
||
|
}
|