2015-03-26 17:02:51 +00:00
|
|
|
#include "resourcesystem.hpp"
|
|
|
|
|
2017-05-05 19:21:11 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2024-04-04 00:30:27 +00:00
|
|
|
#include "animblendrulesmanager.hpp"
|
2024-04-18 02:01:12 +00:00
|
|
|
#include "bgsmfilemanager.hpp"
|
2016-02-05 22:03:53 +00:00
|
|
|
#include "imagemanager.hpp"
|
2015-12-12 17:52:06 +00:00
|
|
|
#include "keyframemanager.hpp"
|
2015-12-01 22:04:02 +00:00
|
|
|
#include "niffilemanager.hpp"
|
2015-03-26 17:02:51 +00:00
|
|
|
#include "scenemanager.hpp"
|
|
|
|
|
|
|
|
namespace Resource
|
|
|
|
{
|
|
|
|
|
2024-01-17 17:10:42 +00:00
|
|
|
ResourceSystem::ResourceSystem(
|
|
|
|
const VFS::Manager* vfs, double expiryDelay, const ToUTF8::StatelessUtf8Encoder* encoder)
|
2015-03-26 17:02:51 +00:00
|
|
|
: mVFS(vfs)
|
|
|
|
{
|
2024-01-16 19:56:58 +00:00
|
|
|
mNifFileManager = std::make_unique<NifFileManager>(vfs, encoder);
|
2024-04-18 02:01:12 +00:00
|
|
|
mBgsmFileManager = std::make_unique<BgsmFileManager>(vfs, expiryDelay);
|
2023-09-09 17:29:26 +00:00
|
|
|
mImageManager = std::make_unique<ImageManager>(vfs, expiryDelay);
|
2024-04-18 04:43:33 +00:00
|
|
|
mSceneManager = std::make_unique<SceneManager>(
|
|
|
|
vfs, mImageManager.get(), mNifFileManager.get(), mBgsmFileManager.get(), expiryDelay);
|
2024-01-16 19:56:58 +00:00
|
|
|
mKeyframeManager = std::make_unique<KeyframeManager>(vfs, mSceneManager.get(), expiryDelay, encoder);
|
2024-04-04 00:30:27 +00:00
|
|
|
mAnimBlendRulesManager = std::make_unique<AnimBlendRulesManager>(vfs, expiryDelay);
|
2016-02-06 15:57:54 +00:00
|
|
|
|
|
|
|
addResourceManager(mNifFileManager.get());
|
2024-04-18 02:01:12 +00:00
|
|
|
addResourceManager(mBgsmFileManager.get());
|
2016-02-06 15:57:54 +00:00
|
|
|
addResourceManager(mKeyframeManager.get());
|
|
|
|
// note, scene references images so add images afterwards for correct implementation of updateCache()
|
|
|
|
addResourceManager(mSceneManager.get());
|
|
|
|
addResourceManager(mImageManager.get());
|
2024-04-04 00:30:27 +00:00
|
|
|
addResourceManager(mAnimBlendRulesManager.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
|
|
|
}
|
|
|
|
|
2024-04-18 02:01:12 +00:00
|
|
|
BgsmFileManager* ResourceSystem::getBgsmFileManager()
|
|
|
|
{
|
|
|
|
return mBgsmFileManager.get();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2024-04-04 00:30:27 +00:00
|
|
|
AnimBlendRulesManager* ResourceSystem::getAnimBlendRulesManager()
|
|
|
|
{
|
|
|
|
return mAnimBlendRulesManager.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
|
|
|
}
|