2015-03-26 17:02:51 +00:00
|
|
|
#include "resourcesystem.hpp"
|
|
|
|
|
2017-05-05 19:21:11 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2015-03-26 17:02:51 +00:00
|
|
|
#include "scenemanager.hpp"
|
2016-02-05 22:03:53 +00:00
|
|
|
#include "imagemanager.hpp"
|
2015-12-01 22:04:02 +00:00
|
|
|
#include "niffilemanager.hpp"
|
2015-12-12 17:52:06 +00:00
|
|
|
#include "keyframemanager.hpp"
|
2015-03-26 17:02:51 +00:00
|
|
|
|
|
|
|
namespace Resource
|
|
|
|
{
|
|
|
|
|
|
|
|
ResourceSystem::ResourceSystem(const VFS::Manager *vfs)
|
|
|
|
: mVFS(vfs)
|
|
|
|
{
|
2015-12-01 22:04:02 +00:00
|
|
|
mNifFileManager.reset(new NifFileManager(vfs));
|
2015-12-12 17:52:06 +00:00
|
|
|
mKeyframeManager.reset(new KeyframeManager(vfs));
|
2016-02-05 22:10:27 +00:00
|
|
|
mImageManager.reset(new ImageManager(vfs));
|
|
|
|
mSceneManager.reset(new SceneManager(vfs, mImageManager.get(), mNifFileManager.get()));
|
2016-02-06 15:57:54 +00:00
|
|
|
|
|
|
|
addResourceManager(mNifFileManager.get());
|
|
|
|
addResourceManager(mKeyframeManager.get());
|
|
|
|
// note, scene references images so add images afterwards for correct implementation of updateCache()
|
|
|
|
addResourceManager(mSceneManager.get());
|
|
|
|
addResourceManager(mImageManager.get());
|
2015-03-26 17:02:51 +00:00
|
|
|
}
|
|
|
|
|
2015-05-08 15:52:35 +00:00
|
|
|
ResourceSystem::~ResourceSystem()
|
|
|
|
{
|
|
|
|
// this has to be defined in the .cpp file as we can't delete incomplete types
|
2016-02-06 15:57:54 +00:00
|
|
|
|
|
|
|
mResourceManagers.clear();
|
2015-05-08 15:52:35 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 17:02:51 +00:00
|
|
|
SceneManager* ResourceSystem::getSceneManager()
|
|
|
|
{
|
|
|
|
return mSceneManager.get();
|
|
|
|
}
|
|
|
|
|
2016-02-05 22:10:27 +00:00
|
|
|
ImageManager* ResourceSystem::getImageManager()
|
2015-04-16 23:23:37 +00:00
|
|
|
{
|
2016-02-05 22:10:27 +00:00
|
|
|
return mImageManager.get();
|
2015-04-16 23:23:37 +00:00
|
|
|
}
|
|
|
|
|
2015-12-12 17:52:06 +00:00
|
|
|
NifFileManager* ResourceSystem::getNifFileManager()
|
2015-12-01 22:04:02 +00:00
|
|
|
{
|
|
|
|
return mNifFileManager.get();
|
|
|
|
}
|
|
|
|
|
2015-12-12 17:52:06 +00:00
|
|
|
KeyframeManager* ResourceSystem::getKeyframeManager()
|
|
|
|
{
|
|
|
|
return mKeyframeManager.get();
|
|
|
|
}
|
|
|
|
|
2016-02-07 18:05:55 +00:00
|
|
|
void ResourceSystem::setExpiryDelay(double expiryDelay)
|
|
|
|
{
|
2019-03-13 07:15:58 +00:00
|
|
|
for (std::vector<BaseResourceManager*>::iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)
|
2016-02-07 18:05:55 +00:00
|
|
|
(*it)->setExpiryDelay(expiryDelay);
|
|
|
|
|
|
|
|
// NIF files aren't needed any more once the converted objects are cached in SceneManager / BulletShapeManager,
|
|
|
|
// so no point in using an expiry delay
|
|
|
|
mNifFileManager->setExpiryDelay(0.0);
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:57:54 +00:00
|
|
|
void ResourceSystem::updateCache(double referenceTime)
|
|
|
|
{
|
2019-03-13 07:15:58 +00:00
|
|
|
for (std::vector<BaseResourceManager*>::iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)
|
2016-02-06 15:57:54 +00:00
|
|
|
(*it)->updateCache(referenceTime);
|
|
|
|
}
|
|
|
|
|
2017-08-19 19:26:46 +00:00
|
|
|
void ResourceSystem::clearCache()
|
|
|
|
{
|
2019-03-13 07:15:58 +00:00
|
|
|
for (std::vector<BaseResourceManager*>::iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)
|
2017-08-19 19:26:46 +00:00
|
|
|
(*it)->clearCache();
|
|
|
|
}
|
|
|
|
|
2019-03-13 07:15:58 +00:00
|
|
|
void ResourceSystem::addResourceManager(BaseResourceManager *resourceMgr)
|
2016-02-06 15:57:54 +00:00
|
|
|
{
|
|
|
|
mResourceManagers.push_back(resourceMgr);
|
|
|
|
}
|
|
|
|
|
2019-03-13 07:15:58 +00:00
|
|
|
void ResourceSystem::removeResourceManager(BaseResourceManager *resourceMgr)
|
2015-12-01 22:04:02 +00:00
|
|
|
{
|
2019-03-13 07:15:58 +00:00
|
|
|
std::vector<BaseResourceManager*>::iterator found = std::find(mResourceManagers.begin(), mResourceManagers.end(), resourceMgr);
|
2016-02-06 15:57:54 +00:00
|
|
|
if (found != mResourceManagers.end())
|
|
|
|
mResourceManagers.erase(found);
|
2015-12-01 22:04:02 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 17:02:51 +00:00
|
|
|
const VFS::Manager* ResourceSystem::getVFS() const
|
|
|
|
{
|
|
|
|
return mVFS;
|
|
|
|
}
|
|
|
|
|
2017-03-07 03:02:06 +00:00
|
|
|
void ResourceSystem::reportStats(unsigned int frameNumber, osg::Stats *stats) const
|
2017-02-22 01:18:18 +00:00
|
|
|
{
|
2019-03-13 07:15:58 +00:00
|
|
|
for (std::vector<BaseResourceManager*>::const_iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)
|
2017-02-22 01:18:18 +00:00
|
|
|
(*it)->reportStats(frameNumber, stats);
|
|
|
|
}
|
|
|
|
|
2017-08-26 19:28:23 +00:00
|
|
|
void ResourceSystem::releaseGLObjects(osg::State *state)
|
|
|
|
{
|
2019-03-13 07:15:58 +00:00
|
|
|
for (std::vector<BaseResourceManager*>::const_iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)
|
2017-08-26 19:28:23 +00:00
|
|
|
(*it)->releaseGLObjects(state);
|
|
|
|
}
|
|
|
|
|
2015-03-26 17:02:51 +00:00
|
|
|
}
|