1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-24 18:23:52 +00:00
openmw-tes3mp/components/resource/niffilemanager.cpp

58 lines
1.4 KiB
C++
Raw Normal View History

#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
{
2015-12-12 17:33:55 +00:00
Nif::NIFFilePtr file (new Nif::NIFFile(mVFS->getNormalized(name), name));
obj = new NifFileHolder(file);
mCache->addEntryToObjectCache(name, obj);
return file;
}
}
}