Skip to content

Commit

Permalink
Added new public API routine R_GetPatchName for querying the name
Browse files Browse the repository at this point in the history
associated with a unique patch identifier.

I opted not to make use of patchinfo_t because the games currently
statically-allocate copies of this struct.

This needs cleaning up; either:
a) engine manages the extended info and stores it so the game can
retrieve an immutable pointer to it whenever it is required
b) game asks the engine to dynamically allocate the info which the
game should then take care to destroy when no longer needed.
  • Loading branch information
danij-deng committed May 23, 2011
1 parent 3d691a0 commit 92e197a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
3 changes: 2 additions & 1 deletion doomsday/engine/api/doomsday.def
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; Doomsday Engine API (Routines exported from Doomsday.exe).
;
; Highest ordinal is currently: --> 510 <--
; Other free ordinals: 90 133 247
; Other free ordinals: 90 133

NAME "DOOMSDAY"
EXPORTS
Expand Down Expand Up @@ -375,6 +375,7 @@ EXPORTS
R_SetBorderGfx @93 NONAME
R_GetSpriteInfo @94 NONAME
R_GetPatchInfo @237 NONAME
R_GetPatchName @247 NONAME
R_PointToAngle2 @101 NONAME
R_PointInSubsector @102 NONAME
R_HSVToRGB @439 NONAME
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/api/doomsday.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ scalemode_t R_ChooseScaleMode(int width, int height, int availWidth, int availHe

void R_SetBorderGfx(const dduri_t* paths[9]);
boolean R_GetSpriteInfo(int sprite, int frame, spriteinfo_t* sprinfo);
boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info);
boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info);
const ddstring_t* R_GetPatchName(patchid_t id);
void R_HSVToRGB(float* rgb, float h, float s, float v);
angle_t R_PointToAngle2(float x1, float y1, float x2, float y2);
struct subsector_s* R_PointInSubsector(float x, float y);
Expand Down
12 changes: 11 additions & 1 deletion doomsday/engine/portable/include/r_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,17 @@ patchid_t R_RegisterPatch(const char* name);

patchtex_t* R_PatchTextureByIndex(patchid_t id);
void R_ClearPatchTexs(void);
boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info);

/**
* Retrieve extended info for the patch associated with @a id.
* @param id Unique identifier of the patch to lookup.
* @param info Extend info will be written here if found.
* @return @c true= Extended info for this patch was found.
*/
boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info);

/// @return Name of the patch associated with @a id.
const ddstring_t* R_GetPatchName(patchid_t id);

void R_InitRawTexs(void);
void R_UpdateRawTexs(void);
Expand Down
35 changes: 26 additions & 9 deletions doomsday/engine/portable/src/r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,28 +1145,45 @@ patchid_t R_RegisterPatch(const char* name)

boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info)
{
const patchtex_t* patch;
if(!info)
Con_Error("R_GetPatchInfo: Argument 'info' cannot be NULL.");
{
const patchtex_t* p;

memset(info, 0, sizeof(*info));
if(NULL != (p = getPatchTex(id)))
patch = getPatchTex(id);
if(NULL != patch)
{
texture_t* tex = GL_ToTexture(p->texId);
texture_t* tex = GL_ToTexture(patch->texId);
assert(NULL != tex);
info->id = id;
info->width = Texture_Width(tex);
info->height = Texture_Height(tex);
info->offset = p->offX;
info->topOffset = p->offY;
info->isCustom = p->isCustom;
info->offset = patch->offX;
info->topOffset = patch->offY;
info->isCustom = patch->isCustom;
/// \kludge:
info->extraOffset[0] = info->extraOffset[1] = (p->flags & PF_UPSCALE_AND_SHARPEN)? -1 : 0;
info->extraOffset[0] = info->extraOffset[1] = (patch->flags & PF_UPSCALE_AND_SHARPEN)? -1 : 0;
return true;
}
VERBOSE(Con_Message("R_GetPatchInfo: Warning, unknown Patch %i.\n", id));
if(id != 0)
{
VERBOSE( Con_Message("Warning:R_GetPatchInfo Invalid Patch id #%u.\n", (uint)id) )
}
return false;
}

const ddstring_t* R_GetPatchName(patchid_t id)
{
const patchtex_t* patch = getPatchTex(id);
if(NULL != patch)
{
return &patch->name;
}
if(id != 0)
{
VERBOSE( Con_Message("Warning:R_GetPatchName: Invalid Patch id #%u.\n", (uint)id) )
}
return NULL;
}

patchid_t R_PrecachePatch(const char* name, patchinfo_t* info)
Expand Down

0 comments on commit 92e197a

Please sign in to comment.