Skip to content

Commit

Permalink
Refactor: Removed last remnants of game-side caching of patchinfo_t
Browse files Browse the repository at this point in the history
Patch info is now retrieved when needed rather than caching this data
on game side. patchinfo_t is now defined for use as a temporary POD
structure for use exclusively with R_GetPatchInfo.

Replaced R_PrecachePatch with R_DeclarePatch.

Texture URIs are automatically converted to lowercase before being
registered in the collection. Sprite rotation builder has been updated
accordingly.
  • Loading branch information
danij-deng committed Nov 14, 2011
1 parent 81afd78 commit e02753e
Show file tree
Hide file tree
Showing 27 changed files with 761 additions and 796 deletions.
6 changes: 4 additions & 2 deletions doomsday/engine/api/doomsday.def
Expand Up @@ -397,18 +397,20 @@ EXPORTS

R_PrecacheMobjNum @427 NONAME
R_PrecacheSkinsForState @240 NONAME
R_PrecachePatch @335 NONAME

R_RenderPlayerView @90 NONAME
R_ViewWindowDimensions @91 NONAME
R_SetViewWindowDimensions @92 NONAME
R_ViewportDimensions @430 NONAME
R_SetViewPortPlayer @65 NONAME

R_SetBorderGfx @93 NONAME

R_GetSpriteInfo @94 NONAME

R_DeclarePatch @335 NONAME
R_GetPatchInfo @237 NONAME
R_ComposePatchUri @247 NONAME

R_OriginalIndexForTexture @438 NONAME
R_OriginalIndexForTexture2 @501 NONAME

Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/api/doomsday.h
Expand Up @@ -389,7 +389,6 @@ int DD_GetFrameRate(void);
void R_SetupMap(int mode, int flags);

void R_PrecacheMobjNum(int mobjtypeNum);
patchid_t R_PrecachePatch(const char* name, patchinfo_t* info);
void R_PrecacheSkinsForState(int stateIndex);

void R_RenderPlayerView(int num);
Expand All @@ -406,6 +405,8 @@ scalemode_t R_ChooseScaleMode2(int width, int height, int availWidth, int availH
scalemode_t R_ChooseScaleMode(int width, int height, int availWidth, int availHeight, scalemode_t overrideMode);

boolean R_GetSpriteInfo(int sprite, int frame, spriteinfo_t* sprinfo);

patchid_t R_DeclarePatch(const char* name);
boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info);
Uri* R_ComposePatchUri(patchid_t id);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/gl_texmanager.h
Expand Up @@ -305,7 +305,7 @@ DGLuint GL_PrepareExtTexture(const char* name, gfxmode_t mode, int useMipmap,
DGLuint GL_PrepareSysFlareTexture(flaretexid_t flare);
DGLuint GL_PrepareLightMap(const Uri* path);
DGLuint GL_PrepareLSTexture(lightingtexid_t which);
DGLuint GL_PreparePatchTexture(patchtex_t* patch);
DGLuint GL_PreparePatchTexture(texture_t* tex);
DGLuint GL_PrepareRawTexture(rawtex_t* rawTex);

/**
Expand Down
15 changes: 2 additions & 13 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -145,7 +145,6 @@ typedef struct {
#define PF_UPSCALE_AND_SHARPEN 0x2

typedef struct patchtex_s {
textureid_t texId; /// Name of the associated Texture.
short flags;
/// Offset to texture origin in logical pixels.
short offX, offY;
Expand Down Expand Up @@ -386,18 +385,8 @@ struct texture_s* R_FindReflectionTextureForResourcePath(const Uri* resourcePath
struct texture_s* R_CreateMaskTexture(const Uri* resourcePath, int logicalWidth, int logicalHeight);
struct texture_s* R_FindMaskTextureForResourcePath(const Uri* resourcePath);

patchid_t R_PrecachePatch(const char* name, patchinfo_t* info);

/**
* 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_RegisterPatch(const char* name);

/**
* Returns a patchtex_t* for the given lump, if one already exists.
*/
patchtex_t* R_PatchTextureByIndex(patchid_t id);
patchid_t R_DeclarePatch(const char* name);
texture_t* R_PatchTextureById(patchid_t id);

/**
* Retrieve extended info for the patch associated with @a id.
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/include/r_draw.h
Expand Up @@ -35,10 +35,10 @@ void R_ShutdownViewWindow(void);
void R_SetBorderGfx(const Uri* const* paths);
void R_DrawViewBorder(void);

void R_DrawPatch(patchtex_t* p, int x, int y);
void R_DrawPatch2(patchtex_t* p, int x, int y, int w, int h);
void R_DrawPatch3(patchtex_t* p, int x, int y, int w, int h, boolean useOffsets);
void R_DrawPatch(texture_t* texture, int x, int y);
void R_DrawPatch2(texture_t* texture, int x, int y, int w, int h);
void R_DrawPatch3(texture_t* texture, int x, int y, int w, int h, boolean useOffsets);

void R_DrawPatchTiled(patchtex_t* p, int x, int y, int w, int h, DGLint wrapS, DGLint wrapT);
void R_DrawPatchTiled(texture_t* texture, int x, int y, int w, int h, DGLint wrapS, DGLint wrapT);

#endif /* LIBDENG_REFRESH_DRAW_H */
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/bitmapfont.c
Expand Up @@ -655,7 +655,7 @@ void BitmapCompositeFont_Prepare(font_t* font)
avgHeight += cf->_chars[i].h;

if(!(novideo || isDedicated) && cf->_chars[i].tex == 0)
cf->_chars[i].tex = GL_PreparePatchTexture(R_PatchTextureByIndex(patch));
cf->_chars[i].tex = GL_PreparePatchTexture(R_PatchTextureById(patch));
}}

