Files
Bret Curtis 4addabaf95 Let the resource cache be told what it stores, and free its values from OSG
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.
2026-09-18 16:10:18 +02:00

109 lines
3.5 KiB
C++

#ifndef OPENMW_NAVMESHTOOL_WORLDSPACEDATA_H
#define OPENMW_NAVMESHTOOL_WORLDSPACEDATA_H
#include <components/bullethelpers/collisionobject.hpp>
#include <components/detournavigator/settings.hpp>
#include <components/detournavigator/tilecachedrecastmeshmanager.hpp>
#include <components/esm3/loadland.hpp>
#include <components/misc/convert.hpp>
#include <components/resource/bulletshape.hpp>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <BulletCollision/Gimpact/btBoxCollision.h>
#include <LinearMath/btVector3.h>
#include <memory>
#include <regex>
#include <span>
#include <vector>
namespace ESM
{
class ESMReader;
class ReadersCache;
}
namespace VFS
{
class Manager;
}
namespace Resource
{
class BulletShapeManager;
}
namespace EsmLoader
{
struct EsmData;
}
namespace NavMeshTool
{
using DetourNavigator::ObjectTransform;
using DetourNavigator::RecastSettings;
using DetourNavigator::TileCachedRecastMeshManager;
class BulletObject
{
public:
BulletObject(std::shared_ptr<Resource::BulletShapeInstance>&& shapeInstance, const ESM::Position& position,
float localScaling)
: mShapeInstance(std::move(shapeInstance))
, mObjectTransform{ position, localScaling }
, mCollisionObject(BulletHelpers::makeCollisionObject(mShapeInstance->mCollisionShape.get(),
Misc::Convert::toBullet(position.asVec3()),
Misc::Convert::toBullet(Misc::Convert::makeOsgQuat(position))))
{
mShapeInstance->setLocalScaling(btVector3(localScaling, localScaling, localScaling));
}
const std::shared_ptr<Resource::BulletShapeInstance>& getShapeInstance() const noexcept
{
return mShapeInstance;
}
const DetourNavigator::ObjectTransform& getObjectTransform() const noexcept { return mObjectTransform; }
btCollisionObject& getCollisionObject() const noexcept { return *mCollisionObject; }
private:
std::shared_ptr<Resource::BulletShapeInstance> mShapeInstance;
DetourNavigator::ObjectTransform mObjectTransform;
std::unique_ptr<btCollisionObject> mCollisionObject;
};
struct TilesData
{
const RecastSettings mSettings;
TileCachedRecastMeshManager mTileCachedRecastMeshManager;
std::vector<BulletObject> mObjects;
std::vector<std::unique_ptr<ESM::Land::LandData>> mLandData;
std::vector<std::vector<float>> mHeightfields;
explicit TilesData(const RecastSettings& settings)
: mSettings(settings)
, mTileCachedRecastMeshManager(mSettings)
{
}
};
struct WorldspaceData
{
ESM::RefId mWorldspace;
btAABB mAabb;
bool mAabbInitialized = false;
std::vector<DetourNavigator::TilePosition> mTiles;
std::shared_ptr<TilesData> mTilesData;
WorldspaceData(ESM::RefId worldspace, const RecastSettings& settings);
};
std::unordered_map<ESM::RefId, std::vector<std::size_t>> collectWorldspaceCells(
const EsmLoader::EsmData& esmData, bool processInteriorCells, const std::regex& worldspaceFilter);
WorldspaceData gatherWorldspaceData(const DetourNavigator::Settings& settings, ESM::ReadersCache& readers,
const VFS::Manager& vfs, Resource::BulletShapeManager& bulletShapeManager, const EsmLoader::EsmData& esmData,
bool writeBinaryLog, ESM::RefId worldspace, std::span<const std::size_t> cells);
}
#endif