Rename DetourNavigator::Water -> Cell

dont-compose-content
elsid 4 years ago
parent 753767d6d9
commit 5d6c93566d
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -83,7 +83,7 @@ namespace
std::uniform_real_distribution<float> distribution(0.0, 1.0);
std::generate_n(out, count, [&] {
const osg::Vec3f shift(distribution(random), distribution(random), distribution(random));
return Water {1, shift};
return Cell {1, shift};
});
}
@ -108,7 +108,7 @@ namespace
const std::size_t generation = std::uniform_int_distribution<std::size_t>(0, 100)(random);
const std::size_t revision = std::uniform_int_distribution<std::size_t>(0, 10000)(random);
Mesh mesh = generateMesh(triangles, random);
std::vector<Water> water;
std::vector<Cell> water;
generateWater(std::back_inserter(water), 2, random);
RecastMesh recastMesh(generation, revision, std::move(mesh), std::move(water));
return Key {agentHalfExtents, tilePosition, std::move(recastMesh)};

@ -143,12 +143,12 @@ namespace
const std::size_t mGeneration = 0;
const std::size_t mRevision = 0;
const Mesh mMesh {makeMesh()};
const std::vector<Water> mWater {};
const std::vector<Cell> mWater {};
const RecastMesh mRecastMesh {mGeneration, mRevision, mMesh, mWater};
std::unique_ptr<PreparedNavMeshData> mPreparedNavMeshData {makePeparedNavMeshData(3)};
const std::size_t mRecastMeshSize = sizeof(mRecastMesh) + getSize(mRecastMesh);
const std::size_t mRecastMeshWithWaterSize = mRecastMeshSize + sizeof(Water);
const std::size_t mRecastMeshWithWaterSize = mRecastMeshSize + sizeof(Cell);
const std::size_t mPreparedNavMeshDataSize = sizeof(*mPreparedNavMeshData) + getSize(*mPreparedNavMeshData);
};
@ -231,7 +231,7 @@ namespace
{
const std::size_t maxSize = 1;
NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const std::vector<Cell> water {1, Cell {1, osg::Vec3f()}};
const RecastMesh unexistentRecastMesh {mGeneration, mRevision, mMesh, water};
cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
@ -243,7 +243,7 @@ namespace
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const std::vector<Cell> water {1, Cell {1, osg::Vec3f()}};
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water};
auto anotherPreparedNavMeshData = makePeparedNavMeshData(3);
const auto copy = clone(*anotherPreparedNavMeshData);
@ -261,7 +261,7 @@ namespace
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const std::vector<Cell> water {1, Cell {1, osg::Vec3f()}};
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water};
auto anotherPreparedNavMeshData = makePeparedNavMeshData(3);
@ -277,11 +277,11 @@ namespace
NavMeshTilesCache cache(maxSize);
const auto copy = clone(*mPreparedNavMeshData);
const std::vector<Water> leastRecentlySetWater {1, Water {1, osg::Vec3f()}};
const std::vector<Cell> leastRecentlySetWater {1, Cell {1, osg::Vec3f()}};
const RecastMesh leastRecentlySetRecastMesh {mGeneration, mRevision, mMesh, leastRecentlySetWater};
auto leastRecentlySetData = makePeparedNavMeshData(3);
const std::vector<Water> mostRecentlySetWater {1, Water {2, osg::Vec3f()}};
const std::vector<Cell> mostRecentlySetWater {1, Cell {2, osg::Vec3f()}};
const RecastMesh mostRecentlySetRecastMesh {mGeneration, mRevision, mMesh, mostRecentlySetWater};
auto mostRecentlySetData = makePeparedNavMeshData(3);
@ -303,12 +303,12 @@ namespace
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
NavMeshTilesCache cache(maxSize);
const std::vector<Water> leastRecentlyUsedWater {1, Water {1, osg::Vec3f()}};
const std::vector<Cell> leastRecentlyUsedWater {1, Cell {1, osg::Vec3f()}};
const RecastMesh leastRecentlyUsedRecastMesh {mGeneration, mRevision, mMesh, leastRecentlyUsedWater};
auto leastRecentlyUsedData = makePeparedNavMeshData(3);
const auto leastRecentlyUsedCopy = clone(*leastRecentlyUsedData);
const std::vector<Water> mostRecentlyUsedWater {1, Water {2, osg::Vec3f()}};
const std::vector<Cell> mostRecentlyUsedWater {1, Cell {2, osg::Vec3f()}};
const RecastMesh mostRecentlyUsedRecastMesh {mGeneration, mRevision, mMesh, mostRecentlyUsedWater};
auto mostRecentlyUsedData = makePeparedNavMeshData(3);
const auto mostRecentlyUsedCopy = clone(*mostRecentlyUsedData);
@ -342,7 +342,7 @@ namespace
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const std::vector<Cell> water {1, Cell {1, osg::Vec3f()}};
const RecastMesh tooLargeRecastMesh {mGeneration, mRevision, mMesh, water};
auto tooLargeData = makePeparedNavMeshData(10);
@ -356,11 +356,11 @@ namespace
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
NavMeshTilesCache cache(maxSize);
const std::vector<Water> anotherWater {1, Water {1, osg::Vec3f()}};
const std::vector<Cell> anotherWater {1, Cell {1, osg::Vec3f()}};
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, anotherWater};
auto anotherData = makePeparedNavMeshData(3);
const std::vector<Water> tooLargeWater {1, Water {2, osg::Vec3f()}};
const std::vector<Cell> tooLargeWater {1, Cell {2, osg::Vec3f()}};
const RecastMesh tooLargeRecastMesh {mGeneration, mRevision, mMesh, tooLargeWater};
auto tooLargeData = makePeparedNavMeshData(10);
@ -380,7 +380,7 @@ namespace
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const std::vector<Cell> water {1, Cell {1, osg::Vec3f()}};
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water};
auto anotherData = makePeparedNavMeshData(3);
@ -399,7 +399,7 @@ namespace
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const std::vector<Cell> water {1, Cell {1, osg::Vec3f()}};
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water};
auto anotherData = makePeparedNavMeshData(3);

@ -19,9 +19,9 @@
namespace DetourNavigator
{
static inline bool operator ==(const Water& lhs, const Water& rhs)
static inline bool operator ==(const Cell& lhs, const Cell& rhs)
{
return lhs.mCellSize == rhs.mCellSize && lhs.mShift == rhs.mShift;
return lhs.mSize == rhs.mSize && lhs.mShift == rhs.mShift;
}
}
@ -404,8 +404,8 @@ namespace
RecastMeshBuilder builder(mBounds);
builder.addWater(1000, osg::Vec3f(100, 200, 300));
const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
EXPECT_EQ(recastMesh->getWater(), std::vector<Water>({
Water {1000, osg::Vec3f(100, 200, 300)}
EXPECT_EQ(recastMesh->getWater(), std::vector<Cell>({
Cell {1000, osg::Vec3f(100, 200, 300)}
}));
}

@ -295,7 +295,7 @@ namespace
ASSERT_TRUE(manager.addWater(cellPosition, cellSize, osg::Vec3f()));
const auto result = manager.removeWater(cellPosition);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(result->mCellSize, cellSize);
EXPECT_EQ(result->mSize, cellSize);
}
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_remove_empty_tiles)

@ -42,7 +42,7 @@ namespace DetourNavigator
return true;
}
std::optional<Water> CachedRecastMeshManager::removeWater(const osg::Vec2i& cellPosition)
std::optional<Cell> CachedRecastMeshManager::removeWater(const osg::Vec2i& cellPosition)
{
const auto water = mImpl.removeWater(cellPosition);
if (water)

@ -18,7 +18,7 @@ namespace DetourNavigator
bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift);
std::optional<Water> removeWater(const osg::Vec2i& cellPosition);
std::optional<Cell> removeWater(const osg::Vec2i& cellPosition);
std::optional<RemovedRecastMeshObject> removeObject(const ObjectId id);

