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.
62 lines
2.1 KiB
C++
62 lines
2.1 KiB
C++
#ifndef OPENMW_COMPONENTS_BULLETSHAPEMANAGER_H
|
|
#define OPENMW_COMPONENTS_BULLETSHAPEMANAGER_H
|
|
|
|
#include <memory>
|
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <components/vfs/pathutil.hpp>
|
|
|
|
#include "bulletshape.hpp"
|
|
#include "multiobjectcache.hpp"
|
|
#include "resourcemanager.hpp"
|
|
|
|
namespace Resource
|
|
{
|
|
class SceneManager;
|
|
class NifFileManager;
|
|
|
|
struct BulletShape;
|
|
class BulletShapeInstance;
|
|
|
|
/// Handles loading, caching and "instancing" of bullet shapes.
|
|
/// A shape 'instance' is a clone of another shape, with the goal of setting a different scale on this instance.
|
|
/// @note May be used from any thread.
|
|
class BulletShapeManager : public ResourceManager<std::shared_ptr<const BulletShape>>
|
|
{
|
|
public:
|
|
BulletShapeManager(
|
|
const VFS::Manager* vfs, SceneManager* sceneMgr, NifFileManager* nifFileManager, double expiryDelay);
|
|
~BulletShapeManager();
|
|
|
|
/// @note May return a null pointer if the object has no shape.
|
|
std::shared_ptr<const BulletShape> getShape(VFS::Path::NormalizedView name);
|
|
|
|
/// Create an instance of the given shape and cache it for later use, so that future calls to getInstance() can
|
|
/// simply return the cached instance instead of having to create a new one.
|
|
/// @note The returned shared_ptr may be kept by the caller to ensure that the instance stays in cache for as
|
|
/// long as needed.
|
|
std::shared_ptr<BulletShapeInstance> cacheInstance(VFS::Path::NormalizedView name);
|
|
|
|
/// @note May return a null pointer if the object has no shape.
|
|
std::shared_ptr<BulletShapeInstance> getInstance(VFS::Path::NormalizedView name);
|
|
|
|
/// @see ResourceManager::updateCache
|
|
void updateCache(double referenceTime) override;
|
|
|
|
void clearCache() override;
|
|
|
|
void reportStats(unsigned int frameNumber, osg::Stats* stats) const override;
|
|
|
|
private:
|
|
std::shared_ptr<BulletShapeInstance> createInstance(VFS::Path::NormalizedView name);
|
|
|
|
std::unique_ptr<MultiObjectCache<std::shared_ptr<BulletShapeInstance>>> mInstanceCache;
|
|
SceneManager* mSceneManager;
|
|
NifFileManager* mNifFileManager;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|