2015-12-01 22:04:02 +00:00
|
|
|
#include "niffilemanager.hpp"
|
|
|
|
|
2022-07-21 11:51:34 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2016-02-09 17:11:07 +00:00
|
|
|
#include <osg/Object>
|
|
|
|
|
2015-12-01 22:04:02 +00:00
|
|
|
#include <components/vfs/manager.hpp>
|
|
|
|
|
2015-12-02 14:14:39 +00:00
|
|
|
#include "objectcache.hpp"
|
|
|
|
|
2015-12-01 22:04:02 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-01-16 19:56:58 +00:00
|
|
|
NifFileHolder() = default;
|
2015-12-01 22:04:02 +00:00
|
|
|
|
|
|
|
META_Object(Resource, NifFileHolder)
|
|
|
|
|
|
|
|
Nif::NIFFilePtr mNifFile;
|
|
|
|
};
|
|
|
|
|
2024-01-17 17:10:42 +00:00
|
|
|
NifFileManager::NifFileManager(const VFS::Manager* vfs, const ToUTF8::StatelessUtf8Encoder* encoder)
|
2023-08-27 15:12:42 +00:00
|
|
|
// NIF files aren't needed any more once the converted objects are cached in SceneManager / BulletShapeManager,
|
|
|
|
// so no point in using an expiry delay.
|
|
|
|
: ResourceManager(vfs, 0)
|
2024-01-16 19:56:58 +00:00
|
|
|
, mEncoder(encoder)
|
2015-12-01 22:04:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-01-16 19:56:58 +00:00
|
|
|
NifFileManager::~NifFileManager() = default;
|
2015-12-01 22:04:02 +00:00
|
|
|
|
2024-03-09 00:45:21 +00:00
|
|
|
Nif::NIFFilePtr NifFileManager::get(VFS::Path::NormalizedView name)
|
2015-12-01 22:04:02 +00:00
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(name);
|
2024-11-15 12:41:32 +00:00
|
|
|
if (obj != nullptr)
|
2015-12-01 22:04:02 +00:00
|
|
|
return static_cast<NifFileHolder*>(obj.get())->mNifFile;
|
2024-11-15 12:41:32 +00:00
|
|
|
|
|
|
|
auto file = std::make_shared<Nif::NIFFile>(name);
|
|
|
|
Nif::Reader reader(*file, mEncoder);
|
|
|
|
reader.parse(mVFS->get(name));
|
|
|
|
obj = new NifFileHolder(file);
|
|
|
|
mCache->addEntryToObjectCache(name.value(), obj);
|
|
|
|
return file;
|
2015-12-01 22:04:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 03:02:06 +00:00
|
|
|
void NifFileManager::reportStats(unsigned int frameNumber, osg::Stats* stats) const
|
2017-02-22 01:18:18 +00:00
|
|
|
{
|
2023-12-21 23:23:49 +00:00
|
|
|
Resource::reportStats("Nif", frameNumber, mCache->getStats(), *stats);
|
2017-02-22 01:18:18 +00:00
|
|
|
}
|
|
|
|
|
2015-12-01 22:04:02 +00:00
|
|
|
}
|