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_);
68#define DECLARE_RESOURCE_PACK(_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(
159 Ogre::ScriptCompilerManager::getSingleton().setListener(
this);
168 if (!Ogre::ResourceGroupManager::getSingleton().getLoadingListener())
169 Ogre::ResourceGroupManager::getSingleton().setLoadingListener(
this);
182 LOG(
"RoR|ContentManager: Registering Particle Box Emitter");
184 ParticleSystemManager::getSingleton().addRendererFactory(mParticleSystemRendererFact);
193#ifdef USE_ANGELSCRIPT
196 ParticleSystemManager::getSingleton().addAffectorFactory(pAffFact);
200 ParticleSystemManager::getSingleton().addAffectorFactory(pAffFact);
205 LOG(
"RoR|ContentManager: Creating Sound Manager");
213 LOG(
"RoR|ContentManager: Loading filesystems");
215 LOG(
"RoR|ContentManager: Registering colored text overlay factory");
217 OverlayManager::getSingleton().addOverlayElementFactory(pCT);
220 if (TextureManager::getSingletonPtr())
221 TextureManager::getSingleton().setDefaultNumMipmaps(5);
223 TextureFilterOptions tfo = TFO_NONE;
231 MaterialManager::getSingleton().setDefaultAnisotropy(Math::Clamp(
App::gfx_anisotropy->getInt(), 1, 16));
232 MaterialManager::getSingleton().setDefaultTextureFiltering(tfo);
235 LOG(
"RoR|ContentManager: Calling initialiseAllResourceGroups()");
238 ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
240 catch (Ogre::Exception& e)
242 LOG(
"RoR|ContentManager: catched error while initializing Resource groups: " + e.getFullDescription());
248 new Ogre::MeshLodGenerator();
262 ResourceGroupManager::getSingleton().addResourceLocation(
264 ResourceGroupManager::getSingleton().addResourceLocation(
266 ResourceGroupManager::getSingleton().addResourceLocation(
274 ResourceGroupManager::getSingleton().addResourceLocation(extra_mod_path ,
"FileSystem",
RGN_CONTENT);
281 std::string objects =
PathCombine(
"resources",
"beamobjects.zip");
283 std::string dashboards =
PathCombine(
"resources",
"dashboards.zip");
285 std::string gadgets =
PathCombine(
"resources",
"gadgets.zip");
290 ResourceGroupManager::getSingleton().createResourceGroup(
RGN_TEMP,
false);
294 ResourceGroupManager::getSingleton().addResourceLocation(extra_mod_path ,
"FileSystem",
RGN_TEMP,
true);
305 FileInfoListPtr dirs = ResourceGroupManager::getSingleton().findResourceFileInfo(
RGN_TEMP,
"*",
true);
306 for (
const auto& dir_fileinfo : *dirs)
308 if (!dir_fileinfo.archive)
310 String fullpath =
PathCombine(dir_fileinfo.archive->getName(), dir_fileinfo.filename);
311 ResourceGroupManager::getSingleton().addResourceLocation(fullpath,
"FileSystem",
RGN_CONTENT,
false,
false);
313 ResourceGroupManager::getSingleton().destroyResourceGroup(
RGN_TEMP);
323 ResourceGroupManager::getSingleton().destroyResourceGroup(
RGN_CONTENT);
329 return Ogre::DataStreamPtr();
343 RoR::LogFormat(
"[RoR|ContentManager] Skipping resource with duplicate name: '%s' (origin: '%s')",
344 resource->getName().c_str(), resource->getOrigin().c_str());
350 if (evt->mType == CreateMaterialScriptCompilerEvent::eventType)
354 auto* matEvent =
static_cast<CreateMaterialScriptCompilerEvent*
>(evt);
355 if (matEvent->mName.empty())
357 RoR::LogFormat(
"[RoR] Got malformed material (empty name) from file: '%s' - forcing OGRE to fail loading.",
358 matEvent->mFile.c_str());
364 else if (evt->mType == CreateParticleSystemScriptCompilerEvent::eventType)
368 auto* particleEvent =
static_cast<CreateParticleSystemScriptCompilerEvent*
>(evt);
369 if (Ogre::ParticleSystemManager::getSingleton().getTemplate(particleEvent->mName) !=
nullptr)
372 RoR::LogFormat(
"[RoR] Duplicate particle system name '%s' in file: '%s' - forcing OGRE to fail loading.",
373 particleEvent->mName.c_str(), particleEvent->mFile.c_str());
390 ResourceGroupManager::getSingleton().addResourceLocation(
PathCombine(managed_materials_dir,
"shadows/pssm/on/shared"),
"FileSystem", rg_name);
392 ResourceGroupManager::getSingleton().addResourceLocation(
PathCombine(managed_materials_dir,
"shadows/pssm/on"),
"FileSystem", rg_name);
396 ResourceGroupManager::getSingleton().addResourceLocation(
PathCombine(managed_materials_dir,
"shadows/pssm/off"),
"FileSystem", rg_name);
399 ResourceGroupManager::getSingleton().addResourceLocation(
PathCombine(managed_materials_dir,
"texture"),
"FileSystem", rg_name);
402 ResourceGroupManager::getSingleton().addResourceLocation(managed_materials_dir,
"FileSystem", rg_name);
405 ResourceGroupManager::getSingleton().initialiseResourceGroup(rg_name);
438 std::stringstream buf;
440 auto dir_list = Ogre::ResourceGroupManager::getSingleton().listResourceFileInfo(
RGN_CONTENT,
true);
441 for (
auto dir: *dir_list)
443 buf << dir.filename << std::endl;
447 std::regex file_whitelist(
"^.\\.(airplane|boat|car|fixed|load|machine|skin|terrn2|train|truck)$", std::regex::icase);
449 auto file_list = Ogre::ResourceGroupManager::getSingleton().listResourceFileInfo(
RGN_CONTENT,
false);
450 for (
auto file: *file_list)
452 if ((file.archive !=
nullptr) || std::regex_match(file.filename, file_whitelist))
454 buf << file.filename << std::endl;
465 Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, rg_name);
466 Ogre::String json_str = stream->getAsString();
467 rapidjson::MemoryStream j_stream(json_str.data(), json_str.length());
468 j_doc.ParseStream<rapidjson::kParseNanAndInfFlag>(j_stream);
470 catch (Ogre::FileNotFoundException)
474 catch (std::exception& e)
476 RoR::LogFormat(
"[RoR] Failed to open or read json file '%s' (resource group '%s'), message: '%s'",
477 filename.c_str(), rg_name.c_str(), e.what());
481 if (j_doc.HasParseError())
483 RoR::LogFormat(
"[RoR] Error parsing JSON file '%s' (resource group '%s')",
484 filename.c_str(), rg_name.c_str());
494 rapidjson::StringBuffer buffer;
495 rapidjson::Writer<rapidjson::StringBuffer, rapidjson::UTF8<>, rapidjson::UTF8<>,
496 rapidjson::CrtAllocator, rapidjson::kWriteNanAndInfFlag>
498 j_doc.Accept(writer);
503 Ogre::DataStreamPtr stream
504 = Ogre::ResourceGroupManager::getSingleton().createResource(
505 filename, rg_name,
true);
506 size_t written = stream->write(buffer.GetString(), buffer.GetSize());
507 if (written < buffer.GetSize())
509 RoR::LogFormat(
"[RoR] Error writing JSON file '%s' (resource group '%s'), ",
510 "only written %u out of %u bytes!",
511 filename.c_str(), rg_name.c_str(), written, buffer.GetSize());
516 catch (std::exception& e)
518 RoR::LogFormat(
"[RoR] Error writing JSON file '%s' (resource group '%s'), message: '%s'",
519 filename.c_str(), rg_name.c_str(), e.what());
528 Ogre::ResourceGroupManager::getSingleton().deleteResource(filename, rg_name);
531 catch (std::exception& e)
533 RoR::LogFormat(
"[RoR|ModCache] Error deleting file '%s' (resource group '%s'), message: '%s'",
534 filename.c_str(), rg_name.c_str(), e.what());
Central state/object manager and communications hub.
#define RGN_REPO_ATTACHMENTS
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 * 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