Skip to content

Commit

Permalink
Fixed|R_DeclarePatch: Now assumes a percent-encoded name
Browse files Browse the repository at this point in the history
This routine was not being used consistently resulting in erroneous
double percent-encoding of names. It is now the responsibility of
the caller to ensure the supplied name is encoded if necessary.
  • Loading branch information
danij-deng committed Mar 4, 2013
1 parent a6f4966 commit 1628cc1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 36 deletions.
5 changes: 4 additions & 1 deletion doomsday/api/api_resource.h
Expand Up @@ -29,7 +29,10 @@ DENG_API_TYPEDEF(R)
{
de_api_t api;

patchid_t (*DeclarePatch)(const char* name);
/**
* @param encodedName Percent-encoded name for the patch.
*/
patchid_t (*DeclarePatch)(char const *encodedName);

/**
* Retrieve extended info for the patch associated with @a id.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/resource/bitmapfont.h
Expand Up @@ -103,7 +103,7 @@ struct ded_compositefont_s *BitmapCompositeFont_Definition(font_t const *font);
void BitmapCompositeFont_SetDefinition(font_t *font, struct ded_compositefont_s *def);

patchid_t BitmapCompositeFont_CharPatch(font_t *font, unsigned char ch);
void BitmapCompositeFont_CharSetPatch(font_t *font, unsigned char ch, char const *patchName);
void BitmapCompositeFont_CharSetPatch(font_t *font, unsigned char ch, char const *encodedPatchName);

de::Texture::Variant *BitmapCompositeFont_CharTexture(font_t *font, unsigned char ch);
void BitmapCompositeFont_ReleaseTextures(font_t *font);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/api_resource.cpp
Expand Up @@ -61,7 +61,7 @@ DENG_EXTERN_C void R_GetColorPaletteRGBf(colorpaletteid_t id, int colorIdx, floa
* r_data.cpp:
*/
#undef R_DeclarePatch
DENG_EXTERN_C patchid_t R_DeclarePatch(char const *name);
DENG_EXTERN_C patchid_t R_DeclarePatch(char const *encodedName);

#undef R_GetPatchInfo
DENG_EXTERN_C boolean R_GetPatchInfo(patchid_t id, patchinfo_t *info);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/resource/bitmapfont.cpp
Expand Up @@ -621,12 +621,12 @@ patchid_t BitmapCompositeFont_CharPatch(font_t *font, unsigned char ch)
return cf->_chars[ch].patch;
}

void BitmapCompositeFont_CharSetPatch(font_t *font, unsigned char chr, char const *patchName)
void BitmapCompositeFont_CharSetPatch(font_t *font, unsigned char chr, char const *encodedPatchName)
{
DENG_ASSERT(font && font->_type == FT_BITMAPCOMPOSITE);
bitmapcompositefont_t *cf = (bitmapcompositefont_t *)font;
bitmapcompositefont_char_t *ch = &cf->_chars[chr];
ch->patch = R_DeclarePatch(patchName);
ch->patch = R_DeclarePatch(encodedPatchName);
font->_isDirty = true;
}

Expand Down
8 changes: 3 additions & 5 deletions doomsday/client/src/resource/r_data.cpp
Expand Up @@ -172,21 +172,19 @@ DENG_EXTERN_C uri_s *R_ComposePatchUri(patchid_t id)
}

#undef R_DeclarePatch
DENG_EXTERN_C patchid_t R_DeclarePatch(char const *name)
DENG_EXTERN_C patchid_t R_DeclarePatch(char const *encodedName)
{
LOG_AS("R_DeclarePatch");

if(!name || !name[0])
if(!encodedName || !encodedName[0])
{
LOG_DEBUG("Invalid 'name' argument, ignoring.");
return 0;
}

Textures &textures = App_Textures();

// WAD format allows characters not normally permitted in native paths.
// To achieve uniformity we apply a percent encoding to the "raw" names.
de::Uri uri("Patches", Path(QString(QByteArray(name, qstrlen(name)).toPercentEncoding())));
de::Uri uri("Patches", Path(encodedName));

// Already defined as a patch?
try
Expand Down
52 changes: 26 additions & 26 deletions doomsday/client/src/ui/finaleinterpreter.cpp
Expand Up @@ -1631,46 +1631,46 @@ DEFFC(XImage)

DEFFC(Patch)
{
fi_object_t* obj = getObject(fi, FI_PIC, OP_CSTRING(0));
const char* name = OP_CSTRING(3);
fi_object_t *obj = getObject(fi, FI_PIC, OP_CSTRING(0));
char const *encodedName = OP_CSTRING(3);
patchid_t patchId;

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

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

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

patchId = R_DeclarePatch(name);
patchId = R_DeclarePatch(encodedName);
if(patchId == 0)
{
Con_Message("FIC_SetPatch: Warning, missing Patch '%s'.", name);
Con_Message("FIC_SetPatch: Warning, missing Patch '%s'.", encodedName);
return;
}

if(!((fidata_pic_t*)obj)->numFrames)
if(!((fidata_pic_t *)obj)->numFrames)
{
FIData_PicAppendFrame(obj, PFT_PATCH, -1, (void*)&patchId, 0, false);
FIData_PicAppendFrame(obj, PFT_PATCH, -1, (void *)&patchId, 0, false);
return;
}

// Convert the first frame.
f = ((fidata_pic_t*)obj)->frames[0];
f = ((fidata_pic_t *)obj)->frames[0];
f->type = PFT_PATCH;
f->texRef.patch = patchId;
f->tics = -1;
Expand All @@ -1687,36 +1687,36 @@ DEFFC(ClearAnim)

DEFFC(Anim)
{
fi_object_t* obj = getObject(fi, FI_PIC, OP_CSTRING(0));
const char* name = OP_CSTRING(1);
fi_object_t *obj = getObject(fi, FI_PIC, OP_CSTRING(0));
char const *encodedName = OP_CSTRING(1);
int tics = FRACSECS_TO_TICKS(OP_FLOAT(2));
patchid_t patchId;

patchId = R_DeclarePatch(name);
patchId = R_DeclarePatch(encodedName);
if(patchId == 0)
{
Con_Message("FIC_Anim: Warning, Patch '%s' not found.", name);
Con_Message("FIC_Anim: Warning, Patch '%s' not found.", encodedName);
return;
}

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

DEFFC(AnimImage)
{
fi_object_t* obj = getObject(fi, FI_PIC, OP_CSTRING(0));
const char* name = OP_CSTRING(1);
fi_object_t *obj = getObject(fi, FI_PIC, OP_CSTRING(0));
char const *encodedName = OP_CSTRING(1);
int tics = FRACSECS_TO_TICKS(OP_FLOAT(2));
lumpnum_t lumpNum = F_LumpNumForName(name);
rawtex_t* rawTex = R_GetRawTex(lumpNum);
if(NULL != rawTex)
lumpnum_t lumpNum = F_LumpNumForName(encodedName);
rawtex_t *rawTex = R_GetRawTex(lumpNum);
if(rawTex)
{
FIData_PicAppendFrame(obj, PFT_RAW, tics, &rawTex->lumpNum, 0, false);
((fidata_pic_t*)obj)->animComplete = false;
((fidata_pic_t *)obj)->animComplete = false;
return;
}
Con_Message("FIC_AnimImage: Warning, lump '%s' not found.", name);
Con_Message("FIC_AnimImage: Warning, lump '%s' not found.", encodedName);
}

DEFFC(Repeat)
Expand Down

0 comments on commit 1628cc1

Please sign in to comment.