font->_noCharWidth = avgWidth / numPatches;
Expand Down Expand Up @@ -784,7 +784,7 @@ void BitmapCompositeFont_CharSetPatch(font_t* font, unsigned char ch, const char
cf->_chars[ch].dlist = 0;
}

cf->_chars[ch].patch = R_RegisterPatch(patchName);
cf->_chars[ch].patch = R_DeclarePatch(patchName);
{ patchinfo_t info;
R_GetPatchInfo(cf->_chars[ch].patch, &info);
cf->_chars[ch].x = info.offset + info.extraOffset[0] + font->_marginWidth;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/dgl_common.c
Expand Up @@ -684,7 +684,7 @@ void DGL_SetNoMaterial(void)

void DGL_SetPatch(patchid_t id, int wrapS, int wrapT)
{
GL_BindTexture(GL_PreparePatchTexture(R_PatchTextureByIndex(id)), (filterUI ? GL_LINEAR : GL_NEAREST));
GL_BindTexture(GL_PreparePatchTexture(R_PatchTextureById(id)), (filterUI ? GL_LINEAR : GL_NEAREST));

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (wrapS == DGL_CLAMP? GL_CLAMP : wrapS == DGL_CLAMP_TO_EDGE? GL_CLAMP_TO_EDGE : GL_REPEAT));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (wrapT == DGL_CLAMP? GL_CLAMP : wrapT == DGL_CLAMP_TO_EDGE? GL_CLAMP_TO_EDGE : GL_REPEAT));
Expand Down
58 changes: 32 additions & 26 deletions doomsday/engine/portable/src/finaleinterpreter.c
Expand Up @@ -1468,44 +1468,48 @@ DEFFC(Patch)
{
fi_object_t* obj = getObject(fi, FI_PIC, OP_CSTRING(0));
const char* name = OP_CSTRING(3);
patchid_t patch;
patchid_t patchId;

AnimatorVector3_Init(obj->pos, OP_FLOAT(1), OP_FLOAT(2), 0);
FIData_PicClearAnimation(obj);

if((patch = R_PrecachePatch(name, NULL)) != 0)
patchId = R_DeclarePatch(name);
if(patchId != 0)
{
FIData_PicAppendFrame(obj, PFT_PATCH, -1, &patch, 0, 0);
FIData_PicAppendFrame(obj, PFT_PATCH, -1, (void*)&patchId, 0, 0);
}
else
{
Con_Message("FIC_Patch: Warning, missing Patch '%s'.\n", name);
}
}

