From 508f7144d562ce17ad4a5a08faad9f13cd35fe1d Mon Sep 17 00:00:00 2001 From: danij Date: Fri, 7 Dec 2012 05:40:53 +0000 Subject: [PATCH] Optimize: Removed the redundant central texture index As there is no longer a need to reference textures with a contiguous range of indices, the central texture index itself was redundant. This is because the texture manifests persist engine resets and all bookkeeping is fully dynamic. The unused central texture index and the associated textureid_t have now been removed. --- doomsday/engine/include/resource/animgroups.h | 2 +- doomsday/engine/include/resource/texture.h | 4 - .../engine/include/resource/texturemanifest.h | 14 +-- doomsday/engine/include/resource/textures.h | 31 ------ doomsday/engine/src/dd_main.cpp | 2 - doomsday/engine/src/def_main.cpp | 6 +- doomsday/engine/src/resource/animgroups.cpp | 34 +++--- doomsday/engine/src/resource/fonts.cpp | 2 +- .../engine/src/resource/texturemanifest.cpp | 11 +- doomsday/engine/src/resource/textures.cpp | 105 ++---------------- 10 files changed, 36 insertions(+), 175 deletions(-) diff --git a/doomsday/engine/include/resource/animgroups.h b/doomsday/engine/include/resource/animgroups.h index 43b765afcf..f330b6b0d9 100644 --- a/doomsday/engine/include/resource/animgroups.h +++ b/doomsday/engine/include/resource/animgroups.h @@ -34,7 +34,7 @@ extern "C" { */ typedef struct animframe_s { - textureid_t texture; + void *textureManifest; ushort tics; ushort randomTics; } animframe_t; diff --git a/doomsday/engine/include/resource/texture.h b/doomsday/engine/include/resource/texture.h index 5719027366..3691d11280 100644 --- a/doomsday/engine/include/resource/texture.h +++ b/doomsday/engine/include/resource/texture.h @@ -25,9 +25,6 @@ #include #include "texturevariant.h" -/// Unique identifier associated with each texture name in a texture collection. -typedef int textureid_t; - #ifdef __cplusplus extern "C" { #endif @@ -243,7 +240,6 @@ void Texture_SetAnalysisDataPointer(Texture* tex, texture_analysisid_t analysis, boolean Texture_IsCustom(const Texture* tex); void Texture_FlagCustom(Texture* tex, boolean yes); -textureid_t Texture_PrimaryBind(const Texture* tex); int Texture_Width(const Texture* tex); int Texture_Height(const Texture* tex); const Size2Raw* Texture_Dimensions(const Texture* tex); diff --git a/doomsday/engine/include/resource/texturemanifest.h b/doomsday/engine/include/resource/texturemanifest.h index ef3009b095..3c7b56991c 100644 --- a/doomsday/engine/include/resource/texturemanifest.h +++ b/doomsday/engine/include/resource/texturemanifest.h @@ -1,6 +1,4 @@ -/** - * @file texturemanifest.h - * @ingroup resource +/** @file texturemanifest.h Texture Manifest. * * @author Copyright © 2010-2012 Daniel Swanson * @@ -33,8 +31,11 @@ class Textures; class TextureScheme; /** - * Models a reference to and the associated metadata for a would-be logical - * Texture resource in the Textures collection. + * Metadata for a would-be logical Texture resource. + * @ingroup resource + * + * Models a reference to and the associated metadata for a logical texture + * in the texture resource collection. */ class TextureManifest : public PathTree::Node { @@ -134,9 +135,6 @@ class TextureManifest : public PathTree::Node /// Returns a reference to the application's texture system. static Textures &textures(); - /// @todo Refactor away -ds - textureid_t lookupTextureId() const; - private: /// Scheme-unique identifier determined by the owner of the subspace. int uniqueId_; diff --git a/doomsday/engine/include/resource/textures.h b/doomsday/engine/include/resource/textures.h index aafaf8ac94..5dd1d981fc 100644 --- a/doomsday/engine/include/resource/textures.h +++ b/doomsday/engine/include/resource/textures.h @@ -23,9 +23,6 @@ #include "uri.h" -/// Special value used to signify an invalid texture id. -#define NOTEXTUREID 0 - #ifdef __cplusplus #include @@ -141,21 +138,6 @@ class Textures DENG2_FOR_EACH(Schemes, i, schemes){ (*i)->clear(); } } - /// @return Total number of unique Textures in the collection. - int size() const; - - /// @return Total number of unique Textures in the collection. Same as @ref size() - inline int count() const { - return size(); - } - - /** - * Removes the manifest from any indexes. - * - * @param manifest Manifest to remove from the index. - */ - void deindex(Manifest &manifest); - /** * Find a single declared texture. * @@ -234,19 +216,6 @@ class Textures private: struct Instance; Instance *d; - -public: - /* - * Here follows legacy interface methods awaiting removal -ds - */ - - /// @return Unique identifier of the primary name for @a manifest else @c NOTEXTUREID. - /// @deprecated Texture ids are now obsolete. Reference/point-to the manifest instead. - textureid_t idForManifest(Manifest const &manifest) const; - - /// @return Texture associated with unique identifier @a textureId else @c 0. - /// @deprecated Texture ids are now obsolete. Reference/point-to the manifest instead. - Texture *toTexture(textureid_t textureId) const; }; } // namespace de diff --git a/doomsday/engine/src/dd_main.cpp b/doomsday/engine/src/dd_main.cpp index d750fb7986..255203a24d 100644 --- a/doomsday/engine/src/dd_main.cpp +++ b/doomsday/engine/src/dd_main.cpp @@ -537,7 +537,6 @@ void DD_CreateTextureSchemes() void DD_ClearRuntimeTextureSchemes() { Textures &textures = *App_Textures(); - if(!textures.count()) return; textures.scheme("Flats").clear(); textures.scheme("Textures").clear(); @@ -557,7 +556,6 @@ void DD_ClearRuntimeTextureSchemes() void DD_ClearSystemTextureSchemes() { Textures &textures = *App_Textures(); - if(!textures.count()) return; textures.scheme("System").clear(); GL_PruneTextureVariantSpecifications(); diff --git a/doomsday/engine/src/def_main.cpp b/doomsday/engine/src/def_main.cpp index 5692575c29..9d37ca013b 100644 --- a/doomsday/engine/src/def_main.cpp +++ b/doomsday/engine/src/def_main.cpp @@ -922,8 +922,6 @@ void Def_GenerateGroupsFromAnims(void) int groupCount = R_AnimGroupCount(), i; if(!groupCount) return; - de::Textures &textures = *App_Textures(); - // Group ids are 1-based. for(i = 1; i < groupCount+1; ++i) { @@ -945,7 +943,9 @@ void Def_GenerateGroupsFromAnims(void) gmbr = &grp->members[idx]; gmbr->tics = frame->tics; gmbr->randomTics = frame->randomTics; - if(de::Texture *tex = textures.toTexture(frame->texture)) + if(!frame->textureManifest) continue; + + if(de::Texture *tex = reinterpret_cast(frame->textureManifest)->texture()) { de::Uri textureUri = tex->manifest().composeUri(); gmbr->material = reinterpret_cast(new de::Uri(Str_Text(DD_MaterialSchemeNameForTextureScheme(textureUri.scheme())), textureUri.path())); diff --git a/doomsday/engine/src/resource/animgroups.cpp b/doomsday/engine/src/resource/animgroups.cpp index fe382c4cbe..efb7af9d96 100644 --- a/doomsday/engine/src/resource/animgroups.cpp +++ b/doomsday/engine/src/resource/animgroups.cpp @@ -19,11 +19,15 @@ * 02110-1301 USA */ +#include + #include "de_base.h" #include "de_console.h" #include "de_resource.h" #include +using namespace de; + static int numgroups; static animgroup_t *groups; @@ -33,16 +37,12 @@ static animgroup_t *getAnimGroup(int number) return &groups[number]; } -static boolean isInAnimGroup(animgroup_t const *group, textureid_t texId) +static bool isInAnimGroup(animgroup_t const &group, TextureManifest &manifest) { - DENG_ASSERT(group); - if(texId != NOTEXTUREID) + for(int i = 0; i < group.count; ++i) { - for(int i = 0; i < group->count; ++i) - { - if(group->frames[i].texture == texId) - return true; - } + if(group.frames[i].textureManifest == &manifest) + return true; } return false; } @@ -53,8 +53,8 @@ void R_ClearAnimGroups() for(int i = 0; i < numgroups; ++i) { - animgroup_t *grp = &groups[i]; - if(grp->frames) Z_Free(grp->frames); + animgroup_t &grp = groups[i]; + if(grp.frames) Z_Free(grp.frames); } Z_Free(groups); groups = 0; numgroups = 0; @@ -83,7 +83,7 @@ int R_CreateAnimGroup(int flags) animgroup_t *group = &groups[numgroups-1]; // Init the new group. - memset(group, 0, sizeof *group); + std::memset(group, 0, sizeof *group); group->id = numgroups; // 1-based index. group->flags = flags; @@ -91,7 +91,7 @@ int R_CreateAnimGroup(int flags) } /// @note Part of the Doomsday public API. -void R_AddAnimGroupFrame(int groupNum, Uri const *textureUri, int tics, int randomTics) +void R_AddAnimGroupFrame(int groupNum, uri_s const *textureUri, int tics, int randomTics) { LOG_AS("R_AddAnimGroupFrame"); @@ -104,7 +104,7 @@ void R_AddAnimGroupFrame(int groupNum, Uri const *textureUri, int tics, int rand return; } - de::TextureManifest *manifest = App_Textures()->find(reinterpret_cast(*textureUri)); + TextureManifest *manifest = App_Textures()->find(reinterpret_cast(*textureUri)); if(!manifest) { LOG_DEBUG("Invalid texture uri \"%s\", ignoring.") << reinterpret_cast(*textureUri); @@ -116,17 +116,17 @@ void R_AddAnimGroupFrame(int groupNum, Uri const *textureUri, int tics, int rand if(!group->frames) Con_Error("R_AddAnimGroupFrame: Failed on (re)allocation of %lu bytes enlarging AnimFrame list for group #%i.", (unsigned long) sizeof(*group->frames) * group->count, groupNum); animframe_t *frame = &group->frames[group->count - 1]; - frame->texture = manifest->lookupTextureId(); + frame->textureManifest = manifest; frame->tics = tics; frame->randomTics = randomTics; } -boolean R_IsTextureInAnimGroup(Uri const *texture, int groupNum) +boolean R_IsTextureInAnimGroup(uri_s const *texture, int groupNum) { if(!texture) return false; animgroup_t *group = getAnimGroup(groupNum); if(!group) return false; - de::TextureManifest *manifest = App_Textures()->find(reinterpret_cast(*texture)); + TextureManifest *manifest = App_Textures()->find(reinterpret_cast(*texture)); if(!manifest) return false; - return isInAnimGroup(group, manifest->lookupTextureId()); + return isInAnimGroup(*group, *manifest); } diff --git a/doomsday/engine/src/resource/fonts.cpp b/doomsday/engine/src/resource/fonts.cpp index 4ae14a271e..745aa471d6 100644 --- a/doomsday/engine/src/resource/fonts.cpp +++ b/doomsday/engine/src/resource/fonts.cpp @@ -498,7 +498,7 @@ void Fonts_ClearRuntime(void) void Fonts_ClearSystem(void) { - if(!App_Textures()->count()) return; + if(!Fonts_Size()) return; Fonts_ClearScheme(FS_SYSTEM); GL_PruneTextureVariantSpecifications(); diff --git a/doomsday/engine/src/resource/texturemanifest.cpp b/doomsday/engine/src/resource/texturemanifest.cpp index 9e5a62b454..a6281b31cd 100644 --- a/doomsday/engine/src/resource/texturemanifest.cpp +++ b/doomsday/engine/src/resource/texturemanifest.cpp @@ -1,6 +1,4 @@ -/** - * @file texturemanifest.cpp Manifest for a logical Texture. - * @ingroup resource +/** @file texturemanifest.cpp Texture Manifest. * * @author Copyright © 2010-2012 Daniel Swanson * @@ -39,8 +37,6 @@ TextureManifest::~TextureManifest() #endif delete texture_; } - - textures().deindex(*this); } Textures &TextureManifest::textures() @@ -120,11 +116,6 @@ bool TextureManifest::setResourceUri(Uri const &newUri) return false; } -textureid_t TextureManifest::lookupTextureId() const -{ - return textures().idForManifest(*this); -} - Texture *TextureManifest::texture() const { return texture_; diff --git a/doomsday/engine/src/resource/textures.cpp b/doomsday/engine/src/resource/textures.cpp index 451c996f4e..19ec60b435 100644 --- a/doomsday/engine/src/resource/textures.cpp +++ b/doomsday/engine/src/resource/textures.cpp @@ -1,8 +1,6 @@ -/** - * @file textures.cpp - * Textures collection. @ingroup resource +/** @file textures.cpp Texture Resource Collection. * - * @authors Copyright © 2010-2012 Daniel Swanson + * @author Copyright © 2010-2012 Daniel Swanson * * @par License * GPL: http://www.gnu.org/licenses/gpl.html @@ -78,9 +76,6 @@ struct Textures::Instance { Textures& self; - // LUT which translates textureid_t => TextureManifest*. Index with textureid_t-1 - QList textureIdLut; - /// System subspace schemes containing the textures. Textures::Schemes schemes; @@ -96,25 +91,6 @@ struct Textures::Instance schemes.clear(); } - inline bool validTextureId(textureid_t id) const - { - return (id != NOTEXTUREID && id <= textureIdLut.size()); - } - - /// @pre textureIdLut has been initialized and is large enough! - void unlinkFromTextureIdLut(TextureManifest &manifest) - { - textureid_t texId = self.idForManifest(manifest); - if(!validTextureId(texId)) return; // Not linked. - textureIdLut[texId - 1/*1-based index*/] = 0; - } - - TextureManifest *manifestByTextureId(textureid_t id) - { - if(!validTextureId(id)) return 0; - return textureIdLut[id - 1/*1-based index*/]; - } - TextureManifest *manifestByUri(Uri const &validatedUri) { // Is this a URN? (of the form "urn:schemename:uniqueid") @@ -275,11 +251,6 @@ Textures::Scheme& Textures::createScheme(String name) return *newScheme; } -int Textures::size() const -{ - return d->textureIdLut.size(); -} - static void release(Texture *tex) { /// Stub. @@ -287,27 +258,10 @@ static void release(Texture *tex) /// @todo Update any Materials (and thus Surfaces) which reference this. } -Texture *Textures::toTexture(textureid_t id) const -{ - LOG_AS("Textures::toTexture"); - if(TextureManifest *manifest = d->manifestByTextureId(id)) - { - return manifest->texture(); - } - -#if _DEBUG - if(id != NOTEXTUREID) - LOG_WARNING("Failed to locate texture for id #%i, returning 0.") << id; -#endif - return 0; -} - TextureManifest *Textures::find(Uri const &uri) const { LOG_AS("Textures::find"); - if(!Textures::size()) return 0; - if(!d->validateUri(uri, AnyScheme, true /*quiet please*/)) { #if _DEBUG @@ -333,22 +287,16 @@ TextureManifest *Textures::declare(Uri const &uri, int uniqueId, Uri const *reso return 0; } - // Have we already created a binding for this? + // Have we already created a manifest for this? TextureManifest *manifest = d->manifestByUri(uri); if(!manifest) { - /* - * A new binding. - */ manifest = &scheme(uri.scheme()).insertManifest(uri.path()); manifest->setUniqueId(uniqueId); - - // Link it into the id LUT. - d->textureIdLut.push_back(manifest); } - /** - * (Re)configure this binding. + /* + * (Re)configure the manifest. */ // We don't care whether these identfiers are truely unique. Our only @@ -375,18 +323,6 @@ TextureManifest *Textures::declare(Uri const &uri, int uniqueId, Uri const *reso return manifest; } -textureid_t Textures::idForManifest(Textures::Manifest const &manifest) const -{ - LOG_AS("Textures::idForManifest"); - /// @todo Optimize: (Low priority) do not use a linear search. - int index = d->textureIdLut.indexOf(const_cast(&manifest)); - if(index >= 0) - { - return textureid_t(index + 1); // 1-based index. - } - return NOTEXTUREID; // Not linked. -} - bool Textures::knownScheme(String name) const { if(!name.isEmpty()) @@ -486,11 +422,6 @@ int Textures::iterateDeclared(String nameOfScheme, return 0; } -void Textures::deindex(TextureManifest &manifest) -{ - d->unlinkFromTextureIdLut(manifest); -} - static void printVariantInfo(TextureVariant &variant) { float s, t; @@ -665,11 +596,9 @@ static int printTextures2(Textures::Scheme *scheme, Path const &like, int flags) // Print the result index key. int numFoundDigits = MAX_OF(3/*idx*/, M_NumDigits(found.count())); - int numUidDigits = MAX_OF(3/*uid*/, M_NumDigits(App_Textures()->count())); - Con_Printf(" %*s: %-*s %*s origin n# uri\n", numFoundDigits, "idx", - printSchemeName? 22 : 14, printSchemeName? "scheme:path" : "path", - numUidDigits, "uid"); + Con_Printf(" %*s: %-*s origin n# uri\n", numFoundDigits, "idx", + printSchemeName? 22 : 14, printSchemeName? "scheme:path" : "path"); Con_PrintRuler(); // Sort and print the index. @@ -820,13 +749,6 @@ D_CMD(ListTextures) DENG2_UNUSED(src); de::Textures &textures = *App_Textures(); - - if(!textures.count()) - { - Con_Message("There are currently no textures defined/loaded.\n"); - return true; - } - de::Uri search = composeSearchUri(&argv[1], argc - 1); if(!search.scheme().isEmpty() && !textures.knownScheme(search.scheme())) { @@ -843,13 +765,6 @@ D_CMD(InspectTexture) DENG2_UNUSED(src); de::Textures &textures = *App_Textures(); - - if(!textures.count()) - { - Con_Message("There are currently no textures defined/loaded.\n"); - return true; - } - de::Uri search = composeSearchUri(&argv[1], argc - 1, false /*don't match schemes*/); if(!search.scheme().isEmpty() && !textures.knownScheme(search.scheme())) { @@ -875,12 +790,6 @@ D_CMD(PrintTextureStats) de::Textures &textures = *App_Textures(); - if(!textures.count()) - { - Con_Message("There are currently no textures defined/loaded.\n"); - return true; - } - Con_FPrintf(CPF_YELLOW, "Texture Statistics:\n"); de::Textures::Schemes const &schemes = textures.allSchemes(); DENG2_FOR_EACH_CONST(de::Textures::Schemes, i, schemes)