mirror of https://github.com/OpenMW/openmw.git
Move keyframe loading out of SceneManager to new KeyframeManager
parent
295563ba65
commit
64424e7262
@ -0,0 +1,41 @@
|
||||
#include "keyframemanager.hpp"
|
||||
|
||||
#include <components/vfs/manager.hpp>
|
||||
#include <components/nifosg/nifloader.hpp>
|
||||
|
||||
#include "objectcache.hpp"
|
||||
|
||||
namespace Resource
|
||||
{
|
||||
|
||||
KeyframeManager::KeyframeManager(const VFS::Manager* vfs)
|
||||
: mCache(new osgDB::ObjectCache)
|
||||
, mVFS(vfs)
|
||||
{
|
||||
}
|
||||
|
||||
KeyframeManager::~KeyframeManager()
|
||||
{
|
||||
}
|
||||
|
||||
osg::ref_ptr<const NifOsg::KeyframeHolder> KeyframeManager::get(const std::string &name)
|
||||
{
|
||||
std::string normalized = name;
|
||||
mVFS->normalizeFilename(normalized);
|
||||
|
||||
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
|
||||
if (obj)
|
||||
return osg::ref_ptr<const NifOsg::KeyframeHolder>(static_cast<NifOsg::KeyframeHolder*>(obj.get()));
|
||||
else
|
||||
{
|
||||
osg::ref_ptr<NifOsg::KeyframeHolder> loaded (new NifOsg::KeyframeHolder);
|
||||
NifOsg::Loader::loadKf(Nif::NIFFilePtr(new Nif::NIFFile(mVFS->getNormalized(normalized), normalized)), *loaded.get());
|
||||
|
||||
mCache->addEntryToObjectCache(name, loaded);
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
#ifndef OPENMW_COMPONENTS_KEYFRAMEMANAGER_H
|
||||
#define OPENMW_COMPONENTS_KEYFRAMEMANAGER_H
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <string>
|
||||
|
||||
namespace VFS
|
||||
{
|
||||
class Manager;
|
||||
}
|
||||
|
||||
namespace osgDB
|
||||
{
|
||||
class ObjectCache;
|
||||
}
|
||||
|
||||
namespace NifOsg
|
||||
{
|
||||
class KeyframeHolder;
|
||||
}
|
||||
|
||||
namespace Resource
|
||||
{
|
||||
|
||||
/// @brief Managing of keyframe resources
|
||||
class KeyframeManager
|
||||
{
|
||||
public:
|
||||
KeyframeManager(const VFS::Manager* vfs);
|
||||
~KeyframeManager();
|
||||
|
||||
void clearCache();
|
||||
|
||||
/// Retrieve a read-only keyframe resource by name (case-insensitive).
|
||||
/// @note This method is safe to call from any thread.
|
||||
/// @note Throws an exception if the resource is not found.
|
||||
osg::ref_ptr<const NifOsg::KeyframeHolder> get(const std::string& name);
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osgDB::ObjectCache> mCache;
|
||||
|
||||
const VFS::Manager* mVFS;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue