2018-03-13 22:49:08 +00:00
|
|
|
#include "cachedrecastmeshmanager.hpp"
|
|
|
|
#include "debug.hpp"
|
|
|
|
|
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
2021-11-05 19:47:11 +00:00
|
|
|
CachedRecastMeshManager::CachedRecastMeshManager(const TileBounds& bounds, std::size_t generation)
|
|
|
|
: mImpl(bounds, generation)
|
2018-07-12 08:44:11 +00:00
|
|
|
{}
|
2018-04-02 21:04:19 +00:00
|
|
|
|
2021-08-01 00:13:55 +00:00
|
|
|
bool CachedRecastMeshManager::addObject(const ObjectId id, const CollisionShape& shape,
|
2018-07-18 19:09:50 +00:00
|
|
|
const btTransform& transform, const AreaType areaType)
|
2018-03-13 22:49:08 +00:00
|
|
|
{
|
2018-07-18 19:09:50 +00:00
|
|
|
if (!mImpl.addObject(id, shape, transform, areaType))
|
2018-04-02 21:04:19 +00:00
|
|
|
return false;
|
2021-10-09 16:36:37 +00:00
|
|
|
mOutdatedCache = true;
|
2018-04-02 21:04:19 +00:00
|
|
|
return true;
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
2018-09-22 15:36:57 +00:00
|
|
|
bool CachedRecastMeshManager::updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType)
|
2018-05-26 14:44:25 +00:00
|
|
|
{
|
2018-07-18 19:09:50 +00:00
|
|
|
if (!mImpl.updateObject(id, transform, areaType))
|
2018-05-26 14:44:25 +00:00
|
|
|
return false;
|
2021-10-09 16:36:37 +00:00
|
|
|
mOutdatedCache = true;
|
2018-05-26 14:44:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-24 22:33:41 +00:00
|
|
|
std::optional<RemovedRecastMeshObject> CachedRecastMeshManager::removeObject(const ObjectId id)
|
2018-03-13 22:49:08 +00:00
|
|
|
{
|
2021-08-29 18:13:32 +00:00
|
|
|
auto object = mImpl.removeObject(id);
|
2018-04-01 00:44:16 +00:00
|
|
|
if (object)
|
2021-10-09 16:36:37 +00:00
|
|
|
mOutdatedCache = true;
|
2018-04-01 00:44:16 +00:00
|
|
|
return object;
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 01:48:32 +00:00
|
|
|
bool CachedRecastMeshManager::addWater(const osg::Vec2i& cellPosition, int cellSize, float level)
|
2018-07-20 19:11:34 +00:00
|
|
|
{
|
2021-11-04 01:48:32 +00:00
|
|
|
if (!mImpl.addWater(cellPosition, cellSize, level))
|
2018-07-20 19:11:34 +00:00
|
|
|
return false;
|
2021-10-09 16:36:37 +00:00
|
|
|
mOutdatedCache = true;
|
2018-07-20 19:11:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-04 01:48:32 +00:00
|
|
|
std::optional<Water> CachedRecastMeshManager::removeWater(const osg::Vec2i& cellPosition)
|
2018-07-20 19:11:34 +00:00
|
|
|
{
|
|
|
|
const auto water = mImpl.removeWater(cellPosition);
|
|
|
|
if (water)
|
2021-10-09 16:36:37 +00:00
|
|
|
mOutdatedCache = true;
|
2018-07-20 19:11:34 +00:00
|
|
|
return water;
|
|
|
|
}
|
|
|
|
|
2021-07-14 18:57:52 +00:00
|
|
|
bool CachedRecastMeshManager::addHeightfield(const osg::Vec2i& cellPosition, int cellSize,
|
2021-11-04 02:19:41 +00:00
|
|
|
const HeightfieldShape& shape)
|
2021-07-14 18:57:52 +00:00
|
|
|
{
|
2021-11-04 02:19:41 +00:00
|
|
|
if (!mImpl.addHeightfield(cellPosition, cellSize, shape))
|
2021-07-14 18:57:52 +00:00
|
|
|
return false;
|
2021-10-09 16:36:37 +00:00
|
|
|
mOutdatedCache = true;
|
2021-07-14 18:57:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-04 02:19:41 +00:00
|
|
|
std::optional<SizedHeightfieldShape> CachedRecastMeshManager::removeHeightfield(const osg::Vec2i& cellPosition)
|
2021-07-14 18:57:52 +00:00
|
|
|
{
|
2021-11-04 02:19:41 +00:00
|
|
|
const auto heightfield = mImpl.removeHeightfield(cellPosition);
|
|
|
|
if (heightfield)
|
2021-10-09 16:36:37 +00:00
|
|
|
mOutdatedCache = true;
|
2021-11-04 02:19:41 +00:00
|
|
|
return heightfield;
|
2021-07-14 18:57:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 22:49:08 +00:00
|
|
|
std::shared_ptr<RecastMesh> CachedRecastMeshManager::getMesh()
|
|
|
|
{
|
2021-10-09 16:36:37 +00:00
|
|
|
bool outdated = true;
|
|
|
|
if (!mOutdatedCache.compare_exchange_strong(outdated, false))
|
|
|
|
{
|
|
|
|
std::shared_ptr<RecastMesh> cached = getCachedMesh();
|
|
|
|
if (cached != nullptr)
|
|
|
|
return cached;
|
|
|
|
}
|
|
|
|
std::shared_ptr<RecastMesh> mesh = mImpl.getMesh();
|
|
|
|
*mCached.lock() = mesh;
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<RecastMesh> CachedRecastMeshManager::getCachedMesh() const
|
|
|
|
{
|
|
|
|
return *mCached.lockConst();
|
2018-04-02 21:04:19 +00:00
|
|
|
}
|
2018-04-15 22:07:18 +00:00
|
|
|
|
2021-06-29 01:49:21 +00:00
|
|
|
std::shared_ptr<RecastMesh> CachedRecastMeshManager::getNewMesh() const
|
|
|
|
{
|
|
|
|
return mImpl.getMesh();
|
|
|
|
}
|
|
|
|
|
2018-04-15 22:07:18 +00:00
|
|
|
bool CachedRecastMeshManager::isEmpty() const
|
|
|
|
{
|
|
|
|
return mImpl.isEmpty();
|
|
|
|
}
|
2021-04-18 14:51:52 +00:00
|
|
|
|
2021-06-25 19:52:02 +00:00
|
|
|
void CachedRecastMeshManager::reportNavMeshChange(const Version& recastMeshVersion, const Version& navMeshVersion)
|
2021-04-18 14:51:52 +00:00
|
|
|
{
|
|
|
|
mImpl.reportNavMeshChange(recastMeshVersion, navMeshVersion);
|
|
|
|
}
|
2021-05-26 23:09:58 +00:00
|
|
|
|
|
|
|
Version CachedRecastMeshManager::getVersion() const
|
|
|
|
{
|
|
|
|
return mImpl.getVersion();
|
|
|
|
}
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|