Navigation Menu

Skip to content

Commit

Permalink
Optimize: Removed the redundant central texture index
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danij-deng committed Dec 7, 2012
1 parent 2cf30c6 commit 508f714
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 175 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/include/resource/animgroups.h
Expand Up @@ -34,7 +34,7 @@ extern "C" {
*/
typedef struct animframe_s
{
textureid_t texture;
void *textureManifest;
ushort tics;
ushort randomTics;
} animframe_t;
Expand Down
4 changes: 0 additions & 4 deletions doomsday/engine/include/resource/texture.h
Expand Up @@ -25,9 +25,6 @@
#include <de/size.h>
#include "texturevariant.h"

/// Unique identifier associated with each texture name in a texture collection.
typedef int textureid_t;

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions doomsday/engine/include/resource/texturemanifest.h
@@ -1,6 +1,4 @@
/**
* @file texturemanifest.h
* @ingroup resource
/** @file texturemanifest.h Texture Manifest.
*
* @author Copyright &copy; 2010-2012 Daniel Swanson <danij@dengine.net>
*
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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_;
Expand Down
31 changes: 0 additions & 31 deletions doomsday/engine/include/resource/textures.h
Expand Up @@ -23,9 +23,6 @@

#include "uri.h"

/// Special value used to signify an invalid texture id.
#define NOTEXTUREID 0

#ifdef __cplusplus

#include <QList>
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions doomsday/engine/src/dd_main.cpp
Expand Up @@ -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();
Expand All @@ -557,7 +556,6 @@ void DD_ClearRuntimeTextureSchemes()
void DD_ClearSystemTextureSchemes()
{
Textures &textures = *App_Textures();
if(!textures.count()) return;

textures.scheme("System").clear();
GL_PruneTextureVariantSpecifications();
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/src/def_main.cpp
Expand Up @@ -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)
{
Expand All @@ -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<de::TextureManifest *>(frame->textureManifest)->texture())
{
de::Uri textureUri = tex->manifest().composeUri();
gmbr->material = reinterpret_cast<uri_s *>(new de::Uri(Str_Text(DD_MaterialSchemeNameForTextureScheme(textureUri.scheme())), textureUri.path()));
Expand Down
34 changes: 17 additions & 17 deletions doomsday/engine/src/resource/animgroups.cpp
Expand Up @@ -19,11 +19,15 @@
* 02110-1301 USA</small>
*/

#include <cstring>

#include "de_base.h"
#include "de_console.h"
#include "de_resource.h"
#include <de/memoryzone.h>

using namespace de;

static int numgroups;
static animgroup_t *groups;

Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -83,15 +83,15 @@ 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;

return group->id;
}

/// @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");

Expand All @@ -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<de::Uri const &>(*textureUri));
TextureManifest *manifest = App_Textures()->find(reinterpret_cast<de::Uri const &>(*textureUri));
if(!manifest)
{
LOG_DEBUG("Invalid texture uri \"%s\", ignoring.") << reinterpret_cast<de::Uri const &>(*textureUri);
Expand All @@ -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<de::Uri const &>(*texture));
TextureManifest *manifest = App_Textures()->find(reinterpret_cast<de::Uri const &>(*texture));
if(!manifest) return false;
return isInAnimGroup(group, manifest->lookupTextureId());
return isInAnimGroup(*group, *manifest);
}
2 changes: 1 addition & 1 deletion doomsday/engine/src/resource/fonts.cpp
Expand Up @@ -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();
Expand Down
11 changes: 1 addition & 10 deletions 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 &copy; 2010-2012 Daniel Swanson <danij@dengine.net>
*
Expand Down Expand Up @@ -39,8 +37,6 @@ TextureManifest::~TextureManifest()
#endif
delete texture_;
}

textures().deindex(*this);
}

Textures &TextureManifest::textures()
Expand Down Expand Up @@ -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_;
Expand Down

0 comments on commit 508f714

Please sign in to comment.