@ -34,10 +34,10 @@ namespace
osg::Vec3f mMax;
};
WaterBounds getWaterBounds(const Water& water, const Settings& settings,
WaterBounds getWaterBounds(const Cell& water, const Settings& settings,
const osg::Vec3f& agentHalfExtents)
{
if (water.mCellSize == std::numeric_limits<int>::max())
if (water.mSize == std::numeric_limits<int>::max())
{
const auto transform = getSwimLevelTransform(settings, water.mShift, agentHalfExtents.z());
const auto min = toNavMeshCoordinates(settings, Misc::Convert::makeOsgVec3f(transform(btVector3(-1, -1, 0))));
@ -50,7 +50,7 @@ namespace
else
{
const auto transform = getSwimLevelTransform(settings, water.mShift, agentHalfExtents.z());
const auto halfCellSize = water.mCellSize / 2.0f;
const auto halfCellSize = water.mSize / 2.0f;
return WaterBounds {
toNavMeshCoordinates(settings, Misc::Convert::makeOsgVec3f(transform(btVector3(-halfCellSize, -halfCellSize, 0)))),
toNavMeshCoordinates(settings, Misc::Convert::makeOsgVec3f(transform(btVector3(halfCellSize, halfCellSize, 0))))

@ -85,7 +85,7 @@ namespace DetourNavigator
const auto water = mRecastMeshManager.removeWater(cellPosition);
if (!water)
return false;
addChangedTiles(water->mCellSize, water->mShift, ChangeType::remove);
addChangedTiles(water->mSize, water->mShift, ChangeType::remove);
return true;
}

@ -23,7 +23,7 @@ namespace DetourNavigator
struct RecastMeshData
{
Mesh mMesh;
std::vector<Water> mWater;
std::vector<Cell> mWater;
};
inline bool operator <(const RecastMeshData& lhs, const RecastMeshData& rhs)

@ -18,7 +18,7 @@ namespace DetourNavigator
mAreaTypes = std::move(areaTypes);
}
RecastMesh::RecastMesh(std::size_t generation, std::size_t revision, Mesh mesh, std::vector<Water> water)
RecastMesh::RecastMesh(std::size_t generation, std::size_t revision, Mesh mesh, std::vector<Cell> water)
: mGeneration(generation)
, mRevision(revision)
, mMesh(std::move(mesh))

@ -45,16 +45,16 @@ namespace DetourNavigator
}
};
struct Water
struct Cell
{
int mCellSize;
int mSize;
osg::Vec3f mShift;
};
class RecastMesh
{
public:
RecastMesh(std::size_t generation, std::size_t revision, Mesh mesh, std::vector<Water> water);
RecastMesh(std::size_t generation, std::size_t revision, Mesh mesh, std::vector<Cell> water);
std::size_t getGeneration() const
{
@ -68,7 +68,7 @@ namespace DetourNavigator
const Mesh& getMesh() const noexcept { return mMesh; }
const std::vector<Water>& getWater() const
const std::vector<Cell>& getWater() const
{
return mWater;
}
@ -82,7 +82,7 @@ namespace DetourNavigator
std::size_t mGeneration;
std::size_t mRevision;
Mesh mMesh;
std::vector<Water> mWater;
std::vector<Cell> mWater;
Bounds mBounds;
friend inline bool operator <(const RecastMesh& lhs, const RecastMesh& rhs) noexcept
@ -92,13 +92,13 @@ namespace DetourNavigator
friend inline std::size_t getSize(const RecastMesh& value) noexcept
{
return getSize(value.mMesh) + value.mWater.size() * sizeof(Water);
return getSize(value.mMesh) + value.mWater.size() * sizeof(Cell);
}
};
inline bool operator<(const Water& lhs, const Water& rhs) noexcept
inline bool operator<(const Cell& lhs, const Cell& rhs) noexcept
{
return std::tie(lhs.mCellSize, lhs.mShift) < std::tie(rhs.mCellSize, rhs.mShift);
return std::tie(lhs.mSize, lhs.mShift) < std::tie(rhs.mSize, rhs.mShift);
}
}

@ -160,7 +160,7 @@ namespace DetourNavigator
void RecastMeshBuilder::addWater(const int cellSize, const osg::Vec3f& shift)
{
mWater.push_back(Water {cellSize, shift});
mWater.push_back(Cell {cellSize, shift});
}
std::shared_ptr<RecastMesh> RecastMeshBuilder::create(std::size_t generation, std::size_t revision) &&

@ -56,7 +56,7 @@ namespace DetourNavigator
private:
const TileBounds mBounds;
std::vector<RecastMeshTriangle> mTriangles;
std::vector<Water> mWater;
std::vector<Cell> mWater;
void addObject(const btConcaveShape& shape, const btTransform& transform, btTriangleCallback&& callback);

@ -49,19 +49,19 @@ namespace DetourNavigator
bool RecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift)
{
if (!mWater.emplace(cellPosition, Water {cellSize, shift}).second)
if (!mWater.emplace(cellPosition, Cell {cellSize, shift}).second)
return false;
++mRevision;
return true;
}
std::optional<Water> RecastMeshManager::removeWater(const osg::Vec2i& cellPosition)
std::optional<Cell> RecastMeshManager::removeWater(const osg::Vec2i& cellPosition)
{
const auto water = mWater.find(cellPosition);
if (water == mWater.end())
return std::nullopt;
++mRevision;
const Water result = water->second;
const Cell result = water->second;
mWater.erase(water);
return result;
}
@ -73,7 +73,7 @@ namespace DetourNavigator
tileBounds.mMax /= mSettings.mRecastScaleFactor;
RecastMeshBuilder builder(tileBounds);
for (const auto& [k, v] : mWater)
builder.addWater(v.mCellSize, v.mShift);
builder.addWater(v.mSize, v.mShift);
for (const auto& [k, object] : mObjects)
{
const RecastMeshObject& v = object.getImpl();

@ -39,7 +39,7 @@ namespace DetourNavigator
bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift);
std::optional<Water> removeWater(const osg::Vec2i& cellPosition);
std::optional<Cell> removeWater(const osg::Vec2i& cellPosition);
std::optional<RemovedRecastMeshObject> removeObject(const ObjectId id);
@ -63,7 +63,7 @@ namespace DetourNavigator
std::size_t mGeneration;
TileBounds mTileBounds;
std::map<ObjectId, OscillatingRecastMeshObject> mObjects;
std::map<osg::Vec2i, Water> mWater;
std::map<osg::Vec2i, Cell> mWater;
std::optional<Report> mLastNavMeshReportedChange;
std::optional<Report> mLastNavMeshReport;
};

@ -102,12 +102,12 @@ namespace DetourNavigator
return result;
}
std::optional<Water> TileCachedRecastMeshManager::removeWater(const osg::Vec2i& cellPosition)
std::optional<Cell> TileCachedRecastMeshManager::removeWater(const osg::Vec2i& cellPosition)
{
const auto object = mWaterTilesPositions.find(cellPosition);
if (object == mWaterTilesPositions.end())
return std::nullopt;
std::optional<Water> result;
std::optional<Cell> result;
for (const auto& tilePosition : object->second)
{
const auto tiles = mTiles.lock();

@ -78,7 +78,7 @@ namespace DetourNavigator
bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift);
std::optional<Water> removeWater(const osg::Vec2i& cellPosition);
std::optional<Cell> removeWater(const osg::Vec2i& cellPosition);
std::shared_ptr<RecastMesh> getMesh(const TilePosition& tilePosition);

Loading…
Cancel
Save