DEFFC(SetPatch)
{
fi_object_t* obj = getObject(fi, FI_PIC, OP_CSTRING(0));
const char* name = OP_CSTRING(1);
patchid_t patch;
fidata_pic_frame_t* f;
patchid_t patchId;

if((patch = R_PrecachePatch(name, NULL)) != 0)
patchId = R_DeclarePatch(name);
if(patchId == 0)
{
if(!((fidata_pic_t*)obj)->numFrames)
{
FIData_PicAppendFrame(obj, PFT_PATCH, -1, &patch, 0, false);
return;
}
Con_Message("FIC_SetPatch: Warning, missing Patch '%s'.\n", name);
return;
}

// Convert the first frame.
{
fidata_pic_frame_t* f = ((fidata_pic_t*)obj)->frames[0];
f->type = PFT_PATCH;
f->texRef.patch = patch;
f->tics = -1;
f->sound = 0;
}
if(!((fidata_pic_t*)obj)->numFrames)
{
FIData_PicAppendFrame(obj, PFT_PATCH, -1, (void*)&patchId, 0, false);
return;
}
else
Con_Message("FIC_SetPatch: Warning, missing Patch '%s'.\n", name);

// Convert the first frame.
f = ((fidata_pic_t*)obj)->frames[0];
f->type = PFT_PATCH;
f->texRef.patch = patchId;
f->tics = -1;
f->sound = 0;
}

DEFFC(ClearAnim)
Expand All @@ -1521,15 +1525,17 @@ DEFFC(Anim)
fi_object_t* obj = getObject(fi, FI_PIC, OP_CSTRING(0));
const char* name = OP_CSTRING(1);
int tics = FRACSECS_TO_TICKS(OP_FLOAT(2));
patchid_t patch;
patchid_t patchId;

if((patch = R_PrecachePatch(name, NULL)))
patchId = R_DeclarePatch(name);
if(patchId == 0)
{
FIData_PicAppendFrame(obj, PFT_PATCH, tics, &patch, 0, false);
((fidata_pic_t*)obj)->animComplete = false;
}
else
Con_Message("FIC_Anim: Warning, Patch '%s' not found.\n", name);
return;
}

FIData_PicAppendFrame(obj, PFT_PATCH, tics, (void*)&patchId, 0, false);
((fidata_pic_t*)obj)->animComplete = false;
}

DEFFC(AnimImage)
Expand Down
26 changes: 17 additions & 9 deletions doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -2786,18 +2786,26 @@ DGLuint GL_PrepareFlareTexture(const Uri* uri, int oldIdx)
return 0; // Use the automatic selection logic.
}

DGLuint GL_PreparePatchTexture(patchtex_t* patchTex)
DGLuint GL_PreparePatchTexture(texture_t* tex)
{
if(!novideo && patchTex)
texturevariantspecification_t* texSpec;
patchtex_t* pTex;
if(novideo || !tex) return 0;
if(Textures_Namespace(Textures_Id(tex)) != TN_PATCHES)
{
texturevariantspecification_t* texSpec =
GL_TextureVariantSpecificationForContext(TC_UI,
0 | ((patchTex->flags & PF_MONOCHROME) ? TSF_MONOCHROME : 0)
| ((patchTex->flags & PF_UPSCALE_AND_SHARPEN)? TSF_UPSCALE_AND_SHARPEN : 0),
0, 0, 0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, 1, 0, false, false, false, false);
return GL_PrepareTexture(Textures_ToTexture(patchTex->texId), texSpec);
#if _DEBUG
Con_Message("Warning:GL_PreparePatchTexture: Attempted to prepare non-patch [%p].\n", (void*)tex);
#endif
return 0;
}
return 0;
pTex = (patchtex_t*)Texture_UserData(tex);
assert(pTex);

texSpec = GL_TextureVariantSpecificationForContext(TC_UI,
0 | ((pTex->flags & PF_MONOCHROME) ? TSF_MONOCHROME : 0)
| ((pTex->flags & PF_UPSCALE_AND_SHARPEN)? TSF_UPSCALE_AND_SHARPEN : 0),
0, 0, 0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, 1, 0, false, false, false, false);
return GL_PrepareTexture(tex, texSpec);
}

boolean GL_OptimalTextureSize(int width, int height, boolean noStretch, boolean isMipMapped,
Expand Down

0 comments on commit e02753e

Please sign in to comment.