mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-15 19:19:55 +00:00
df57d4bfba
Implement updateCache to delete unreferenced cached objects when they have not been referenced for a while.
57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
#include "niffilemanager.hpp"
|
|
|
|
#include <components/vfs/manager.hpp>
|
|
|
|
#include "objectcache.hpp"
|
|
|
|
namespace Resource
|
|
{
|
|
|
|
class NifFileHolder : public osg::Object
|
|
{
|
|
public:
|
|
NifFileHolder(const Nif::NIFFilePtr& file)
|
|
: mNifFile(file)
|
|
{
|
|
}
|
|
NifFileHolder(const NifFileHolder& copy, const osg::CopyOp& copyop)
|
|
: mNifFile(copy.mNifFile)
|
|
{
|
|
}
|
|
|
|
NifFileHolder()
|
|
{
|
|
}
|
|
|
|
META_Object(Resource, NifFileHolder)
|
|
|
|
Nif::NIFFilePtr mNifFile;
|
|
};
|
|
|
|
NifFileManager::NifFileManager(const VFS::Manager *vfs)
|
|
: ResourceManager(vfs, 0.0) // NIF files aren't needed any more when the converted objects are cached in SceneManager / BulletShapeManager,
|
|
// so we'll use expiryDelay of 0 to instantly delete NIF files after use.
|
|
{
|
|
}
|
|
|
|
NifFileManager::~NifFileManager()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
Nif::NIFFilePtr NifFileManager::get(const std::string &name)
|
|
{
|
|
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(name);
|
|
if (obj)
|
|
return static_cast<NifFileHolder*>(obj.get())->mNifFile;
|
|
else
|
|
{
|
|
Nif::NIFFilePtr file (new Nif::NIFFile(mVFS->getNormalized(name), name));
|
|
obj = new NifFileHolder(file);
|
|
mCache->addEntryToObjectCache(name, obj);
|
|
return file;
|
|
}
|
|
}
|
|
|
|
}
|