2014-07-04 10:46:57 +00:00
|
|
|
#include "resourcesmanager.hpp"
|
|
|
|
|
2022-08-04 22:00:49 +00:00
|
|
|
#include "resources.hpp"
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <apps/opencs/model/world/universalid.hpp>
|
|
|
|
|
2014-07-04 10:46:57 +00:00
|
|
|
#include <stdexcept>
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <type_traits>
|
|
|
|
#include <utility>
|
2014-07-04 10:46:57 +00:00
|
|
|
|
2015-03-25 22:35:10 +00:00
|
|
|
CSMWorld::ResourcesManager::ResourcesManager()
|
2018-10-09 06:21:12 +00:00
|
|
|
: mVFS(nullptr)
|
2015-03-25 22:35:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-08-04 22:00:49 +00:00
|
|
|
CSMWorld::ResourcesManager::~ResourcesManager() = default;
|
|
|
|
|
2014-07-07 13:20:05 +00:00
|
|
|
void CSMWorld::ResourcesManager::addResources(const Resources& resources)
|
|
|
|
{
|
|
|
|
mResources.insert(std::make_pair(resources.getType(), resources));
|
2014-09-30 11:15:15 +00:00
|
|
|
mResources.insert(std::make_pair(UniversalId::getParentType(resources.getType()), resources));
|
2014-07-07 13:20:05 +00:00
|
|
|
}
|
|
|
|
|
2017-08-20 23:07:23 +00:00
|
|
|
const char* const* CSMWorld::ResourcesManager::getMeshExtensions()
|
2014-07-04 10:46:57 +00:00
|
|
|
{
|
2015-11-16 22:26:43 +00:00
|
|
|
// maybe we could go over the osgDB::Registry to list all supported node formats
|
2021-01-18 17:22:01 +00:00
|
|
|
static const char* const sMeshTypes[] = { "nif", "osg", "osgt", "osgb", "osgx", "osg2", "dae", 0 };
|
2017-08-20 23:07:23 +00:00
|
|
|
return sMeshTypes;
|
|
|
|
}
|
2014-07-07 09:34:24 +00:00
|
|
|
|
2017-08-20 23:07:23 +00:00
|
|
|
void CSMWorld::ResourcesManager::setVFS(const VFS::Manager* vfs)
|
|
|
|
{
|
|
|
|
mVFS = vfs;
|
|
|
|
mResources.clear();
|
|
|
|
|
|
|
|
addResources(Resources(vfs, "meshes", UniversalId::Type_Mesh, getMeshExtensions()));
|
2015-03-19 16:49:41 +00:00
|
|
|
addResources(Resources(vfs, "icons", UniversalId::Type_Icon));
|
|
|
|
addResources(Resources(vfs, "music", UniversalId::Type_Music));
|
|
|
|
addResources(Resources(vfs, "sound", UniversalId::Type_SoundRes));
|
|
|
|
addResources(Resources(vfs, "textures", UniversalId::Type_Texture));
|
2017-08-23 04:02:02 +00:00
|
|
|
addResources(Resources(vfs, "video", UniversalId::Type_Video));
|
2014-07-04 10:46:57 +00:00
|
|
|
}
|
|
|
|
|
2017-08-20 23:07:23 +00:00
|
|
|
const VFS::Manager* CSMWorld::ResourcesManager::getVFS() const
|
2015-03-25 22:35:10 +00:00
|
|
|
{
|
|
|
|
return mVFS;
|
|
|
|
}
|
|
|
|
|
2017-08-19 07:43:31 +00:00
|
|
|
void CSMWorld::ResourcesManager::recreateResources()
|
|
|
|
{
|
|
|
|
std::map<UniversalId::Type, Resources>::iterator it = mResources.begin();
|
|
|
|
for (; it != mResources.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it->first == UniversalId::Type_Mesh)
|
2017-08-20 23:07:23 +00:00
|
|
|
it->second.recreate(mVFS, getMeshExtensions());
|
2017-08-19 07:43:31 +00:00
|
|
|
else
|
|
|
|
it->second.recreate(mVFS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 10:46:57 +00:00
|
|
|
const CSMWorld::Resources& CSMWorld::ResourcesManager::get(UniversalId::Type type) const
|
|
|
|
{
|
|
|
|
std::map<UniversalId::Type, Resources>::const_iterator iter = mResources.find(type);
|
|
|
|
|
|
|
|
if (iter == mResources.end())
|
|
|
|
throw std::logic_error("Unknown resource type");
|
|
|
|
|
|
|
|
return iter->second;
|
2015-03-19 16:49:41 +00:00
|
|
|
}
|