GenericObjectCache stored osg::ref_ptr<osg::Object>, so everything cached had to derive from osg::Object whether that meant anything or not: NifFileHolder and BgsmFileHolder existed for no other reason, Resource::BulletShape and ESMTerrain::LandObject carried META_Object and a CopyOp constructor nothing ever called, and every getter paid a static_cast on the way out. The cache and MultiObjectCache now take their value type as a template parameter, ask "is anything else holding this?" through a useCount overload rather than a base class method, and constrain accept and releaseGLObjects so a value type with neither is not an error. Both holders are deleted; BulletShape, BulletShapeInstance and LandObject become plain classes held by std::shared_ptr across physics, pathfinding, navmeshtool and terrain storage; MWPhysics::HeightField's type-erased osg::Object keep-alive becomes the LandObject it was always holding; every remaining manager names the type it actually caches through the NodeResourceManager alias, which removes eight static_casts and stops clang-format wrapping the declarations. The preloader needs two keep-alive sets for now, because the render-owned entries are still osg::Object; they merge once those move behind the render backend.
85 lines
2.8 KiB
C++
85 lines
2.8 KiB
C++
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESHBUILDER_H
|
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTMESHBUILDER_H
|
|
|
|
#include "recastmesh.hpp"
|
|
#include "tilebounds.hpp"
|
|
|
|
#include <components/resource/bulletshape.hpp>
|
|
|
|
#include <osg/Vec3f>
|
|
|
|
#include <LinearMath/btTransform.h>
|
|
|
|
#include <array>
|
|
#include <memory>
|
|
#include <tuple>
|
|
#include <vector>
|
|
|
|
class btBoxShape;
|
|
class btCollisionShape;
|
|
class btCompoundShape;
|
|
class btConcaveShape;
|
|
class btHeightfieldTerrainShape;
|
|
class btTriangleCallback;
|
|
|
|
namespace DetourNavigator
|
|
{
|
|
struct RecastMeshTriangle
|
|
{
|
|
AreaType mAreaType;
|
|
std::array<osg::Vec3f, 3> mVertices;
|
|
|
|
friend inline bool operator<(const RecastMeshTriangle& lhs, const RecastMeshTriangle& rhs)
|
|
{
|
|
return std::tie(lhs.mAreaType, lhs.mVertices) < std::tie(rhs.mAreaType, rhs.mVertices);
|
|
}
|
|
};
|
|
|
|
class RecastMeshBuilder
|
|
{
|
|
public:
|
|
explicit RecastMeshBuilder(const TileBounds& bounds) noexcept;
|
|
|
|
void addObject(const btCollisionShape& shape, const btTransform& transform, const AreaType areaType,
|
|
std::shared_ptr<const Resource::BulletShape> source, const ObjectTransform& objectTransform);
|
|
|
|
void addObject(const btCompoundShape& shape, const btTransform& transform, const AreaType areaType);
|
|
|
|
void addObject(const btConcaveShape& shape, const btTransform& transform, const AreaType areaType);
|
|
|
|
void addObject(const btHeightfieldTerrainShape& shape, const btTransform& transform, const AreaType areaType);
|
|
|
|
void addObject(const btBoxShape& shape, const btTransform& transform, const AreaType areaType);
|
|
|
|
void addWater(const osg::Vec2i& cellPosition, const Water& water);
|
|
|
|
void addHeightfield(const osg::Vec2i& cellPosition, int cellSize, float height);
|
|
|
|
void addHeightfield(const osg::Vec2i& cellPosition, int cellSize, const float* heights, std::size_t size,
|
|
float minHeight, float maxHeight);
|
|
|
|
std::shared_ptr<RecastMesh> create(const Version& version) &&;
|
|
|
|
private:
|
|
const TileBounds mBounds;
|
|
std::vector<RecastMeshTriangle> mTriangles;
|
|
std::vector<CellWater> mWater;
|
|
std::vector<Heightfield> mHeightfields;
|
|
std::vector<FlatHeightfield> mFlatHeightfields;
|
|
std::vector<MeshSource> mSources;
|
|
|
|
inline void addObject(const btCollisionShape& shape, const btTransform& transform, const AreaType areaType);
|
|
|
|
void addObject(const btConcaveShape& shape, const btTransform& transform, btTriangleCallback&& callback);
|
|
|
|
void addObject(
|
|
const btHeightfieldTerrainShape& shape, const btTransform& transform, btTriangleCallback&& callback);
|
|
};
|
|
|
|
Mesh makeMesh(std::vector<RecastMeshTriangle>&& triangles, const osg::Vec3f& shift = osg::Vec3f());
|
|
|
|
Mesh makeMesh(const Heightfield& heightfield);
|
|
}
|
|
|
|
#endif
|