1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 03:35:27 +00:00
OpenMW/components/detournavigator/cachedrecastmeshmanager.cpp

104 lines
3.1 KiB
C++
Raw Normal View History

2018-03-14 01:49:08 +03:00
#include "cachedrecastmeshmanager.hpp"
#include "debug.hpp"
namespace DetourNavigator
{
2019-11-27 23:45:01 +01:00
CachedRecastMeshManager::CachedRecastMeshManager(const Settings& settings, const TileBounds& bounds,
std::size_t generation)
: mImpl(settings, bounds, generation)
2018-07-12 11:44:11 +03:00
{}
2018-04-03 00:04:19 +03:00
bool CachedRecastMeshManager::addObject(const ObjectId id, const CollisionShape& shape,
2018-07-18 22:09:50 +03:00
const btTransform& transform, const AreaType areaType)
2018-03-14 01:49:08 +03:00
{
2018-07-18 22:09:50 +03:00
if (!mImpl.addObject(id, shape, transform, areaType))
2018-04-03 00:04:19 +03:00
return false;
mOutdatedCache = true;
2018-04-03 00:04:19 +03:00
return true;
2018-03-14 01:49:08 +03:00
}
2018-09-22 18:36:57 +03:00
bool CachedRecastMeshManager::updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType)
2018-05-26 17:44:25 +03:00
{
2018-07-18 22:09:50 +03:00
if (!mImpl.updateObject(id, transform, areaType))
2018-05-26 17:44:25 +03:00
return false;
mOutdatedCache = true;
2018-05-26 17:44:25 +03:00
return true;
}
std::optional<RemovedRecastMeshObject> CachedRecastMeshManager::removeObject(const ObjectId id)
2018-03-14 01:49:08 +03:00
{
auto object = mImpl.removeObject(id);
if (object)
mOutdatedCache = true;
return object;
2018-03-14 01:49:08 +03:00
}
2018-07-20 22:11:34 +03:00
bool CachedRecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize,
const osg::Vec3f& shift)
2018-07-20 22:11:34 +03:00
{
if (!mImpl.addWater(cellPosition, cellSize, shift))
2018-07-20 22:11:34 +03:00
return false;
mOutdatedCache = true;
2018-07-20 22:11:34 +03:00
return true;
}
2021-07-14 22:00:16 +02:00
std::optional<Cell> CachedRecastMeshManager::removeWater(const osg::Vec2i& cellPosition)
2018-07-20 22:11:34 +03:00
{
const auto water = mImpl.removeWater(cellPosition);
if (water)
mOutdatedCache = true;
2018-07-20 22:11:34 +03:00
return water;
}
bool CachedRecastMeshManager::addHeightfield(const osg::Vec2i& cellPosition, int cellSize,
const osg::Vec3f& shift, const HeightfieldShape& shape)
{
if (!mImpl.addHeightfield(cellPosition, cellSize, shift, shape))
return false;
mOutdatedCache = true;
return true;
}
std::optional<Cell> CachedRecastMeshManager::removeHeightfield(const osg::Vec2i& cellPosition)
{
const auto cell = mImpl.removeHeightfield(cellPosition);
if (cell)
mOutdatedCache = true;
return cell;
}
2018-03-14 01:49:08 +03:00
std::shared_ptr<RecastMesh> CachedRecastMeshManager::getMesh()
{
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-03 00:04:19 +03:00
}
2018-04-16 01:07:18 +03:00
bool CachedRecastMeshManager::isEmpty() const
{
return mImpl.isEmpty();
}
2021-06-25 21:52:02 +02:00
void CachedRecastMeshManager::reportNavMeshChange(const Version& recastMeshVersion, const Version& navMeshVersion)
{
mImpl.reportNavMeshChange(recastMeshVersion, navMeshVersion);
}
Version CachedRecastMeshManager::getVersion() const
{
return mImpl.getVersion();
}
2018-03-14 01:49:08 +03:00
}