diff --git a/doomsday/client/include/dd_main.h b/doomsday/client/include/dd_main.h index 30613b040b..5305b721f5 100644 --- a/doomsday/client/include/dd_main.h +++ b/doomsday/client/include/dd_main.h @@ -131,14 +131,8 @@ boolean DD_ExchangeGamePluginEntryPoints(pluginid_t pluginId); */ void* DD_FindEntryPoint(pluginid_t pluginId, const char* fn); -void DD_CreateResourceClasses(); - -void DD_ClearResourceClasses(); - namespace de { - typedef QList ResourceClasses; - /// Map of symbolic file type names to file types. typedef QMap FileTypes; } @@ -162,24 +156,6 @@ de::FileType& DD_GuessFileTypeFromFileName(de::String name); /// Returns the registered file types for efficient traversal. de::FileTypes const& DD_FileTypes(); -/** - * Lookup a ResourceClass by id. - * - * @todo Refactor away. - * - * @param classId Unique identifier of the class. - * @return ResourceClass associated with @a id. - */ -de::ResourceClass& DD_ResourceClassById(resourceclassid_t classId); - -/** - * Lookup a ResourceClass by symbolic name. - * - * @param name Symbolic name of the class. - * @return ResourceClass associated with @a name; otherwise @c 0 (not found). - */ -de::ResourceClass& DD_ResourceClassByName(de::String name); - /// @return Symbolic name of the material scheme associated with @a textureSchemeName. de::String DD_MaterialSchemeNameForTextureScheme(de::String textureSchemeName); diff --git a/doomsday/client/include/resource/resourcesystem.h b/doomsday/client/include/resource/resourcesystem.h index 16834f7393..2cb2eee50e 100644 --- a/doomsday/client/include/resource/resourcesystem.h +++ b/doomsday/client/include/resource/resourcesystem.h @@ -20,6 +20,8 @@ #define DENG_RESOURCESYSTEM_H #include +#include +#include "resourceclass.h" #include "Textures" /** @@ -27,13 +29,30 @@ */ class ResourceSystem : public de::System { +public: + /// An unknown resource class identifier was specified. @ingroup errors + DENG2_ERROR(UnknownResourceClass); + public: ResourceSystem(); + /** + * Lookup a ResourceClass by symbolic @a name. + */ + de::ResourceClass &resClass(de::String name); + + /** + * Lookup a ResourceClass by @a id. + * @todo Refactor away. + */ + de::ResourceClass &resClass(resourceclassid_t id); + + /** + * Provides access to the Textures collection. + */ de::Textures &textures(); void clearRuntimeTextureSchemes(); - void clearSystemTextureSchemes(); // System. diff --git a/doomsday/client/include/resourceclass.h b/doomsday/client/include/resourceclass.h index 42a7d416cb..f3146f5446 100644 --- a/doomsday/client/include/resourceclass.h +++ b/doomsday/client/include/resourceclass.h @@ -27,7 +27,7 @@ #include "api_resourceclass.h" #ifdef __cplusplus -#ifndef DENG2_C_API_ONLY +//#ifndef DENG2_C_API_ONLY #include #include @@ -128,7 +128,8 @@ namespace de } } // namespace de -#endif // DENG2_C_API_ONLY + +//#endif // DENG2_C_API_ONLY #endif // __cplusplus #endif /* LIBDENG_RESOURCECLASS_H */ diff --git a/doomsday/client/src/audio/s_cache.cpp b/doomsday/client/src/audio/s_cache.cpp index 6a220c3f9e..014b69dfd4 100644 --- a/doomsday/client/src/audio/s_cache.cpp +++ b/doomsday/client/src/audio/s_cache.cpp @@ -556,7 +556,7 @@ static sfxsample_t *cacheSample(int id, sfxinfo_t const *info) try { String foundPath = App_FileSystem().findPath(de::Uri(info->lumpName, RC_SOUND), - RLF_DEFAULT, DD_ResourceClassById(RC_SOUND)); + RLF_DEFAULT, App_ResourceSystem().resClass(RC_SOUND)); foundPath = App_BasePath() / foundPath; // Ensure the path is absolute. data = WAV_Load(foundPath.toUtf8().constData(), &bytesPer, &rate, &numSamples); diff --git a/doomsday/client/src/audio/s_mus.cpp b/doomsday/client/src/audio/s_mus.cpp index 5f182d3dbd..5ed62bfccf 100644 --- a/doomsday/client/src/audio/s_mus.cpp +++ b/doomsday/client/src/audio/s_mus.cpp @@ -254,7 +254,7 @@ int Mus_GetExt(ded_music_t *def, ddstring_t *retPath) try { String foundPath = App_FileSystem().findPath(de::Uri(def->lumpName, RC_MUSIC), RLF_DEFAULT, - DD_ResourceClassById(RC_MUSIC)); + App_ResourceSystem().resClass(RC_MUSIC)); foundPath = App_BasePath() / foundPath; // Ensure the path is absolute. // Does the caller want to know the matched path? diff --git a/doomsday/client/src/dd_main.cpp b/doomsday/client/src/dd_main.cpp index 62dc4ca187..0c26f654d0 100644 --- a/doomsday/client/src/dd_main.cpp +++ b/doomsday/client/src/dd_main.cpp @@ -165,8 +165,6 @@ finaleid_t titleFinale; int gameDataFormat; // Use a game-specifc data format where applicable. static NullFileType nullFileType; -static NullResourceClass nullResourceClass; -static ResourceClasses resourceClasses; /// A symbolic name => file type map. static FileTypes fileTypeMap; @@ -227,51 +225,6 @@ void App_DeleteMaterials() materials = 0; } -void DD_CreateResourceClasses() -{ - resourceClasses.push_back(new ResourceClass("RC_PACKAGE", "Packages")); - resourceClasses.push_back(new ResourceClass("RC_DEFINITION", "Defs")); - resourceClasses.push_back(new ResourceClass("RC_GRAPHIC", "Graphics")); - resourceClasses.push_back(new ResourceClass("RC_MODEL", "Models")); - resourceClasses.push_back(new ResourceClass("RC_SOUND", "Sfx")); - resourceClasses.push_back(new ResourceClass("RC_MUSIC", "Music")); - resourceClasses.push_back(new ResourceClass("RC_FONT", "Fonts")); -} - -void DD_ClearResourceClasses() -{ - DENG2_FOR_EACH(ResourceClasses, i, resourceClasses) - { - delete *i; - } - resourceClasses.clear(); -} - -ResourceClass& DD_ResourceClassByName(String name) -{ - if(!name.isEmpty()) - { - DENG2_FOR_EACH_CONST(ResourceClasses, i, resourceClasses) - { - ResourceClass& rclass = **i; - if(!rclass.name().compareWithoutCase(name)) - return rclass; - } - } - return nullResourceClass; // Not found. -} - -ResourceClass& DD_ResourceClassById(resourceclassid_t id) -{ - if(id == RC_NULL) return nullResourceClass; - if(!VALID_RESOURCECLASSID(id)) - { - QByteArray msg = String("DD_ResourceClassById: Invalid id '%1'").arg(int(id)).toUtf8(); - App_FatalError(msg.constData()); - } - return *resourceClasses[uint(id)]; -} - void DD_CreateFileTypes() { FileType* ftype; @@ -279,7 +232,7 @@ void DD_CreateFileTypes() /* * Packages types: */ - ResourceClass& packageClass = DD_ResourceClassByName("RC_PACKAGE"); + ResourceClass& packageClass = App_ResourceSystem().resClass("RC_PACKAGE"); ftype = new ZipFileType(); ftype->addKnownExtension(".pk3"); @@ -301,13 +254,13 @@ void DD_CreateFileTypes() */ ftype = new FileType("FT_DED", RC_DEFINITION); ftype->addKnownExtension(".ded"); - DD_ResourceClassByName("RC_DEFINITION").addFileType(*ftype); + App_ResourceSystem().resClass("RC_DEFINITION").addFileType(*ftype); fileTypeMap.insert(ftype->name().toLower(), ftype); /* * Graphic fileTypes: */ - ResourceClass& graphicClass = DD_ResourceClassByName("RC_GRAPHIC"); + ResourceClass& graphicClass = App_ResourceSystem().resClass("RC_GRAPHIC"); ftype = new FileType("FT_PNG", RC_GRAPHIC); ftype->addKnownExtension(".png"); @@ -332,7 +285,7 @@ void DD_CreateFileTypes() /* * Model fileTypes: */ - ResourceClass& modelClass = DD_ResourceClassByName("RC_MODEL"); + ResourceClass& modelClass = App_ResourceSystem().resClass("RC_MODEL"); ftype = new FileType("FT_DMD", RC_MODEL); ftype->addKnownExtension(".dmd"); @@ -349,13 +302,13 @@ void DD_CreateFileTypes() */ ftype = new FileType("FT_WAV", RC_SOUND); ftype->addKnownExtension(".wav"); - DD_ResourceClassByName("RC_SOUND").addFileType(*ftype); + App_ResourceSystem().resClass("RC_SOUND").addFileType(*ftype); fileTypeMap.insert(ftype->name().toLower(), ftype); /* * Music fileTypes: */ - ResourceClass& musicClass = DD_ResourceClassByName("RC_MUSIC"); + ResourceClass& musicClass = App_ResourceSystem().resClass("RC_MUSIC"); ftype = new FileType("FT_OGG", RC_MUSIC); ftype->addKnownExtension(".ogg"); @@ -382,7 +335,7 @@ void DD_CreateFileTypes() */ ftype = new FileType("FT_DFN", RC_FONT); ftype->addKnownExtension(".dfn"); - DD_ResourceClassByName("RC_FONT").addFileType(*ftype); + App_ResourceSystem().resClass("RC_FONT").addFileType(*ftype); fileTypeMap.insert(ftype->name().toLower(), ftype); /* @@ -569,7 +522,7 @@ ResourceSystem &App_ResourceSystem() return ServerApp::resourceSystem(); } #endif - throw Error("App_Textures", "App not yet initialized"); + throw Error("App_ResourceSystem", "App not yet initialized"); } de::Textures &App_Textures() @@ -1855,7 +1808,6 @@ boolean DD_Init(void) // Initialize the subsystems needed prior to entering busy mode for the first time. Sys_Init(); - DD_CreateResourceClasses(); DD_CreateFileTypes(); F_Init(); DD_CreateFileSystemSchemes(); @@ -1884,7 +1836,7 @@ boolean DD_Init(void) DD_DummyWorker, 0, "Buffering..."); // Add resource paths specified using -iwad on the command line. - FS1::Scheme& scheme = App_FileSystem().scheme(DD_ResourceClassByName("RC_PACKAGE").defaultScheme()); + FS1::Scheme& scheme = App_FileSystem().scheme(App_ResourceSystem().resClass("RC_PACKAGE").defaultScheme()); for(int p = 0; p < CommandLine_Count(); ++p) { if(!CommandLine_IsMatchingAlias("-iwad", CommandLine_At(p))) @@ -2142,7 +2094,7 @@ static int DD_StartupWorker(void* /*parm*/) * Add required engine resource files. */ String foundPath = App_FileSystem().findPath(de::Uri("doomsday.pk3", RC_PACKAGE), - RLF_DEFAULT, DD_ResourceClassById(RC_PACKAGE)); + RLF_DEFAULT, App_ResourceSystem().resClass(RC_PACKAGE)); foundPath = App_BasePath() / foundPath; // Ensure the path is absolute. de::File1 *loadedFile = tryLoadFile(de::Uri(foundPath, RC_NULL)); DENG2_ASSERT(loadedFile != 0); @@ -2759,7 +2711,7 @@ D_CMD(Load) try { String foundPath = App_FileSystem().findPath(de::Uri::fromNativePath(argv[arg], RC_PACKAGE), - RLF_MATCH_EXTENSION, DD_ResourceClassById(RC_PACKAGE)); + RLF_MATCH_EXTENSION, App_ResourceSystem().resClass(RC_PACKAGE)); foundPath = App_BasePath() / foundPath; // Ensure the path is absolute. if(tryLoadFile(de::Uri(foundPath, RC_NULL))) @@ -2886,7 +2838,7 @@ D_CMD(Unload) try { String foundPath = App_FileSystem().findPath(de::Uri::fromNativePath(argv[1], RC_PACKAGE), - RLF_MATCH_EXTENSION, DD_ResourceClassById(RC_PACKAGE)); + RLF_MATCH_EXTENSION, App_ResourceSystem().resClass(RC_PACKAGE)); foundPath = App_BasePath() / foundPath; // Ensure the path is absolute. if(tryUnloadFile(de::Uri(foundPath, RC_NULL))) diff --git a/doomsday/client/src/dd_pinit.cpp b/doomsday/client/src/dd_pinit.cpp index e94edd8e2b..b4b51461bc 100644 --- a/doomsday/client/src/dd_pinit.cpp +++ b/doomsday/client/src/dd_pinit.cpp @@ -168,6 +168,5 @@ void DD_ShutdownAll(void) Def_Destroy(); F_Shutdown(); - DD_ClearResourceClasses(); Libdeng_Shutdown(); } diff --git a/doomsday/client/src/def_main.cpp b/doomsday/client/src/def_main.cpp index e26752cb11..d226925937 100644 --- a/doomsday/client/src/def_main.cpp +++ b/doomsday/client/src/def_main.cpp @@ -840,7 +840,7 @@ static void readAllDefinitions() * Start with engine's own top-level definition file. */ String foundPath = App_FileSystem().findPath(de::Uri("doomsday.ded", RC_DEFINITION), - RLF_DEFAULT, DD_ResourceClassById(RC_DEFINITION)); + RLF_DEFAULT, App_ResourceSystem().resClass(RC_DEFINITION)); foundPath = App_BasePath() / foundPath; // Ensure the path is absolute. readDefinitionFile(foundPath); @@ -1429,7 +1429,7 @@ void Def_Read() { // We've already initialized the definitions once. // Get rid of everything. - FS1::Scheme &scheme = App_FileSystem().scheme(DD_ResourceClassByName("RC_MODEL").defaultScheme()); + FS1::Scheme &scheme = App_FileSystem().scheme(App_ResourceSystem().resClass("RC_MODEL").defaultScheme()); scheme.reset(); invalidateAllMaterials(); diff --git a/doomsday/client/src/def_read.cpp b/doomsday/client/src/def_read.cpp index 454d6e7e83..d4da84073b 100644 --- a/doomsday/client/src/def_read.cpp +++ b/doomsday/client/src/def_read.cpp @@ -813,7 +813,7 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile) CHECKSC; de::Uri newSearchPath = de::Uri::fromNativeDirPath(NativePath(label)); - FS1::Scheme& scheme = App_FileSystem().scheme(DD_ResourceClassByName("RC_MODEL").defaultScheme()); + FS1::Scheme& scheme = App_FileSystem().scheme(App_ResourceSystem().resClass("RC_MODEL").defaultScheme()); scheme.addSearchPath(reinterpret_cast(newSearchPath), FS1::ExtraPaths); } diff --git a/doomsday/client/src/filesys/fs_main.cpp b/doomsday/client/src/filesys/fs_main.cpp index b7b096aa18..b28c051145 100644 --- a/doomsday/client/src/filesys/fs_main.cpp +++ b/doomsday/client/src/filesys/fs_main.cpp @@ -618,7 +618,7 @@ String FS1::findPath(de::Uri const& search, int flags, ResourceClass& rclass) String FS1::findPath(de::Uri const& search, int flags) { - return findPath(search, flags, DD_ResourceClassById(RC_NULL)); + return findPath(search, flags, App_ResourceSystem().resClass(RC_NULL)); } #if _DEBUG diff --git a/doomsday/client/src/filesys/manifest.cpp b/doomsday/client/src/filesys/manifest.cpp index 67e8134a2f..c49b88b92e 100644 --- a/doomsday/client/src/filesys/manifest.cpp +++ b/doomsday/client/src/filesys/manifest.cpp @@ -272,7 +272,7 @@ ResourceManifest &ResourceManifest::locateFile() try { String foundPath = App_FileSystem().findPath(de::Uri(*i, d->classId), - RLF_DEFAULT, DD_ResourceClassById(d->classId)); + RLF_DEFAULT, App_ResourceSystem().resClass(d->classId)); foundPath = App_BasePath() / foundPath; // Ensure the path is absolute. // Perform identity validation. diff --git a/doomsday/client/src/gl/gl_texmanager.cpp b/doomsday/client/src/gl/gl_texmanager.cpp index e318c38236..08172ee882 100644 --- a/doomsday/client/src/gl/gl_texmanager.cpp +++ b/doomsday/client/src/gl/gl_texmanager.cpp @@ -1760,7 +1760,7 @@ static TexSource loadExternalTexture(image_t &image, String encodedSearchPath, try { String foundPath = App_FileSystem().findPath(de::Uri(encodedSearchPath + optionalSuffix, RC_GRAPHIC), - RLF_DEFAULT, DD_ResourceClassById(RC_GRAPHIC)); + RLF_DEFAULT, App_ResourceSystem().resClass(RC_GRAPHIC)); // Ensure the found path is absolute. foundPath = App_BasePath() / foundPath; @@ -1775,7 +1775,7 @@ static TexSource loadExternalTexture(image_t &image, String encodedSearchPath, try { String foundPath = App_FileSystem().findPath(de::Uri(encodedSearchPath, RC_GRAPHIC), - RLF_DEFAULT, DD_ResourceClassById(RC_GRAPHIC)); + RLF_DEFAULT, App_ResourceSystem().resClass(RC_GRAPHIC)); // Ensure the found path is absolute. foundPath = App_BasePath() / foundPath; @@ -1904,7 +1904,7 @@ TexSource GL_LoadExtImage(image_t &image, char const *_searchPath, gfxmode_t mod try { String foundPath = App_FileSystem().findPath(de::Uri(RC_GRAPHIC, _searchPath), - RLF_DEFAULT, DD_ResourceClassById(RC_GRAPHIC)); + RLF_DEFAULT, App_ResourceSystem().resClass(RC_GRAPHIC)); // Ensure the found path is absolute. foundPath = App_BasePath() / foundPath; @@ -2182,7 +2182,7 @@ static TexSource loadRaw(image_t &image, rawtex_t const &raw) try { String foundPath = App_FileSystem().findPath(de::Uri("Patches", Path(Str_Text(&raw.name))), - RLF_DEFAULT, DD_ResourceClassById(RC_GRAPHIC)); + RLF_DEFAULT, App_ResourceSystem().resClass(RC_GRAPHIC)); // Ensure the found path is absolute. foundPath = App_BasePath() / foundPath; diff --git a/doomsday/client/src/render/rend_particle.cpp b/doomsday/client/src/render/rend_particle.cpp index 2bdb3e9f42..a18c284b51 100644 --- a/doomsday/client/src/render/rend_particle.cpp +++ b/doomsday/client/src/render/rend_particle.cpp @@ -111,7 +111,7 @@ static Path tryFindImage(String name) try { String foundPath = App_FileSystem().findPath(de::Uri("Textures", name + "-ck"), - RLF_DEFAULT, DD_ResourceClassById(RC_GRAPHIC)); + RLF_DEFAULT, App_ResourceSystem().resClass(RC_GRAPHIC)); // Ensure the path is absolute. return App_BasePath() / foundPath; } @@ -124,7 +124,7 @@ static Path tryFindImage(String name) try { String foundPath = App_FileSystem().findPath(de::Uri("Textures", name), - RLF_DEFAULT, DD_ResourceClassById(RC_GRAPHIC)); + RLF_DEFAULT, App_ResourceSystem().resClass(RC_GRAPHIC)); // Ensure the path is absolute. return App_BasePath() / foundPath; } diff --git a/doomsday/client/src/resource/models.cpp b/doomsday/client/src/resource/models.cpp index da0464998d..1cb7184190 100644 --- a/doomsday/client/src/resource/models.cpp +++ b/doomsday/client/src/resource/models.cpp @@ -505,7 +505,7 @@ static String findSkinPath(Path const &skinPath, Path const &modelFilePath) try { de::Uri searchPath("Models", modelFilePath.toString().fileNamePath() / skinPath.fileName()); - return App_FileSystem().findPath(searchPath, RLF_DEFAULT, DD_ResourceClassById(RC_GRAPHIC)); + return App_FileSystem().findPath(searchPath, RLF_DEFAULT, App_ResourceSystem().resClass(RC_GRAPHIC)); } catch(FS1::NotFoundError const &) {} // Ignore this error. @@ -513,7 +513,7 @@ static String findSkinPath(Path const &skinPath, Path const &modelFilePath) /// @throws FS1::NotFoundError if no resource was found. de::Uri searchPath("Models", skinPath); - return App_FileSystem().findPath(searchPath, RLF_DEFAULT, DD_ResourceClassById(RC_GRAPHIC)); + return App_FileSystem().findPath(searchPath, RLF_DEFAULT, App_ResourceSystem().resClass(RC_GRAPHIC)); } /** @@ -578,7 +578,7 @@ static void defineAllSkins(model_t &mdl) try { String foundPath = App_FileSystem().findPath(searchPath, RLF_DEFAULT, - DD_ResourceClassById(RC_GRAPHIC)); + App_ResourceSystem().resClass(RC_GRAPHIC)); // Ensure the found path is absolute. foundPath = App_BasePath() / foundPath; @@ -1091,7 +1091,7 @@ static void setupModel(ded_model_t& def) try { String foundPath = App_FileSystem().findPath(searchPath, RLF_DEFAULT, - DD_ResourceClassById(RC_MODEL)); + App_ResourceSystem().resClass(RC_MODEL)); // Ensure the found path is absolute. foundPath = App_BasePath() / foundPath; diff --git a/doomsday/client/src/resource/resourcesystem.cpp b/doomsday/client/src/resource/resourcesystem.cpp index c03f6586e3..113ca8cb0f 100644 --- a/doomsday/client/src/resource/resourcesystem.cpp +++ b/doomsday/client/src/resource/resourcesystem.cpp @@ -18,16 +18,29 @@ #include "resource/resourcesystem.h" #include +#include +#include using namespace de; DENG2_PIMPL(ResourceSystem) { + typedef QList ResourceClasses; + NullResourceClass nullResourceClass; + ResourceClasses resClasses; + Textures textures; Instance(Public *i) : Base(i) { LOG_AS("ResourceSystem"); + resClasses.append(new ResourceClass("RC_PACKAGE", "Packages")); + resClasses.append(new ResourceClass("RC_DEFINITION", "Defs")); + resClasses.append(new ResourceClass("RC_GRAPHIC", "Graphics")); + resClasses.append(new ResourceClass("RC_MODEL", "Models")); + resClasses.append(new ResourceClass("RC_SOUND", "Sfx")); + resClasses.append(new ResourceClass("RC_MUSIC", "Music")); + resClasses.append(new ResourceClass("RC_FONT", "Fonts")); LOG_MSG("Initializing Texture collection..."); /// @note Order here defines the ambigious-URI search order. @@ -44,6 +57,11 @@ DENG2_PIMPL(ResourceSystem) textures.createScheme("Lightmaps"); textures.createScheme("Flaremaps"); } + + ~Instance() + { + qDeleteAll(resClasses); + } }; ResourceSystem::ResourceSystem() : d(new Instance(this)) @@ -54,6 +72,30 @@ void ResourceSystem::timeChanged(Clock const &) // Nothing to do. } +ResourceClass &ResourceSystem::resClass(String name) +{ + if(!name.isEmpty()) + { + foreach(ResourceClass *resClass, d->resClasses) + { + if(!resClass->name().compareWithoutCase(name)) + return *resClass; + } + } + return d->nullResourceClass; // Not found. +} + +ResourceClass &ResourceSystem::resClass(resourceclassid_t id) +{ + if(id == RC_NULL) return d->nullResourceClass; + if(VALID_RESOURCECLASSID(id)) + { + return *d->resClasses.at(uint(id)); + } + /// @throw UnknownResourceClass Attempted with an unknown id. + throw UnknownResourceClass("ResourceSystem::toClass", QString("Invalid id '%1'").arg(int(id))); +} + Textures &ResourceSystem::textures() { return d->textures; diff --git a/doomsday/client/src/uri.cpp b/doomsday/client/src/uri.cpp index cd121ac5ed..fdae4b28b0 100644 --- a/doomsday/client/src/uri.cpp +++ b/doomsday/client/src/uri.cpp @@ -121,7 +121,7 @@ DENG2_PIMPL_NOREF(Uri) if(VALID_RESOURCECLASSID(defaultResourceClass)) { - FS1::Scheme &fsScheme = App_FileSystem().scheme(DD_ResourceClassById(defaultResourceClass).defaultScheme()); + FS1::Scheme &fsScheme = App_FileSystem().scheme(App_ResourceSystem().resClass(defaultResourceClass).defaultScheme()); scheme = fsScheme.name(); } }