1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 03:40:14 +00:00
OpenMW/apps/opencs/model/world/resourcesmanager.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
2.1 KiB
C++
Raw Normal View History

2014-07-04 12:46:57 +02:00
#include "resourcesmanager.hpp"
2022-08-05 00:00:49 +02:00
#include "resources.hpp"
2022-10-19 19:02:00 +02:00
#include <apps/opencs/model/world/universalid.hpp>
2014-07-04 12:46:57 +02:00
#include <stdexcept>
2022-10-19 19:02:00 +02:00
#include <type_traits>
#include <utility>
2014-07-04 12:46:57 +02:00
CSMWorld::ResourcesManager::ResourcesManager()
2018-10-09 10:21:12 +04:00
: mVFS(nullptr)
{
}
2022-08-05 00:00:49 +02:00
CSMWorld::ResourcesManager::~ResourcesManager() = default;
2014-07-07 15:20:05 +02:00
void CSMWorld::ResourcesManager::addResources(const Resources& resources)
{
mResources.insert(std::make_pair(resources.getType(), resources));
mResources.insert(std::make_pair(UniversalId::getParentType(resources.getType()), resources));
2014-07-07 15:20:05 +02:00
}
2017-08-20 19:07:23 -04:00
const char* const* CSMWorld::ResourcesManager::getMeshExtensions()
2014-07-04 12:46:57 +02:00
{
2015-11-16 23:26:43 +01:00
// maybe we could go over the osgDB::Registry to list all supported node formats
2021-01-18 19:22:01 +02:00
static const char* const sMeshTypes[] = { "nif", "osg", "osgt", "osgb", "osgx", "osg2", "dae", 0 };
2017-08-20 19:07:23 -04:00
return sMeshTypes;
}
2017-08-20 19:07:23 -04:00
void CSMWorld::ResourcesManager::setVFS(const VFS::Manager* vfs)
{
mVFS = vfs;
mResources.clear();
addResources(Resources(vfs, "meshes", UniversalId::Type_Mesh, getMeshExtensions()));
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 00:02:02 -04:00
addResources(Resources(vfs, "video", UniversalId::Type_Video));
2014-07-04 12:46:57 +02:00
}
2017-08-20 19:07:23 -04:00
const VFS::Manager* CSMWorld::ResourcesManager::getVFS() const
{
return mVFS;
}
2017-08-19 03:43:31 -04: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 19:07:23 -04:00
it->second.recreate(mVFS, getMeshExtensions());
2017-08-19 03:43:31 -04:00
else
it->second.recreate(mVFS);
}
}
2014-07-04 12:46:57 +02: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;
}