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.
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#ifndef OPENMW_COMPONENTS_RESOURCE_IMAGEMANAGER_H
|
|
#define OPENMW_COMPONENTS_RESOURCE_IMAGEMANAGER_H
|
|
|
|
#include <osg/Image>
|
|
#include <osg/Texture2D>
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <components/vfs/pathutil.hpp>
|
|
|
|
#include "resourcemanager.hpp"
|
|
|
|
namespace osgDB
|
|
{
|
|
class Options;
|
|
}
|
|
|
|
namespace Resource
|
|
{
|
|
|
|
/// @brief Handles loading/caching of Images.
|
|
/// @note May be used from any thread.
|
|
class ImageManager : public ResourceManager<osg::ref_ptr<osg::Image>>
|
|
{
|
|
public:
|
|
explicit ImageManager(const VFS::Manager* vfs, double expiryDelay);
|
|
~ImageManager();
|
|
|
|
/// Create or retrieve an Image
|
|
/// Returns the dummy image if the given image is not found.
|
|
osg::ref_ptr<osg::Image> getImage(VFS::Path::NormalizedView path, bool disableFlip = false);
|
|
|
|
osg::Image* getWarningImage();
|
|
|
|
void reportStats(unsigned int frameNumber, osg::Stats* stats) const override;
|
|
|
|
private:
|
|
osg::ref_ptr<osg::Image> mWarningImage;
|
|
osg::ref_ptr<osgDB::Options> mOptions;
|
|
|
|
ImageManager(const ImageManager&);
|
|
void operator=(const ImageManager&);
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|