mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-04 02:41:19 +00:00
f2fb3d6de8
NIFFile might not always be created from a file or stream containing NIF data. Basically there are 2 different responsibilities for this class: 1. Read NIF file 2. Provide input for nifosg and bulletnifloader. Remove no longer needed NIFFileMock since the state of NIFFfile can be initialized independently from reading NIF file.
63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
#include "niffilemanager.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include <osg/Object>
|
|
#include <osg/Stats>
|
|
|
|
#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)
|
|
{
|
|
}
|
|
|
|
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
|
|
{
|
|
auto file = std::make_shared<Nif::NIFFile>(name);
|
|
Nif::Reader reader(*file);
|
|
reader.parse(mVFS->get(name));
|
|
obj = new NifFileHolder(file);
|
|
mCache->addEntryToObjectCache(name, obj);
|
|
return file;
|
|
}
|
|
}
|
|
|
|
void NifFileManager::reportStats(unsigned int frameNumber, osg::Stats* stats) const
|
|
{
|
|
stats->setAttribute(frameNumber, "Nif", mCache->getCacheSize());
|
|
}
|
|
|
|
}
|