mirror of https://github.com/OpenMW/openmw.git
Add a resource manager for BGSM files
parent
cb77bcc4c8
commit
fe1cb3a5ae
@ -0,0 +1,62 @@
|
||||
#include "bgsmfilemanager.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <osg/Object>
|
||||
|
||||
#include <components/bgsm/reader.hpp>
|
||||
#include <components/vfs/manager.hpp>
|
||||
|
||||
#include "objectcache.hpp"
|
||||
|
||||
namespace Resource
|
||||
{
|
||||
|
||||
class BgsmFileHolder : public osg::Object
|
||||
{
|
||||
public:
|
||||
BgsmFileHolder(const Bgsm::MaterialFilePtr& file)
|
||||
: mBgsmFile(file)
|
||||
{
|
||||
}
|
||||
BgsmFileHolder(const BgsmFileHolder& copy, const osg::CopyOp& copyop)
|
||||
: mBgsmFile(copy.mBgsmFile)
|
||||
{
|
||||
}
|
||||
|
||||
BgsmFileHolder() = default;
|
||||
|
||||
META_Object(Resource, BgsmFileHolder)
|
||||
|
||||
Bgsm::MaterialFilePtr mBgsmFile;
|
||||
};
|
||||
|
||||
BgsmFileManager::BgsmFileManager(const VFS::Manager* vfs, double expiryDelay)
|
||||
: ResourceManager(vfs, expiryDelay)
|
||||
{
|
||||
}
|
||||
|
||||
BgsmFileManager::~BgsmFileManager() = default;
|
||||
|
||||
Bgsm::MaterialFilePtr BgsmFileManager::get(VFS::Path::NormalizedView name)
|
||||
{
|
||||
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(name);
|
||||
if (obj)
|
||||
return static_cast<BgsmFileHolder*>(obj.get())->mBgsmFile;
|
||||
else
|
||||
{
|
||||
Bgsm::Reader reader;
|
||||
reader.parse(mVFS->get(name));
|
||||
Bgsm::MaterialFilePtr file = std::move(reader.getFile());
|
||||
obj = new BgsmFileHolder(file);
|
||||
mCache->addEntryToObjectCache(name.value(), obj);
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
void BgsmFileManager::reportStats(unsigned int frameNumber, osg::Stats* stats) const
|
||||
{
|
||||
Resource::reportStats("BSShader Material", frameNumber, mCache->getStats(), *stats);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#ifndef OPENMW_COMPONENTS_RESOURCE_BGSMFILEMANAGER_H
|
||||
#define OPENMW_COMPONENTS_RESOURCE_BGSMFILEMANAGER_H
|
||||
|
||||
#include <components/bgsm/file.hpp>
|
||||
|
||||
#include "resourcemanager.hpp"
|
||||
|
||||
namespace Resource
|
||||
{
|
||||
|
||||
/// @brief Handles caching of material files.
|
||||
/// @note May be used from any thread.
|
||||
class BgsmFileManager : public ResourceManager
|
||||
{
|
||||
public:
|
||||
BgsmFileManager(const VFS::Manager* vfs, double expiryDelay);
|
||||
~BgsmFileManager();
|
||||
|
||||
/// Retrieve a material file from the cache or load it from the VFS if not cached yet.
|
||||
Bgsm::MaterialFilePtr get(VFS::Path::NormalizedView name);
|
||||
|
||||
void reportStats(unsigned int frameNumber, osg::Stats* stats) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue