2018-03-13 22:49:08 +00:00
|
|
|
#include "cachedrecastmeshmanager.hpp"
|
|
|
|
#include "debug.hpp"
|
|
|
|
|
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
2019-11-27 22:45:01 +00:00
|
|
|
CachedRecastMeshManager::CachedRecastMeshManager(const Settings& settings, const TileBounds& bounds,
|
|
|
|
std::size_t generation)
|
|
|
|
: mImpl(settings, bounds, generation)
|
2018-07-12 08:44:11 +00:00
|
|
|
{}
|
2018-04-02 21:04:19 +00:00
|
|
|
|
2021-07-31 23:27:41 +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-08-01 00:43:36 +00:00
|
|
|
mCached.lock()->reset();
|
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-08-01 00:43:36 +00:00
|
|
|
mCached.lock()->reset();
|
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
|
|
|
{
|
2018-04-01 00:44:16 +00:00
|
|
|
const auto object = mImpl.removeObject(id);
|
|
|
|
if (object)
|
2021-08-01 00:43:36 +00:00
|
|
|
mCached.lock()->reset();
|
2018-04-01 00:44:16 +00:00
|
|
|
return object;
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 19:11:34 +00:00
|
|
|
bool CachedRecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize,
|
|
|
|
const btTransform& transform)
|
|
|
|
{
|
|
|
|
if (!mImpl.addWater(cellPosition, cellSize, transform))
|
|
|
|
return false;
|
2021-08-01 00:43:36 +00:00
|
|
|
mCached.lock()->reset();
|
2018-07-20 19:11:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-24 22:33:41 +00:00
|
|
|
std::optional<RecastMeshManager::Water> CachedRecastMeshManager::removeWater(const osg::Vec2i& cellPosition)
|
2018-07-20 19:11:34 +00:00
|
|
|
{
|
|
|
|
const auto water = mImpl.removeWater(cellPosition);
|
|
|
|
if (water)
|
2021-08-01 00:43:36 +00:00
|
|
|
mCached.lock()->reset();
|
2018-07-20 19:11:34 +00:00
|
|
|
return water;
|
|
|
|
}
|
|
|
|
|
2018-03-13 22:49:08 +00:00
|
|
|
std::shared_ptr<RecastMesh> CachedRecastMeshManager::getMesh()
|
|
|
|
{
|
2021-08-01 00:43:36 +00:00
|
|
|
std::shared_ptr<RecastMesh> cached = *mCached.lock();
|
|
|
|
if (cached != nullptr)
|
|
|
|
return cached;
|
|
|
|
cached = mImpl.getMesh();
|
|
|
|
*mCached.lock() = cached;
|
|
|
|
return cached;
|
2018-04-02 21:04:19 +00:00
|
|
|
}
|
2018-04-15 22:07:18 +00:00
|
|
|
|
|
|
|
bool CachedRecastMeshManager::isEmpty() const
|
|
|
|
{
|
|
|
|
return mImpl.isEmpty();
|
|
|
|
}
|
2021-04-18 14:51:52 +00:00
|
|
|
|
|
|
|
void CachedRecastMeshManager::reportNavMeshChange(Version recastMeshVersion, Version navMeshVersion)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|