1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-07 03:54:40 +00:00
OpenMW/components/detournavigator/gettilespositions.hpp
elsid 05b54cbfb8
Cull navmesh objects by scene bounds
If object is too big iteration over all tiles covering it can take too much
time. Limit bounds to a square around a player position to cover only tiles
that will be present in navmesh based on max tiles number option.

Each object is associated with a set of tiles its present in. Culling can
reduce this set but it has to be update when bounds change position. Do this
in TileCachedRecastMeshManager::setBounds updating the set and adding/removing
objects to the corresponding CachedRecastMeshManagers.
2022-02-03 22:09:37 +01:00

61 lines
1.9 KiB
C++

#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_GETTILESPOSITIONS_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_GETTILESPOSITIONS_H
#include "tilebounds.hpp"
#include "tileposition.hpp"
class btVector3;
class btTransform;
class btCollisionShape;
namespace osg
{
class Vec2f;
}
namespace DetourNavigator
{
struct RecastSettings;
struct TilesPositionsRange
{
TilePosition mBegin;
TilePosition mEnd;
};
TilesPositionsRange makeTilesPositionsRange(const osg::Vec2f& aabbMin,
const osg::Vec2f& aabbMax, const RecastSettings& settings);
TilesPositionsRange makeTilesPositionsRange(const btCollisionShape& shape,
const btTransform& transform, const RecastSettings& settings);
TilesPositionsRange makeTilesPositionsRange(const btCollisionShape& shape,
const btTransform& transform, const TileBounds& bounds, const RecastSettings& settings);
TilesPositionsRange makeTilesPositionsRange(const int cellSize, const btVector3& shift,
const RecastSettings& settings);
template <class Callback>
inline void getTilesPositions(const TilesPositionsRange& range, Callback&& callback)
{
for (int tileX = range.mBegin.x(); tileX < range.mEnd.x(); ++tileX)
for (int tileY = range.mBegin.y(); tileY < range.mEnd.y(); ++tileY)
callback(TilePosition {tileX, tileY});
}
inline bool isInTilesPositionsRange(int begin, int end, int coordinate)
{
return begin <= coordinate && coordinate < end;
}
inline bool isInTilesPositionsRange(const TilesPositionsRange& range, const TilePosition& position)
{
return isInTilesPositionsRange(range.mBegin.x(), range.mEnd.x(), position.x())
&& isInTilesPositionsRange(range.mBegin.y(), range.mEnd.y(), position.y());
}
TilesPositionsRange getIntersection(const TilesPositionsRange& a, const TilesPositionsRange& b) noexcept;
}
#endif