1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00
openmw/components/detournavigator/tilecachedrecastmeshmanager.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
3.8 KiB
C++
Raw Normal View History

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