Skip to content

Commit

Permalink
Hexen: Fixed color translations in the Player Setup menu
Browse files Browse the repository at this point in the history
Simplified the math for determining the translation table index in
loadDoomPatch(). Also added an assertion in the engine's patch
loader to make sure translations don't go past the end of the
translation table array.

Todo: Fix the in-game player colors.
  • Loading branch information
skyjake committed Jul 1, 2012
1 parent f412d80 commit 8162e1e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -44,6 +44,9 @@ extern "C" {
struct texture_s;
struct font_s;

// Maximum number of palette translation tables.
#define MAX_TRANSLATION_TABLES 7

// Flags for material decorations.
#define DCRF_NO_IWAD 0x1 // Don't use if from IWAD.
#define DCRF_PWAD 0x2 // Can use if from PWAD.
Expand Down
16 changes: 12 additions & 4 deletions doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -2263,9 +2263,15 @@ static void loadDoomPatch(uint8_t* buffer, int texwidth, int texheight,
assert(buffer && texwidth > 0 && texheight > 0 && patch);

w = SHORT(patch->width);

if(tmap || tclass)
{ // We need to translate the patch.
trans = MAX_OF(0, -256 + tclass * ((8-1) * 256) + tmap * 256);
{
// We need to translate the patch.
trans = MAX_OF(0, 7 * tclass + tmap - 1);
DEBUG_Message(("loadDoomPatch: tclass=%i tmap=%i => TransPal# %i\n",
tclass, tmap, trans));

trans *= 256;
}

destTop = buffer + origx;
Expand Down Expand Up @@ -2301,8 +2307,10 @@ static void loadDoomPatch(uint8_t* buffer, int texwidth, int texheight,

if(trans >= 0)
{
/// @todo Check bounds!
palidx = *(translationTables + trans + palidx);
// Check bounds.
assert(trans + palidx < 256 * 3 * MAX_TRANSLATION_TABLES);

palidx = translationTables[trans + palidx];
}

// Is the destination within bounds?
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/r_data.c
Expand Up @@ -2547,7 +2547,7 @@ void R_UpdateData(void)

void R_InitTranslationTables(void)
{
translationTables = Z_Calloc(256 * 3 * 7, PU_REFRESHTRANS, 0);
translationTables = Z_Calloc(256 * 3 * MAX_TRANSLATION_TABLES, PU_REFRESHTRANS, 0);
}

void R_UpdateTranslationTables(void)
Expand Down
12 changes: 11 additions & 1 deletion doomsday/plugins/common/src/g_game.c
Expand Up @@ -550,8 +550,18 @@ void R_GetTranslation(int plrClass, int plrColor, int* tclass, int* tmap)
*tmap = plrColor;

// Fighter's colors are a bit different.
if(plrClass == PCLASS_FIGHTER && *tmap > 1)
if(plrClass == PCLASS_FIGHTER)
{
*tclass = 0;

if(plrColor == 0)
*tmap = 1;
else if(plrColor == 1)
*tmap = 2;
else if(plrColor == 2)
*tmap = 0; // untranslated Fighter is Yellow
}

}

void R_SetTranslation(mobj_t* mo)
Expand Down

0 comments on commit 8162e1e

Please sign in to comment.