From 3064eac0586fe899f2c507d3f3e0244a0a20e6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Thu, 28 Jul 2016 12:53:52 +0300 Subject: [PATCH] Refactor|Resources: Raw textures are used by the client only --- .../client/include/resource/clientresources.h | 5 +- doomsday/apps/client/src/dd_main.cpp | 2 +- doomsday/apps/client/src/gl/gl_main.cpp | 2 +- doomsday/apps/client/src/gl/gl_texmanager.cpp | 66 +++++++++---------- doomsday/apps/client/src/render/r_draw.cpp | 2 +- .../src/resource/base/clientresources.cpp | 19 +++--- .../client/src/ui/infine/finaleanimwidget.cpp | 2 +- .../src/ui/infine/finaleinterpreter.cpp | 25 ++++--- 8 files changed, 69 insertions(+), 54 deletions(-) diff --git a/doomsday/apps/client/include/resource/clientresources.h b/doomsday/apps/client/include/resource/clientresources.h index db321d71ef..f4631c4c64 100644 --- a/doomsday/apps/client/include/resource/clientresources.h +++ b/doomsday/apps/client/include/resource/clientresources.h @@ -101,6 +101,8 @@ class ClientResources : public Resources typedef QMap SpriteSet; ///< frame => Sprite + static ClientResources &get(); + public: /** * Construct a new resource system, configuring all resource classes and @@ -149,6 +151,8 @@ class ClientResources : public Resources patchid_t declarePatch(de::String encodedName); +#ifdef __CLIENT__ + /** * Returns a rawtex_t for the given lump if one already exists; otherwise @c 0. */ @@ -165,7 +169,6 @@ class ClientResources : public Resources */ QList collectRawTextures() const; -#ifdef __CLIENT__ /** * Determines if a manifest exists for a resource on @a path. * diff --git a/doomsday/apps/client/src/dd_main.cpp b/doomsday/apps/client/src/dd_main.cpp index 0100793a48..75b710cda3 100644 --- a/doomsday/apps/client/src/dd_main.cpp +++ b/doomsday/apps/client/src/dd_main.cpp @@ -1378,9 +1378,9 @@ static dint DD_UpdateEngineStateWorker(void *context) // // Rebuild resource data models (defs might've changed). // - App_ResourceSystem().clearAllRawTextures(); App_ResourceSystem().initSprites(); #ifdef __CLIENT__ + App_ResourceSystem().clearAllRawTextures(); App_ResourceSystem().initModels(); #endif Def_PostInit(); diff --git a/doomsday/apps/client/src/gl/gl_main.cpp b/doomsday/apps/client/src/gl/gl_main.cpp index 425d1d9502..69f8e7a67e 100644 --- a/doomsday/apps/client/src/gl/gl_main.cpp +++ b/doomsday/apps/client/src/gl/gl_main.cpp @@ -945,7 +945,7 @@ void GL_SetPSprite(world::Material *material, dint tClass, dint tMap) void GL_SetRawImage(lumpnum_t lumpNum, gl::Wrapping wrapS, gl::Wrapping wrapT) { - if(rawtex_t *rawTex = resSys().declareRawTexture(lumpNum)) + if(rawtex_t *rawTex = ClientResources::get().declareRawTexture(lumpNum)) { GL_BindTextureUnmanaged(GL_PrepareRawTexture(*rawTex), wrapS, wrapT, (filterUI ? gl::Linear : gl::Nearest)); diff --git a/doomsday/apps/client/src/gl/gl_texmanager.cpp b/doomsday/apps/client/src/gl/gl_texmanager.cpp index 1647eed307..d79f19f44e 100644 --- a/doomsday/apps/client/src/gl/gl_texmanager.cpp +++ b/doomsday/apps/client/src/gl/gl_texmanager.cpp @@ -61,7 +61,7 @@ static DGLuint sysFlareTextures[NUM_SYSFLARE_TEXTURES]; void GL_InitTextureManager() { - if(initedOk) + if (initedOk) { GL_LoadLightingSystemTextures(); GL_LoadFlareTextures(); @@ -97,7 +97,7 @@ static int reloadTextures(void *context) Rend_ParticleLoadSystemTextures(); Rend_ParticleLoadExtraTextures(); - if(usingBusyMode) + if (usingBusyMode) { Con_SetProgress(200); } @@ -106,13 +106,13 @@ static int reloadTextures(void *context) void GL_TexReset() { - if(!initedOk) return; + if (!initedOk) return; App_ResourceSystem().releaseAllGLTextures(); LOG_GL_VERBOSE("Released all GL textures"); bool useBusyMode = !BusyMode_Active(); - if(useBusyMode) + if (useBusyMode) { BusyMode_FreezeGameForBusyMode(); @@ -128,7 +128,7 @@ void GL_TexReset() void GL_LoadLightingSystemTextures() { - if(novideo || !initedOk) return; + if (novideo || !initedOk) return; // Preload lighting system textures. GL_PrepareLSTexture(LST_DYNAMIC); @@ -138,7 +138,7 @@ void GL_LoadLightingSystemTextures() void GL_ReleaseAllLightingSystemTextures() { - if(novideo || !initedOk) return; + if (novideo || !initedOk) return; glDeleteTextures(NUM_LIGHTING_TEXTURES, (GLuint const *) lightingTextures); zap(lightingTextures); @@ -146,8 +146,8 @@ void GL_ReleaseAllLightingSystemTextures() GLuint GL_PrepareLSTexture(lightingtexid_t which) { - if(novideo) return 0; - if(which < 0 || which >= NUM_LIGHTING_TEXTURES) return 0; + if (novideo) return 0; + if (which < 0 || which >= NUM_LIGHTING_TEXTURES) return 0; static const struct TexDef { char const *name; @@ -163,11 +163,11 @@ GLuint GL_PrepareLSTexture(lightingtexid_t which) }; struct TexDef const &def = texDefs[which]; - if(!lightingTextures[which]) + if (!lightingTextures[which]) { image_t image; - if(GL_LoadExtImage(image, def.name, def.mode)) + if (GL_LoadExtImage(image, def.name, def.mode)) { // Loaded successfully and converted accordingly. // Upload the image to GL. @@ -191,11 +191,11 @@ GLuint GL_PrepareLSTexture(lightingtexid_t which) void GL_LoadFlareTextures() { - if(novideo || !initedOk) return; + if (novideo || !initedOk) return; GL_PrepareSysFlaremap(FXT_ROUND); GL_PrepareSysFlaremap(FXT_FLARE); - if(!haloRealistic) + if (!haloRealistic) { GL_PrepareSysFlaremap(FXT_BRFLARE); GL_PrepareSysFlaremap(FXT_BIGFLARE); @@ -204,7 +204,7 @@ void GL_LoadFlareTextures() void GL_ReleaseAllFlareTextures() { - if(novideo || !initedOk) return; + if (novideo || !initedOk) return; glDeleteTextures(NUM_SYSFLARE_TEXTURES, (GLuint const *) sysFlareTextures); zap(sysFlareTextures); @@ -212,8 +212,8 @@ void GL_ReleaseAllFlareTextures() GLuint GL_PrepareSysFlaremap(flaretexid_t which) { - if(novideo) return 0; - if(which < 0 || which >= NUM_SYSFLARE_TEXTURES) return 0; + if (novideo) return 0; + if (which < 0 || which >= NUM_SYSFLARE_TEXTURES) return 0; static const struct TexDef { char const *name; @@ -225,11 +225,11 @@ GLuint GL_PrepareSysFlaremap(flaretexid_t which) }; struct TexDef const &def = texDefs[which]; - if(!sysFlareTextures[which]) + if (!sysFlareTextures[which]) { image_t image; - if(GL_LoadExtImage(image, def.name, LGM_WHITE_ALPHA)) + if (GL_LoadExtImage(image, def.name, LGM_WHITE_ALPHA)) { // Loaded successfully and converted accordingly. // Upload the image to GL. @@ -253,19 +253,19 @@ GLuint GL_PrepareSysFlaremap(flaretexid_t which) GLuint GL_PrepareFlaremap(de::Uri const &resourceUri) { - if(resourceUri.path().length() == 1) + if (resourceUri.path().length() == 1) { // Select a system flare by numeric identifier? int number = resourceUri.path().toStringRef().first().digitValue(); - if(number == 0) return 0; // automatic - if(number >= 1 && number <= 4) + if (number == 0) return 0; // automatic + if (number >= 1 && number <= 4) { return GL_PrepareSysFlaremap(flaretexid_t(number - 1)); } } - if(auto *tex = res::Textures::get().texture("Flaremaps", resourceUri)) + if (auto *tex = res::Textures::get().texture("Flaremaps", resourceUri)) { - if(TextureVariant const *variant = static_cast(tex)->prepareVariant(Rend_HaloTextureSpec())) + if (TextureVariant const *variant = static_cast(tex)->prepareVariant(Rend_HaloTextureSpec())) { return variant->glName(); } @@ -288,13 +288,13 @@ static res::Source loadRaw(image_t &image, rawtex_t const &raw) return GL_LoadImage(image, foundPath)? res::External : res::None; } - catch(FS1::NotFoundError const&) + catch (FS1::NotFoundError const&) {} // Ignore this error. try { FileHandle &file = fileSys.openLump(fileSys.lump(raw.lumpNum)); - if(Image_LoadFromFile(image, file)) + if (Image_LoadFromFile(image, file)) { fileSys.releaseFile(file.file()); delete &file; @@ -315,7 +315,7 @@ static res::Source loadRaw(image_t &image, rawtex_t const &raw) // Load the raw image data. size_t const numPels = RAW_WIDTH * RAW_HEIGHT; image.pixels = (uint8_t *) M_Malloc(3 * numPels); - if(fileLength < 3 * numPels) + if (fileLength < 3 * numPels) { std::memset(image.pixels, 0, 3 * numPels); } @@ -329,7 +329,7 @@ static res::Source loadRaw(image_t &image, rawtex_t const &raw) #undef RAW_HEIGHT #undef RAW_WIDTH } - catch(LumpIndex::NotFoundError const &) + catch (LumpIndex::NotFoundError const &) {} // Ignore error. return res::None; @@ -337,14 +337,14 @@ static res::Source loadRaw(image_t &image, rawtex_t const &raw) GLuint GL_PrepareRawTexture(rawtex_t &raw) { - if(raw.lumpNum < 0 || raw.lumpNum >= App_FileSystem().lumpCount()) return 0; + if (raw.lumpNum < 0 || raw.lumpNum >= App_FileSystem().lumpCount()) return 0; - if(!raw.tex) + if (!raw.tex) { image_t image; Image_Init(image); - if(loadRaw(image, raw) == res::External) + if (loadRaw(image, raw) == res::External) { // Loaded an external raw texture. raw.tex = GL_NewTextureWithParams(image.pixelSize == 4? DGL_RGBA : DGL_RGB, @@ -374,9 +374,9 @@ GLuint GL_PrepareRawTexture(rawtex_t &raw) void GL_SetRawTexturesMinFilter(int newMinFilter) { - foreach(rawtex_t *raw, App_ResourceSystem().collectRawTextures()) + foreach (rawtex_t *raw, App_ResourceSystem().collectRawTextures()) { - if(raw->tex) // Is the texture loaded? + if (raw->tex) // Is the texture loaded? { DENG_ASSERT_IN_MAIN_THREAD(); DENG_ASSERT_GL_CONTEXT_ACTIVE(); @@ -389,9 +389,9 @@ void GL_SetRawTexturesMinFilter(int newMinFilter) void GL_ReleaseTexturesForRawImages() { - foreach(rawtex_t *raw, App_ResourceSystem().collectRawTextures()) + foreach (rawtex_t *raw, App_ResourceSystem().collectRawTextures()) { - if(raw->tex) + if (raw->tex) { glDeleteTextures(1, (GLuint const *) &raw->tex); raw->tex = 0; diff --git a/doomsday/apps/client/src/render/r_draw.cpp b/doomsday/apps/client/src/render/r_draw.cpp index 1321178ce6..f68b8f99c6 100644 --- a/doomsday/apps/client/src/render/r_draw.cpp +++ b/doomsday/apps/client/src/render/r_draw.cpp @@ -62,7 +62,7 @@ static void loadViewBorderPatches() borderPatches[0] = 0; for(uint i = 1; i < 9; ++i) { - borderPatches[i] = ClientApp::resources().declarePatch(borderGraphicsNames[i]->path()); + borderPatches[i] = ClientResources::get().declarePatch(borderGraphicsNames[i]->path()); } // Detemine the view border size. diff --git a/doomsday/apps/client/src/resource/base/clientresources.cpp b/doomsday/apps/client/src/resource/base/clientresources.cpp index 51d5703313..a4943c2195 100644 --- a/doomsday/apps/client/src/resource/base/clientresources.cpp +++ b/doomsday/apps/client/src/resource/base/clientresources.cpp @@ -425,10 +425,13 @@ DENG2_PIMPL(ClientResources) , DENG2_OBSERVES(res::ColorPalette, ColorTableChange) #endif { +#ifdef __CLIENT__ + Binder binder; + Record savedSessionModule; // SavedSession: manipulation, conversion, etc... (based on native class SavedSession) + typedef QHash RawTextureHash; RawTextureHash rawTexHash; -#ifdef __CLIENT__ /// System subspace schemes containing the manifests/resources. FontSchemes fontSchemes; QList fontSchemeCreationOrder; @@ -490,11 +493,6 @@ DENG2_PIMPL(ClientResources) QMap sprites; -#ifdef __CLIENT__ - Binder binder; - Record savedSessionModule; // SavedSession: manipulation, conversion, etc... (based on native class SavedSession) -#endif - Impl(Public *i) : Base(i) #ifdef __CLIENT__ @@ -2063,6 +2061,11 @@ DENG2_PIMPL(ClientResources) } }; +ClientResources &ClientResources::get() // static +{ + return static_cast(Resources::get()); +} + ClientResources::ClientResources() : d(new Impl(this)) {} @@ -2255,6 +2258,8 @@ patchid_t ClientResources::declarePatch(String encodedName) return 0; } +#ifdef __CLIENT__ + rawtex_t *ClientResources::rawTexture(lumpnum_t lumpNum) { LOG_AS("ClientResources::rawTexture"); @@ -2302,8 +2307,6 @@ void ClientResources::clearAllRawTextures() d->rawTexHash.clear(); } -#ifdef __CLIENT__ - void ClientResources::releaseAllSystemGLTextures() { if (::novideo) return; diff --git a/doomsday/apps/client/src/ui/infine/finaleanimwidget.cpp b/doomsday/apps/client/src/ui/infine/finaleanimwidget.cpp index 8d3b8150fd..b8fd17e65d 100644 --- a/doomsday/apps/client/src/ui/infine/finaleanimwidget.cpp +++ b/doomsday/apps/client/src/ui/infine/finaleanimwidget.cpp @@ -220,7 +220,7 @@ static void drawPicFrame(FinaleAnimWidget *p, uint frame, float const _origin[3] switch (f->type) { case FinaleAnimWidget::Frame::PFT_RAW: { - rawtex_t *rawTex = App_ResourceSystem().declareRawTexture(f->texRef.lumpNum); + rawtex_t *rawTex = ClientResources::get().declareRawTexture(f->texRef.lumpNum); if (rawTex) { DGLuint glName = GL_PrepareRawTexture(*rawTex); diff --git a/doomsday/apps/client/src/ui/infine/finaleinterpreter.cpp b/doomsday/apps/client/src/ui/infine/finaleinterpreter.cpp index 58df9a7a8e..6f383f729a 100644 --- a/doomsday/apps/client/src/ui/infine/finaleinterpreter.cpp +++ b/doomsday/apps/client/src/ui/infine/finaleinterpreter.cpp @@ -1594,13 +1594,15 @@ DEFFC(Image) anim.clearAllFrames(); - if (rawtex_t *rawTex = App_ResourceSystem().declareRawTexture(lumpNum)) +#ifdef __CLIENT__ + if (rawtex_t *rawTex = ClientResources::get().declareRawTexture(lumpNum)) { anim.newFrame(FinaleAnimWidget::Frame::PFT_RAW, -1, &rawTex->lumpNum, 0, false); return; } LOG_SCR_WARNING("Missing lump '%s'") << name; +#endif } DEFFC(ImageAt) @@ -1609,14 +1611,16 @@ DEFFC(ImageAt) LOG_AS("FIC_ImageAt"); FinaleAnimWidget &anim = fi.findOrCreateWidget(FI_ANIM, OP_CSTRING(0)).as(); - float x = OP_FLOAT(1); - float y = OP_FLOAT(2); - char const *name = OP_CSTRING(3); - lumpnum_t lumpNum = App_FileSystem().lumpNumForName(name); + float x = OP_FLOAT(1); + float y = OP_FLOAT(2); anim.clearAllFrames() .setOrigin(Vector2f(x, y)); +#ifdef __CLIENT__ + char const *name = OP_CSTRING(3); + lumpnum_t lumpNum = App_FileSystem().lumpNumForName(name); + if (rawtex_t *rawTex = App_ResourceSystem().declareRawTexture(lumpNum)) { anim.newFrame(FinaleAnimWidget::Frame::PFT_RAW, -1, &rawTex->lumpNum, 0, false); @@ -1624,6 +1628,7 @@ DEFFC(ImageAt) } LOG_SCR_WARNING("Missing lump '%s'") << name; +#endif } #ifdef __CLIENT__ @@ -1766,16 +1771,20 @@ DEFFC(AnimImage) LOG_AS("FIC_AnimImage"); FinaleAnimWidget &anim = fi.findOrCreateWidget(FI_ANIM, OP_CSTRING(0)).as(); + +#ifdef __CLIENT__ char const *encodedName = OP_CSTRING(1); int const tics = FRACSECS_TO_TICKS(OP_FLOAT(2)); - - lumpnum_t lumpNum = App_FileSystem().lumpNumForName(encodedName); + lumpnum_t lumpNum = App_FileSystem().lumpNumForName(encodedName); if (rawtex_t *rawTex = App_ResourceSystem().declareRawTexture(lumpNum)) { anim.newFrame(FinaleAnimWidget::Frame::PFT_RAW, tics, &rawTex->lumpNum, 0, false); return; } LOG_SCR_WARNING("Lump '%s' not found") << encodedName; +#else + DENG2_UNUSED(anim); +#endif } DEFFC(Repeat) @@ -1981,7 +1990,7 @@ DEFFC(FillColor) int which = 0; if (!qstricmp(OP_CSTRING(1), "top")) which |= 1; else if (!qstricmp(OP_CSTRING(1), "bottom")) which |= 2; - else which = 3; + else which = 3; Vector4f color; for (int i = 0; i < 4; ++i)