2020-01-28 21:24:51 +00:00
|
|
|
|
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_NAVIGATOR_H
|
2018-03-13 22:49:08 +00:00
|
|
|
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_NAVIGATOR_H
|
|
|
|
|
|
2024-03-16 12:07:56 +00:00
|
|
|
|
#include <cassert>
|
2022-06-19 11:28:33 +00:00
|
|
|
|
#include <filesystem>
|
2024-05-19 13:59:12 +00:00
|
|
|
|
#include <optional>
|
2022-06-19 11:28:33 +00:00
|
|
|
|
|
2024-05-19 13:59:12 +00:00
|
|
|
|
#include "cellgridbounds.hpp"
|
2021-07-14 18:57:52 +00:00
|
|
|
|
#include "heightfieldshape.hpp"
|
2019-02-16 12:27:02 +00:00
|
|
|
|
#include "objectid.hpp"
|
2022-08-11 22:09:49 +00:00
|
|
|
|
#include "objecttransform.hpp"
|
2019-11-27 22:45:01 +00:00
|
|
|
|
#include "recastmeshtiles.hpp"
|
2022-08-11 22:09:49 +00:00
|
|
|
|
#include "sharednavmeshcacheitem.hpp"
|
2023-04-20 23:45:21 +00:00
|
|
|
|
#include "updateguard.hpp"
|
2021-05-14 19:06:29 +00:00
|
|
|
|
#include "waitconditiontype.hpp"
|
2021-07-14 18:57:52 +00:00
|
|
|
|
|
2024-05-19 13:38:47 +00:00
|
|
|
|
#include <components/esm/refid.hpp>
|
2021-08-01 00:13:55 +00:00
|
|
|
|
#include <components/resource/bulletshape.hpp>
|
|
|
|
|
|
2020-06-11 21:23:30 +00:00
|
|
|
|
namespace ESM
|
|
|
|
|
{
|
|
|
|
|
struct Cell;
|
|
|
|
|
struct Pathgrid;
|
2023-02-15 22:19:51 +00:00
|
|
|
|
class RefId;
|
2020-06-11 21:23:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-05 16:13:17 +00:00
|
|
|
|
namespace Loading
|
|
|
|
|
{
|
|
|
|
|
class Listener;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-13 22:49:08 +00:00
|
|
|
|
namespace DetourNavigator
|
|
|
|
|
{
|
2021-11-05 23:34:06 +00:00
|
|
|
|
struct Settings;
|
2022-06-16 22:28:44 +00:00
|
|
|
|
struct AgentBounds;
|
2022-08-28 12:52:12 +00:00
|
|
|
|
struct Stats;
|
2021-11-05 23:34:06 +00:00
|
|
|
|
|
2018-07-12 08:44:11 +00:00
|
|
|
|
struct ObjectShapes
|
|
|
|
|
{
|
2021-08-01 00:13:55 +00:00
|
|
|
|
osg::ref_ptr<const Resource::BulletShapeInstance> mShapeInstance;
|
2021-11-04 00:57:27 +00:00
|
|
|
|
ObjectTransform mTransform;
|
2018-07-12 08:44:11 +00:00
|
|
|
|
|
2021-11-04 00:57:27 +00:00
|
|
|
|
ObjectShapes(
|
|
|
|
|
const osg::ref_ptr<const Resource::BulletShapeInstance>& shapeInstance, const ObjectTransform& transform)
|
2021-08-01 00:13:55 +00:00
|
|
|
|
: mShapeInstance(shapeInstance)
|
2021-11-04 00:57:27 +00:00
|
|
|
|
, mTransform(transform)
|
|
|
|
|
{
|
|
|
|
|
assert(mShapeInstance != nullptr);
|
|
|
|
|
}
|
2018-07-12 08:44:11 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-08-26 20:27:38 +00:00
|
|
|
|
struct DoorShapes : ObjectShapes
|
|
|
|
|
{
|
|
|
|
|
osg::Vec3f mConnectionStart;
|
|
|
|
|
osg::Vec3f mConnectionEnd;
|
|
|
|
|
|
2021-08-01 00:13:55 +00:00
|
|
|
|
DoorShapes(const osg::ref_ptr<const Resource::BulletShapeInstance>& shapeInstance,
|
2021-11-04 00:57:27 +00:00
|
|
|
|
const ObjectTransform& transform, const osg::Vec3f& connectionStart, const osg::Vec3f& connectionEnd)
|
|
|
|
|
: ObjectShapes(shapeInstance, transform)
|
2018-08-26 20:27:38 +00:00
|
|
|
|
, mConnectionStart(connectionStart)
|
|
|
|
|
, mConnectionEnd(connectionEnd)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
2019-02-16 12:27:02 +00:00
|
|
|
|
* @brief Top level interface of detournavigator component. Navigator allows to build a scene with navmesh and find
|
2018-09-29 22:20:42 +00:00
|
|
|
|
* a path for an agent there. Scene contains agents, geometry objects and water. Agent are distinguished only by
|
|
|
|
|
* half extents. Each object has unique identifier and could be added, updated or removed. Water could be added once
|
|
|
|
|
* for each world cell at given level of height. Navmesh builds asynchronously in separate threads. To start build
|
|
|
|
|
* navmesh call update method.
|
|
|
|
|
*/
|
2019-02-16 12:27:02 +00:00
|
|
|
|
struct Navigator
|
2018-03-13 22:49:08 +00:00
|
|
|
|
{
|
2019-02-16 12:27:02 +00:00
|
|
|
|
virtual ~Navigator() = default;
|
2018-03-13 22:49:08 +00:00
|
|
|
|
|
2023-04-20 23:45:21 +00:00
|
|
|
|
virtual ScopedUpdateGuard makeUpdateGuard() = 0;
|
2022-09-05 07:23:14 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief addAgent should be called for each agent even if all of them has same half extents.
|
2022-06-16 22:28:44 +00:00
|
|
|
|
* @param agentBounds allows to setup bounding cylinder for each agent, for each different half extents
|
2018-09-29 22:20:42 +00:00
|
|
|
|
* there is different navmesh.
|
2023-01-17 22:31:17 +00:00
|
|
|
|
* @return true if agent is successfully added or false if agent bounds are not supported.
|
2018-09-29 22:20:42 +00:00
|
|
|
|
*/
|
2023-01-17 22:31:17 +00:00
|
|
|
|
virtual bool addAgent(const AgentBounds& agentBounds) = 0;
|
2018-03-13 22:49:08 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief removeAgent should be called for each agent even if all of them has same half extents
|
2022-06-16 22:28:44 +00:00
|
|
|
|
* @param agentBounds allows determine which agent to remove
|
2018-09-29 22:20:42 +00:00
|
|
|
|
*/
|
2022-06-16 22:28:44 +00:00
|
|
|
|
virtual void removeAgent(const AgentBounds& agentBounds) = 0;
|
2018-03-13 22:49:08 +00:00
|
|
|
|
|
2024-05-19 13:38:47 +00:00
|
|
|
|
// Updates bounds for recast mesh and navmesh tiles, removes tiles outside the range.
|
2024-05-19 13:59:12 +00:00
|
|
|
|
virtual void updateBounds(ESM::RefId worldspace, const std::optional<CellGridBounds>& cellGridBounds,
|
|
|
|
|
const osg::Vec3f& playerPosition, const UpdateGuard* guard)
|
2024-05-19 13:38:47 +00:00
|
|
|
|
= 0;
|
2022-02-01 00:21:47 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief addObject is used to add complex object with allowed to walk and avoided to walk shapes
|
|
|
|
|
* @param id is used to distinguish different objects
|
|
|
|
|
* @param shape members must live until object is updated by another shape removed from Navigator
|
|
|
|
|
* @param transform allows to setup objects geometry according to its world state
|
|
|
|
|
*/
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void addObject(
|
|
|
|
|
const ObjectId id, const ObjectShapes& shapes, const btTransform& transform, const UpdateGuard* guard)
|
|
|
|
|
= 0;
|
2018-07-12 08:44:11 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief addObject is used to add doors.
|
|
|
|
|
* @param id is used to distinguish different objects.
|
|
|
|
|
* @param shape members must live until object is updated by another shape or removed from Navigator.
|
|
|
|
|
* @param transform allows to setup objects geometry according to its world state.
|
|
|
|
|
*/
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void addObject(
|
|
|
|
|
const ObjectId id, const DoorShapes& shapes, const btTransform& transform, const UpdateGuard* guard)
|
|
|
|
|
= 0;
|
2018-08-26 20:27:38 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief updateObject replace object geometry by given data.
|
|
|
|
|
* @param id is used to find object.
|
|
|
|
|
* @param shape members must live until object is updated by another shape removed from Navigator.
|
|
|
|
|
* @param transform allows to setup objects geometry according to its world state.
|
|
|
|
|
*/
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void updateObject(
|
|
|
|
|
const ObjectId id, const ObjectShapes& shapes, const btTransform& transform, const UpdateGuard* guard)
|
|
|
|
|
= 0;
|
2018-07-12 08:44:11 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief updateObject replace object geometry by given data.
|
|
|
|
|
* @param id is used to find object.
|
|
|
|
|
* @param shape members must live until object is updated by another shape removed from Navigator.
|
|
|
|
|
* @param transform allows to setup objects geometry according to its world state.
|
|
|
|
|
*/
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void updateObject(
|
|
|
|
|
const ObjectId id, const DoorShapes& shapes, const btTransform& transform, const UpdateGuard* guard)
|
|
|
|
|
= 0;
|
2018-08-26 20:27:38 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief removeObject to make it no more available at the scene.
|
|
|
|
|
* @param id is used to find object.
|
|
|
|
|
*/
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void removeObject(const ObjectId id, const UpdateGuard* guard) = 0;
|
2018-03-13 22:49:08 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief addWater is used to set water level at given world cell.
|
|
|
|
|
* @param cellPosition allows to distinguish cells if there is many in current world.
|
|
|
|
|
* @param cellSize set cell borders. std::numeric_limits<int>::max() disables cell borders.
|
2021-07-14 19:54:41 +00:00
|
|
|
|
* @param shift set global shift of cell center.
|
2018-09-29 22:20:42 +00:00
|
|
|
|
*/
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void addWater(const osg::Vec2i& cellPosition, int cellSize, float level, const UpdateGuard* guard) = 0;
|
2018-07-20 19:11:34 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief removeWater to make it no more available at the scene.
|
|
|
|
|
* @param cellPosition allows to find cell.
|
|
|
|
|
*/
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void removeWater(const osg::Vec2i& cellPosition, const UpdateGuard* guard) = 0;
|
2018-07-20 19:11:34 +00:00
|
|
|
|
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void addHeightfield(
|
|
|
|
|
const osg::Vec2i& cellPosition, int cellSize, const HeightfieldShape& shape, const UpdateGuard* guard)
|
|
|
|
|
= 0;
|
2021-07-14 18:57:52 +00:00
|
|
|
|
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void removeHeightfield(const osg::Vec2i& cellPosition, const UpdateGuard* guard) = 0;
|
2021-07-14 18:57:52 +00:00
|
|
|
|
|
2020-06-11 21:23:30 +00:00
|
|
|
|
virtual void addPathgrid(const ESM::Cell& cell, const ESM::Pathgrid& pathgrid) = 0;
|
|
|
|
|
|
|
|
|
|
virtual void removePathgrid(const ESM::Pathgrid& pathgrid) = 0;
|
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
2021-05-27 14:52:01 +00:00
|
|
|
|
* @brief update starts background navmesh update using current scene state.
|
2018-09-29 22:20:42 +00:00
|
|
|
|
* @param playerPosition setup initial point to order build tiles of navmesh.
|
|
|
|
|
*/
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void update(const osg::Vec3f& playerPosition, const UpdateGuard* guard) = 0;
|
2018-03-13 22:49:08 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
2021-05-14 19:06:29 +00:00
|
|
|
|
* @brief wait locks thread until tiles are updated from last update call based on passed condition type.
|
|
|
|
|
* @param waitConditionType defines when waiting will stop
|
2022-09-05 07:23:14 +00:00
|
|
|
|
* @param listener optional listener for a progress bar
|
2018-09-29 22:20:42 +00:00
|
|
|
|
*/
|
2022-09-05 07:23:14 +00:00
|
|
|
|
virtual void wait(WaitConditionType waitConditionType, Loading::Listener* listener) = 0;
|
2018-03-13 22:49:08 +00:00
|
|
|
|
|
2019-02-16 12:14:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief getNavMesh returns navmesh for specific agent half extents
|
|
|
|
|
* @return navmesh
|
|
|
|
|
*/
|
2022-06-16 22:28:44 +00:00
|
|
|
|
virtual SharedNavMeshCacheItem getNavMesh(const AgentBounds& agentBounds) const = 0;
|
2019-02-16 12:14:05 +00:00
|
|
|
|
|
2018-09-29 22:20:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief getNavMeshes returns all current navmeshes
|
|
|
|
|
* @return map of agent half extents to navmesh
|
|
|
|
|
*/
|
2022-06-16 22:28:44 +00:00
|
|
|
|
virtual std::map<AgentBounds, SharedNavMeshCacheItem> getNavMeshes() const = 0;
|
2018-07-12 08:44:11 +00:00
|
|
|
|
|
2019-02-19 08:46:00 +00:00
|
|
|
|
virtual const Settings& getSettings() const = 0;
|
2019-03-17 17:18:53 +00:00
|
|
|
|
|
2022-08-28 12:52:12 +00:00
|
|
|
|
virtual Stats getStats() const = 0;
|
2020-01-20 22:06:47 +00:00
|
|
|
|
|
2021-10-09 16:36:37 +00:00
|
|
|
|
virtual RecastMeshTiles getRecastMeshTiles() const = 0;
|
2021-03-23 22:15:13 +00:00
|
|
|
|
|
|
|
|
|
virtual float getMaxNavmeshAreaRealRadius() const = 0;
|
2018-03-13 22:49:08 +00:00
|
|
|
|
};
|
2021-11-05 23:14:41 +00:00
|
|
|
|
|
2022-06-19 11:28:33 +00:00
|
|
|
|
std::unique_ptr<Navigator> makeNavigator(const Settings& settings, const std::filesystem::path& userDataPath);
|
2021-11-05 23:14:41 +00:00
|
|
|
|
|
|
|
|
|
std::unique_ptr<Navigator> makeNavigatorStub();
|
2018-03-13 22:49:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|