1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-16 16:10:58 +00:00
OpenMW/components/detournavigator/navigatorimpl.hpp

117 lines
4.2 KiB
C++
Raw Normal View History

2019-02-16 12:27:02 +00:00
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_NAVIGATORIMPL_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_NAVIGATORIMPL_H
#include "navigator.hpp"
#include "navmeshmanager.hpp"
#include <memory>
2022-09-22 18:26:05 +00:00
#include <set>
2019-02-16 12:27:02 +00:00
namespace DetourNavigator
{
class NavigatorImpl final : public Navigator
{
public:
/**
* @brief Navigator constructor initializes all internal data. Constructed object is ready to build a scene.
* @param settings allows to customize navigator work. Constructor is only place to set navigator settings.
*/
explicit NavigatorImpl(const Settings& settings, std::unique_ptr<NavMeshDb>&& db);
2019-02-16 12:27:02 +00:00
std::unique_ptr<const DetourNavigator::UpdateGuard> makeUpdateGuard() override
{
return std::make_unique<const UpdateGuard>(*this);
}
void addAgent(const AgentBounds& agentBounds) override;
2019-02-16 12:27:02 +00:00
void removeAgent(const AgentBounds& agentBounds) override;
2019-02-16 12:27:02 +00:00
void setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) override;
void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard) override;
void addObject(const ObjectId id, const ObjectShapes& shapes, const btTransform& transform,
const UpdateGuard* guard) override;
2019-02-16 12:27:02 +00:00
void addObject(const ObjectId id, const DoorShapes& shapes, const btTransform& transform,
const UpdateGuard* guard) override;
2019-02-16 12:27:02 +00:00
void updateObject(const ObjectId id, const ObjectShapes& shapes, const btTransform& transform,
const UpdateGuard* guard) override;
2019-02-16 12:27:02 +00:00
void updateObject(const ObjectId id, const DoorShapes& shapes, const btTransform& transform,
const UpdateGuard* guard) override;
2019-02-16 12:27:02 +00:00
void removeObject(const ObjectId id, const UpdateGuard* guard) override;
2019-02-16 12:27:02 +00:00
void addWater(const osg::Vec2i& cellPosition, int cellSize, float level, const UpdateGuard* guard) override;
2019-02-16 12:27:02 +00:00
void removeWater(const osg::Vec2i& cellPosition, const UpdateGuard* guard) override;
2019-02-16 12:27:02 +00:00
void addHeightfield(const osg::Vec2i& cellPosition, int cellSize, const HeightfieldShape& shape,
const UpdateGuard* guard) override;
void removeHeightfield(const osg::Vec2i& cellPosition, const UpdateGuard* guard) override;
void addPathgrid(const ESM::Cell& cell, const ESM::Pathgrid& pathgrid) override;
void removePathgrid(const ESM::Pathgrid& pathgrid) override;
void update(const osg::Vec3f& playerPosition, const UpdateGuard* guard) override;
2019-02-16 12:27:02 +00:00
void wait(WaitConditionType waitConditionType, Loading::Listener* listener) override;
2019-02-16 12:27:02 +00:00
SharedNavMeshCacheItem getNavMesh(const AgentBounds& agentBounds) const override;
2019-02-16 12:27:02 +00:00
std::map<AgentBounds, SharedNavMeshCacheItem> getNavMeshes() const override;
2019-02-16 12:27:02 +00:00
const Settings& getSettings() const override;
2019-02-16 12:27:02 +00:00
Stats getStats() const override;
2019-03-17 17:18:53 +00:00
RecastMeshTiles getRecastMeshTiles() const override;
2019-11-27 22:45:01 +00:00
float getMaxNavmeshAreaRealRadius() const override;
2019-02-16 12:27:02 +00:00
private:
Settings mSettings;
NavMeshManager mNavMeshManager;
std::optional<TilePosition> mLastPlayerPosition;
std::map<AgentBounds, std::size_t> mAgents;
2019-02-16 12:27:02 +00:00
std::unordered_map<ObjectId, ObjectId> mAvoidIds;
std::unordered_map<ObjectId, ObjectId> mWaterIds;
2022-09-22 18:26:05 +00:00
inline bool addObjectImpl(
const ObjectId id, const ObjectShapes& shapes, const btTransform& transform, const UpdateGuard* guard);
inline void updateAvoidShapeId(const ObjectId id, const ObjectId avoidId, const UpdateGuard* guard);
inline void updateId(const ObjectId id, const ObjectId waterId, std::unordered_map<ObjectId, ObjectId>& ids,
const UpdateGuard* guard);
inline void removeUnusedNavMeshes();
friend class UpdateGuard;
};
class UpdateGuard
{
public:
2022-09-22 18:26:05 +00:00
explicit UpdateGuard(NavigatorImpl& navigator)
: mImpl(navigator.mNavMeshManager)
{
}
private:
NavMeshManager::UpdateGuard mImpl;
friend inline const NavMeshManager::UpdateGuard* getImpl(const UpdateGuard* guard)
{
return guard == nullptr ? nullptr : &guard->mImpl;
}
2019-02-16 12:27:02 +00:00
};
}
#endif