Skip to content

Commit

Permalink
Make use of the GLTexture by-name search to remove the use of lump in…
Browse files Browse the repository at this point in the history
…dicies for unique identification in R_RegisterAsPatch.
  • Loading branch information
danij-deng committed May 27, 2010
1 parent 046cd92 commit 4f8140c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
9 changes: 9 additions & 0 deletions doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -2974,6 +2974,9 @@ boolean GLTexture_IsFromIWAD(const gltexture_t* tex)
case GLT_SPRITE:
return W_IsFromIWAD(spriteTextures[tex->ofTypeID]->lump);

case GLT_DOOMPATCH:
return !R_FindPatchTex(tex->ofTypeID)->isCustom;

case GLT_DETAIL:
case GLT_SHINY:
case GLT_MASK:
Expand Down Expand Up @@ -3008,6 +3011,9 @@ float GLTexture_GetWidth(const gltexture_t* tex)
case GLT_SPRITE:
return spriteTextures[tex->ofTypeID]->width;

case GLT_DOOMPATCH:
return R_FindPatchTex(tex->ofTypeID)->width;

case GLT_DETAIL:
return 128;

Expand Down Expand Up @@ -3048,6 +3054,9 @@ float GLTexture_GetHeight(const gltexture_t* tex)
case GLT_SPRITE:
return spriteTextures[tex->ofTypeID]->height;

case GLT_DOOMPATCH:
return R_FindPatchTex(tex->ofTypeID)->height;

case GLT_DETAIL:
return 128;

Expand Down
48 changes: 23 additions & 25 deletions doomsday/engine/portable/src/r_data.c
Expand Up @@ -919,18 +919,11 @@ static patchtex_t* getPatchTex(patchid_t id)
return NULL;
}

static patchid_t patchForLump(lumpnum_t lump)
static patchid_t patchForName(const char* name)
{
if(lump >= 0 && lump < numLumps)
{
uint i;
for(i = 0; i < numDoomPatchDefs; ++i)
{
patchtex_t* patchTex = doomPatchDefs[i];
if(patchTex->lump == lump)
return i + 1;
}
}
const gltexture_t* glTex;
if((glTex = GL_GetGLTextureByName(name, GLT_DOOMPATCH)))
return glTex->ofTypeID;
return 0;
}

Expand All @@ -949,19 +942,25 @@ patchtex_t* R_FindPatchTex(patchid_t id)
* Get a patchtex_t data structure for a patch specified with a WAD lump
* number. Allocates a new patchtex_t if it hasn't been loaded yet.
*/
patchid_t R_RegisterAsPatch(lumpnum_t lump)
patchid_t R_RegisterAsPatch(const char* name)
{
assert(name);
{
const lumppatch_t* patch;
lumpnum_t lump;
patchid_t id;
patchtex_t* p;

if(lump < 0 || lump >= numLumps)
return -1;
if(!name[0])
return 0;

// Already defined as a patch?
if((id = patchForLump(lump)) != 0)
if((id = patchForName(name)) != 0)
return id;

if((lump = W_CheckNumForName(name)) == -1)
return 0;

/// \fixme What about min lump size?
patch = (const lumppatch_t*) W_CacheLumpNum(lump, PU_STATIC);

Expand All @@ -987,7 +986,7 @@ patchid_t R_RegisterAsPatch(lumpnum_t lump)

// Register a gltexture for this.
{
const gltexture_t* glTex = GL_CreateGLTexture(W_LumpName(lump), ++numDoomPatchDefs, GLT_DOOMPATCH);
const gltexture_t* glTex = GL_CreateGLTexture(name, ++numDoomPatchDefs, GLT_DOOMPATCH);
p->texId = glTex->id;
}

Expand All @@ -997,6 +996,7 @@ patchid_t R_RegisterAsPatch(lumpnum_t lump)

W_ChangeCacheTag(lump, PU_CACHE);
return numDoomPatchDefs;
}
}

boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info)
Expand Down Expand Up @@ -1025,27 +1025,25 @@ boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info)

patchid_t R_PrecachePatch(const char* name, patchinfo_t* info)
{
lumpnum_t lump;
if(!name)
Con_Error("R_PrecachePatch: Argument 'name' cannot be NULL.");

if(info)
{
memset(info, 0, sizeof(patchinfo_t));
}

if(isDedicated)
return 0;

if((lump = W_CheckNumForName(name)) != -1)
{
patchid_t patch = R_RegisterAsPatch(lump);
patchid_t patch;
if((patch = R_RegisterAsPatch(name)) != 0)
{
GL_PreparePatch(getPatchTex(patch));
if(info)
{
R_GetPatchInfo(patch, info);
}
return patch;
}
return 0;
return patch;
}
}

/**
Expand Down

0 comments on commit 4f8140c

Please sign in to comment.