2018-04-15 22:07:18 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_TILECACHEDRECASTMESHMANAGER_H
|
|
|
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_TILECACHEDRECASTMESHMANAGER_H
|
|
|
|
|
|
|
|
#include "tileposition.hpp"
|
2020-02-25 02:38:39 +00:00
|
|
|
#include "gettilespositions.hpp"
|
2021-04-18 14:51:52 +00:00
|
|
|
#include "version.hpp"
|
2021-07-14 18:57:52 +00:00
|
|
|
#include "heightfieldshape.hpp"
|
2022-02-01 00:21:47 +00:00
|
|
|
#include "changetype.hpp"
|
2022-08-26 18:33:34 +00:00
|
|
|
#include "objectid.hpp"
|
|
|
|
#include "areatype.hpp"
|
|
|
|
#include "recastmeshobject.hpp"
|
2018-04-15 22:07:18 +00:00
|
|
|
|
2022-02-03 21:24:26 +00:00
|
|
|
#include <components/misc/guarded.hpp>
|
|
|
|
|
2018-04-15 22:07:18 +00:00
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
2021-05-27 13:25:21 +00:00
|
|
|
#include <vector>
|
2022-02-01 00:21:47 +00:00
|
|
|
#include <set>
|
2018-04-15 22:07:18 +00:00
|
|
|
|
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
2022-08-26 18:33:34 +00:00
|
|
|
class CachedRecastMeshManager;
|
|
|
|
class RecastMesh;
|
|
|
|
|
2018-04-15 22:07:18 +00:00
|
|
|
class TileCachedRecastMeshManager
|
|
|
|
{
|
|
|
|
public:
|
2021-11-06 12:46:43 +00:00
|
|
|
explicit TileCachedRecastMeshManager(const RecastSettings& settings);
|
2018-04-15 22:07:18 +00:00
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
void setBounds(const TileBounds& bounds);
|
2022-02-01 00:21:47 +00:00
|
|
|
|
2021-07-09 20:51:42 +00:00
|
|
|
std::string getWorldspace() const;
|
|
|
|
|
|
|
|
void setWorldspace(std::string_view worldspace);
|
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
bool addObject(ObjectId id, const CollisionShape& shape, const btTransform& transform, AreaType areaType);
|
2018-04-15 22:07:18 +00:00
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
bool updateObject(ObjectId id, const CollisionShape& shape, const btTransform& transform, AreaType areaType);
|
2018-05-26 14:44:25 +00:00
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
void removeObject(ObjectId id);
|
2018-04-15 22:07:18 +00:00
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
void addWater(const osg::Vec2i& cellPosition, int cellSize, float level);
|
2018-07-20 19:11:34 +00:00
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
void removeWater(const osg::Vec2i& cellPosition);
|
2018-07-20 19:11:34 +00:00
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
void addHeightfield(const osg::Vec2i& cellPosition, int cellSize, const HeightfieldShape& shape);
|
2021-07-14 18:57:52 +00:00
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
void removeHeightfield(const osg::Vec2i& cellPosition);
|
2021-07-14 18:57:52 +00:00
|
|
|
|
2021-07-09 20:51:42 +00:00
|
|
|
std::shared_ptr<RecastMesh> getMesh(std::string_view worldspace, const TilePosition& tilePosition) const;
|
2018-04-15 22:07:18 +00:00
|
|
|
|
2021-07-09 20:51:42 +00:00
|
|
|
std::shared_ptr<RecastMesh> getCachedMesh(std::string_view worldspace, const TilePosition& tilePosition) const;
|
2021-10-09 16:36:37 +00:00
|
|
|
|
2021-07-09 20:51:42 +00:00
|
|
|
std::shared_ptr<RecastMesh> getNewMesh(std::string_view worldspace, const TilePosition& tilePosition) const;
|
2021-06-29 01:49:21 +00:00
|
|
|
|
2018-04-20 23:57:01 +00:00
|
|
|
template <class Function>
|
2021-08-08 14:58:47 +00:00
|
|
|
void forEachTile(Function&& function) const
|
2018-04-20 23:57:01 +00:00
|
|
|
{
|
2022-02-03 21:24:26 +00:00
|
|
|
const auto& locked = mWorldspaceTiles.lockConst();
|
|
|
|
for (const auto& [tilePosition, recastMeshManager] : locked->mTiles)
|
2021-08-01 00:43:36 +00:00
|
|
|
function(tilePosition, *recastMeshManager);
|
2018-04-20 23:57:01 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
std::size_t getRevision() const { return mRevision; }
|
2018-04-20 23:57:01 +00:00
|
|
|
|
2021-08-08 14:58:47 +00:00
|
|
|
void reportNavMeshChange(const TilePosition& tilePosition, Version recastMeshVersion, Version navMeshVersion) const;
|
2021-04-18 14:51:52 +00:00
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
void addChangedTile(const TilePosition& tilePosition, ChangeType changeType);
|
|
|
|
|
|
|
|
std::map<osg::Vec2i, ChangeType> takeChangedTiles() { return std::move(mChangedTiles); }
|
|
|
|
|
2018-04-15 22:07:18 +00:00
|
|
|
private:
|
2021-08-01 00:43:36 +00:00
|
|
|
using TilesMap = std::map<TilePosition, std::shared_ptr<CachedRecastMeshManager>>;
|
|
|
|
|
2022-02-01 00:21:47 +00:00
|
|
|
struct ObjectData
|
|
|
|
{
|
|
|
|
const CollisionShape mShape;
|
|
|
|
const btTransform mTransform;
|
|
|
|
const AreaType mAreaType;
|
|
|
|
std::set<TilePosition> mTiles;
|
|
|
|
};
|
|
|
|
|
2022-02-03 21:24:26 +00:00
|
|
|
struct WorldspaceTiles
|
|
|
|
{
|
|
|
|
std::string mWorldspace;
|
|
|
|
TilesMap mTiles;
|
|
|
|
};
|
|
|
|
|
2021-11-06 12:46:43 +00:00
|
|
|
const RecastSettings& mSettings;
|
2022-02-01 00:21:47 +00:00
|
|
|
TileBounds mBounds;
|
|
|
|
TilesPositionsRange mRange;
|
2022-02-03 21:24:26 +00:00
|
|
|
Misc::ScopeGuarded<WorldspaceTiles> mWorldspaceTiles;
|
2022-02-01 00:21:47 +00:00
|
|
|
std::unordered_map<ObjectId, ObjectData> mObjects;
|
2018-07-20 19:11:34 +00:00
|
|
|
std::map<osg::Vec2i, std::vector<TilePosition>> mWaterTilesPositions;
|
2021-07-14 18:57:52 +00:00
|
|
|
std::map<osg::Vec2i, std::vector<TilePosition>> mHeightfieldTilesPositions;
|
2022-08-26 18:33:34 +00:00
|
|
|
std::map<osg::Vec2i, ChangeType> mChangedTiles;
|
2018-04-20 23:57:01 +00:00
|
|
|
std::size_t mRevision = 0;
|
2019-11-27 22:45:01 +00:00
|
|
|
std::size_t mTilesGeneration = 0;
|
2019-02-16 21:48:07 +00:00
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
inline bool addTile(ObjectId id, const CollisionShape& shape, const btTransform& transform,
|
|
|
|
AreaType areaType, const TilePosition& tilePosition, TilesMap& tiles);
|
2019-02-16 21:48:07 +00:00
|
|
|
|
2022-08-26 18:33:34 +00:00
|
|
|
inline bool removeTile(ObjectId id, const TilePosition& tilePosition, TilesMap& tiles);
|
2021-10-09 16:36:37 +00:00
|
|
|
|
2021-07-09 20:51:42 +00:00
|
|
|
inline std::shared_ptr<CachedRecastMeshManager> getManager(std::string_view worldspace,
|
|
|
|
const TilePosition& tilePosition) const;
|
2018-04-15 22:07:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|