25#include <Overlay/OgreOverlayManager.h>
26#include <Overlay/OgreOverlay.h>
27#include <Plugins/ParticleFX/OgreBoxEmitterFactory.h>
54#include <OgreFileSystem.h>
56#include <rapidjson/stringbuffer.h>
57#include <rapidjson/writer.h>
59#include <OgreMeshLodGenerator.h>
68#define DECLARE_RESOURCE_PACK(_FIELD_, _NAME_, _RESOURCE_GROUP_) \
69 const ContentManager::ResourcePack ContentManager::ResourcePack::_FIELD_(_NAME_, _RESOURCE_GROUP_);
101 Ogre::ResourceGroupManager& rgm = Ogre::ResourceGroupManager::getSingleton();
103 Ogre::String rg_name;
104 if (!override_rgn.empty())
106 rg_name = override_rgn;
117 std::stringstream log_msg;
118 log_msg <<
"[RoR|ContentManager] Loading resource pack \"" << resource_pack.
name <<
"\" to group \"" << rg_name <<
"\"";
120 std::string zip_path = dir_path +
".zip";
123 log_msg <<
" (ZIP archive)";
125 rgm.addResourceLocation(zip_path,
"Zip", rg_name);
131 log_msg <<
" (directory)";
133 rgm.addResourceLocation(dir_path,
"FileSystem", rg_name);
137 log_msg <<
" failed, data not found.";
138 throw std::runtime_error(log_msg.str());
142 if (override_rgn.empty())
144 rgm.initialiseResourceGroup(rg_name);
150 ResourceGroupManager::getSingleton().addResourceLocation(
152 ResourceGroupManager::getSingleton().addResourceLocation(
154 ResourceGroupManager::getSingleton().addResourceLocation(
156 ResourceGroupManager::getSingleton().addResourceLocation(
161 ResourceGroupManager::getSingleton().addResourceLocation(
165 FileInfoListPtr dirs = ResourceGroupManager::getSingleton().findResourceFileInfo(
RGN_SERVER_SCRIPTS,
"*",
true);
166 for (
const auto& dir_fileinfo : *dirs)
168 if (!dir_fileinfo.archive)
170 String fullpath =
PathCombine(dir_fileinfo.archive->getName(), dir_fileinfo.filename);
171 ResourceGroupManager::getSingleton().addResourceLocation(fullpath,
"FileSystem",
RGN_SERVER_SCRIPTS,
false,
false);
174 Ogre::ScriptCompilerManager::getSingleton().setListener(
this);
183 if (!Ogre::ResourceGroupManager::getSingleton().getLoadingListener())
184 Ogre::ResourceGroupManager::getSingleton().setLoadingListener(
this);
197 LOG(
"RoR|ContentManager: Registering Particle Box Emitter");
199 ParticleSystemManager::getSingleton().addRendererFactory(mParticleSystemRendererFact);
208#ifdef USE_ANGELSCRIPT
211 ParticleSystemManager::getSingleton().addAffectorFactory(pAffFact);
215 ParticleSystemManager::getSingleton().addAffectorFactory(pAffFact);
220 LOG(
"RoR|ContentManager: Creating Sound Manager");
228 LOG(
"RoR|ContentManager: Loading filesystems");
230 LOG(
"RoR|ContentManager: Registering colored text overlay factory");
232 OverlayManager::getSingleton().addOverlayElementFactory(pCT);
235 if (TextureManager::getSingletonPtr())
236 TextureManager::getSingleton().setDefaultNumMipmaps(5);
238 TextureFilterOptions tfo = TFO_NONE;
246 MaterialManager::getSingleton().setDefaultAnisotropy(Math::Clamp(
App::gfx_anisotropy->getInt(), 1, 16));
247 MaterialManager::getSingleton().setDefaultTextureFiltering(tfo);
250 LOG(
"RoR|ContentManager: Calling initialiseAllResourceGroups()");
253 ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
255 catch (Ogre::Exception& e)
257 LOG(
"RoR|ContentManager: catched error while initializing Resource groups: " + e.getFullDescription());
263 new Ogre::MeshLodGenerator();
277 ResourceGroupManager::getSingleton().addResourceLocation(
279 ResourceGroupManager::getSingleton().addResourceLocation(
281 ResourceGroupManager::getSingleton().addResourceLocation(
289 ResourceGroupManager::getSingleton().addResourceLocation(extra_mod_path ,
"FileSystem",
RGN_CONTENT);
296 std::string objects =
PathCombine(
"resources",
"beamobjects.zip");
298 std::string dashboards =
PathCombine(
"resources",
"dashboards.zip");
300 std::string gadgets =
PathCombine(
"resources",
"gadgets.zip");
305 ResourceGroupManager::getSingleton().createResourceGroup(
RGN_TEMP,
false);
309 ResourceGroupManager::getSingleton().addResourceLocation(extra_mod_path ,
"FileSystem",
RGN_TEMP,
true);
320 FileInfoListPtr dirs = ResourceGroupManager::getSingleton().findResourceFileInfo(
RGN_TEMP,
"*",
true);
321 for (
const auto& dir_fileinfo : *dirs)
323 if (!dir_fileinfo.archive)
325 String fullpath =
PathCombine(dir_fileinfo.archive->getName(), dir_fileinfo.filename);
326 ResourceGroupManager::getSingleton().addResourceLocation(fullpath,
"FileSystem",
RGN_CONTENT,
false,
false);
328 ResourceGroupManager::getSingleton().destroyResourceGroup(
RGN_TEMP);
338 ResourceGroupManager::getSingleton().destroyResourceGroup(
RGN_CONTENT);
344 return Ogre::DataStreamPtr();
358 RoR::LogFormat(
"[RoR|ContentManager] Skipping resource with duplicate name: '%s' (origin: '%s')",
359 resource->getName().c_str(), resource->getOrigin().c_str());
365 if (evt->mType == CreateMaterialScriptCompilerEvent::eventType)
369 auto* matEvent =
static_cast<CreateMaterialScriptCompilerEvent*
>(evt);
370 if (matEvent->mName.empty())
372 RoR::LogFormat(
"[RoR] Got malformed material (empty name) from file: '%s' - forcing OGRE to fail loading.",
373 matEvent->mFile.c_str());
379 else if (evt->mType == CreateParticleSystemScriptCompilerEvent::eventType)
383 auto* particleEvent =
static_cast<CreateParticleSystemScriptCompilerEvent*
>(evt);
384 if (Ogre::ParticleSystemManager::getSingleton().getTemplate(particleEvent->mName) !=
nullptr)
387 RoR::LogFormat(
"[RoR] Duplicate particle system name '%s' in file: '%s' - forcing OGRE to fail loading.",
388 particleEvent->mName.c_str(), particleEvent->mFile.c_str());
392#if OGRE_VERSION < 0x010C08
393 else if (evt->mType == CreateHighLevelGpuProgramScriptCompilerEvent::eventType)
399 auto* progEvent =
static_cast<CreateHighLevelGpuProgramScriptCompilerEvent*
>(evt);
400 if (progEvent->mLanguage !=
"hlsl")
403 HighLevelGpuProgramPtr prog = HighLevelGpuProgramManager::getSingleton().createProgram(
404 progEvent->mName, progEvent->mResourceGroup, progEvent->mLanguage, progEvent->mProgramType);
407 prog->setSourceFile(progEvent->mSource);
408 const String prefix = (progEvent->mProgramType == GPT_VERTEX_PROGRAM) ?
"vs_" :
"ps_";
409 const bool sm3 = GpuProgramManager::getSingleton().isSyntaxSupported(prefix +
"3_0");
410 prog->setParameter(
"target", prefix + (sm3 ?
"3_0" :
"2_0"));
412 *
static_cast<HighLevelGpuProgram**
>(retval) = prog.get();
429 ResourceGroupManager::getSingleton().addResourceLocation(
PathCombine(managed_materials_dir,
"shadows/pssm/on/shared"),
"FileSystem", rg_name);
431 ResourceGroupManager::getSingleton().addResourceLocation(
PathCombine(managed_materials_dir,
"shadows/pssm/on"),
"FileSystem", rg_name);
435 ResourceGroupManager::getSingleton().addResourceLocation(
PathCombine(managed_materials_dir,
"shadows/pssm/off"),
"FileSystem", rg_name);
438 ResourceGroupManager::getSingleton().addResourceLocation(
PathCombine(managed_materials_dir,
"texture"),
"FileSystem", rg_name);
441 ResourceGroupManager::getSingleton().addResourceLocation(managed_materials_dir,
"FileSystem", rg_name);
444 ResourceGroupManager::getSingleton().initialiseResourceGroup(rg_name);
477 std::stringstream buf;
479 auto dir_list = Ogre::ResourceGroupManager::getSingleton().listResourceFileInfo(
RGN_CONTENT,
true);
480 for (
auto dir: *dir_list)
482 buf << dir.filename << std::endl;
486 std::regex file_whitelist(
"^.\\.(airplane|boat|car|fixed|load|machine|skin|terrn2|train|truck)$", std::regex::icase);
488 auto file_list = Ogre::ResourceGroupManager::getSingleton().listResourceFileInfo(
RGN_CONTENT,
false);
489 for (
auto file: *file_list)
491 if ((file.archive !=
nullptr) || std::regex_match(file.filename, file_whitelist))
493 buf << file.filename << std::endl;
504 Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, rg_name);
505 Ogre::String json_str = stream->getAsString();
506 rapidjson::MemoryStream j_stream(json_str.data(), json_str.length());
507 j_doc.ParseStream<rapidjson::kParseNanAndInfFlag>(j_stream);
509 catch (Ogre::FileNotFoundException)
513 catch (std::exception& e)
515 RoR::LogFormat(
"[RoR] Failed to open or read json file '%s' (resource group '%s'), message: '%s'",
516 filename.c_str(), rg_name.c_str(), e.what());
520 if (j_doc.HasParseError())
522 RoR::LogFormat(
"[RoR] Error parsing JSON file '%s' (resource group '%s')",
523 filename.c_str(), rg_name.c_str());
533 rapidjson::StringBuffer buffer;
534 rapidjson::Writer<rapidjson::StringBuffer, rapidjson::UTF8<>, rapidjson::UTF8<>,
535 rapidjson::CrtAllocator, rapidjson::kWriteNanAndInfFlag>
537 j_doc.Accept(writer);
542 Ogre::DataStreamPtr stream
543 = Ogre::ResourceGroupManager::getSingleton().createResource(
544 filename, rg_name,
true);
545 size_t written = stream->write(buffer.GetString(), buffer.GetSize());
546 if (written < buffer.GetSize())
548 RoR::LogFormat(
"[RoR] Error writing JSON file '%s' (resource group '%s'), ",
549 "only written %u out of %u bytes!",
550 filename.c_str(), rg_name.c_str(), written, buffer.GetSize());
555 catch (std::exception& e)
557 RoR::LogFormat(
"[RoR] Error writing JSON file '%s' (resource group '%s'), message: '%s'",
558 filename.c_str(), rg_name.c_str(), e.what());
567 Ogre::ResourceGroupManager::getSingleton().deleteResource(filename, rg_name);
570 catch (std::exception& e)
572 RoR::LogFormat(
"[RoR|ModCache] Error deleting file '%s' (resource group '%s'), message: '%s'",
573 filename.c_str(), rg_name.c_str(), e.what());
Central state/object manager and communications hub.
#define RGN_REPO_ATTACHMENTS
#define RGN_SERVER_SCRIPTS
void LOG(const char *msg)
Legacy alias - formerly a macro.
A database of user-installed content alias 'mods' (vehicles, terrains...)
#define DECLARE_RESOURCE_PACK(_FIELD_, _NAME_, _RESOURCE_GROUP_)
Factory for creating TextAreaOverlayElement instances.
Factory class for DeflectorPlaneAffector.
Factory class for DeflectorPlaneAffector.
Factory class for ShaderParticleRenderer.
std::string const & getStr() const
CacheValidity EvaluateCacheValidity()
const std::vector< std::string > & GetContentDirs() const
void LoadModCache(CacheValidity validity)
bool resourceCollision(Ogre::Resource *resource, Ogre::ResourceManager *resourceManager) override
bool m_base_resource_loaded
Ogre::DataStreamPtr resourceLoading(const Ogre::String &name, const Ogre::String &group, Ogre::Resource *resource) override
void AddResourcePack(ResourcePack const &resource_pack, std::string const &override_rgn="")
Loads resources if not already loaded.
bool handleEvent(Ogre::ScriptCompiler *compiler, Ogre::ScriptCompilerEvent *evt, void *retval) override
bool DeleteDiskFile(std::string const &filename, std::string const &rg_name)
bool LoadAndParseJson(std::string const &filename, std::string const &rg_name, rapidjson::Document &j_doc)
bool SerializeAndWriteJson(std::string const &filename, std::string const &rg_name, rapidjson::Document &j_doc)
void resourceStreamOpened(const Ogre::String &name, const Ogre::String &group, Ogre::Resource *resource, Ogre::DataStreamPtr &dataStream) override
void InitModCache(CacheValidity validity)
void InitContentManager()
std::string ListAllUserContent()
Used by ModCache for quick detection of added/removed content.
void LoadGameplayResources()
Checks GVar settings and loads required resources.
void InitManagedMaterials(std::string const &rg_name)
void setLoadingBaseSounds(bool value)
bool FolderExists(const char *path)
Path must be UTF-8 encoded.
std::string PathCombine(std::string a, std::string b)
bool FileExists(const char *path)
Path must be UTF-8 encoded.
CVar * sys_repo_attachments_dir
SoundScriptManager * GetSoundScriptManager()
CVar * sys_server_scripts_dir
CVar * gfx_vegetation_mode
CacheSystem * GetCacheSystem()
CVar * gfx_texture_filter
void CreateSoundScriptManager()
CVar * sys_thumbnails_dir
CVar * app_extra_mod_path
void LogFormat(const char *format,...)
Improved logging utility. Uses fixed 2Kb buffer.
@ CAELUM
Caelum (best looking, slower)
@ SKYX
SkyX (best looking, slower)
static const ResourcePack HYDRAX
static const ResourcePack DASHBOARDS
static const ResourcePack OVERLAYS
static const ResourcePack PARTICLES
static const ResourcePack TEXTURES
static const ResourcePack MESHES
const char * resource_group_name
static const ResourcePack SOUNDS
static const ResourcePack MYGUI
static const ResourcePack AIRFOILS
static const ResourcePack SKYX
static const ResourcePack CAELUM
static const ResourcePack FAMICONS
static const ResourcePack MATERIALS
static const ResourcePack PAGED