Reduce code duplication

This commit is contained in:
Lactozilla 2023-10-31 16:26:51 -03:00
parent b65d8d1010
commit 62f3454268
4 changed files with 24 additions and 62 deletions

View file

@ -5504,45 +5504,7 @@ static void HWR_ProjectSprite(mobj_t *thing)
translation = thing->translation; translation = thing->translation;
//Hurdler: 25/04/2000: now support colormap in hardware mode //Hurdler: 25/04/2000: now support colormap in hardware mode
if (R_ThingIsFlashing(vis->mobj)) // Bosses "flash" vis->colormap = R_GetTranslationForThing(vis->mobj, color, translation);
{
if (vis->mobj->type == MT_CYBRAKDEMON || vis->mobj->colorized)
vis->colormap = R_GetTranslationColormap(TC_ALLWHITE, 0, GTC_CACHE);
else if (vis->mobj->type == MT_METALSONIC_BATTLE)
vis->colormap = R_GetTranslationColormap(TC_METALSONIC, 0, GTC_CACHE);
else
vis->colormap = R_GetTranslationColormap(TC_BOSS, color, GTC_CACHE);
}
else if (translation != 0)
{
remaptable_t *tr = R_GetTranslationByID(translation);
if (tr != NULL)
vis->colormap = tr->remap;
}
else if (color != SKINCOLOR_NONE)
{
// New colormap stuff for skins Tails 06-07-2002
if (thing->colorized)
vis->colormap = R_GetTranslationColormap(TC_RAINBOW, color, GTC_CACHE);
else if (thing->player && thing->player->dashmode >= DASHMODE_THRESHOLD
&& (thing->player->charflags & SF_DASHMODE)
&& ((leveltime/2) & 1))
{
if (thing->player->charflags & SF_MACHINE)
vis->colormap = R_GetTranslationColormap(TC_DASHMODE, 0, GTC_CACHE);
else
vis->colormap = R_GetTranslationColormap(TC_RAINBOW, color, GTC_CACHE);
}
else if (thing->skin && thing->sprite == SPR_PLAY) // This thing is a player!
{
size_t skinnum = (skin_t*)thing->skin-skins;
vis->colormap = R_GetTranslationColormap((INT32)skinnum, color, GTC_CACHE);
}
else
vis->colormap = NULL;
}
else
vis->colormap = NULL;
// set top/bottom coords // set top/bottom coords
vis->gzt = gzt; vis->gzt = gzt;

View file

@ -408,7 +408,7 @@ static void R_RasterizeFloorSplat(floorsplat_t *pSplat, vector2_t *verts, visspr
} }
ds_colormap = vis->colormap; ds_colormap = vis->colormap;
ds_translation = R_GetSpriteTranslation(vis); ds_translation = R_GetTranslationForThing(vis->mobj, vis->color, vis->translation);
if (ds_translation == NULL) if (ds_translation == NULL)
ds_translation = colormaps; ds_translation = colormaps;

View file

@ -766,46 +766,46 @@ void R_DrawFlippedMaskedColumn(column_t *column)
dc_texturemid = basetexturemid; dc_texturemid = basetexturemid;
} }
UINT8 *R_GetSpriteTranslation(vissprite_t *vis) UINT8 *R_GetTranslationForThing(mobj_t *mobj, skincolornum_t color, UINT16 translation)
{ {
if (R_ThingIsFlashing(vis->mobj)) // Bosses "flash" if (R_ThingIsFlashing(mobj)) // Bosses "flash"
{ {
if (vis->mobj->type == MT_CYBRAKDEMON || vis->mobj->colorized) if (mobj->type == MT_CYBRAKDEMON || mobj->colorized)
return R_GetTranslationColormap(TC_ALLWHITE, 0, GTC_CACHE); return R_GetTranslationColormap(TC_ALLWHITE, 0, GTC_CACHE);
else if (vis->mobj->type == MT_METALSONIC_BATTLE) else if (mobj->type == MT_METALSONIC_BATTLE)
return R_GetTranslationColormap(TC_METALSONIC, 0, GTC_CACHE); return R_GetTranslationColormap(TC_METALSONIC, 0, GTC_CACHE);
else else
return R_GetTranslationColormap(TC_BOSS, vis->color, GTC_CACHE); return R_GetTranslationColormap(TC_BOSS, color, GTC_CACHE);
} }
else if (vis->translation) else if (translation != 0)
{ {
remaptable_t *tr = R_GetTranslationByID(vis->translation); remaptable_t *tr = R_GetTranslationByID(translation);
if (tr != NULL) if (tr != NULL)
return tr->remap; return tr->remap;
} }
else if (vis->color) else if (color != SKINCOLOR_NONE)
{ {
// New colormap stuff for skins Tails 06-07-2002 // New colormap stuff for skins Tails 06-07-2002
if (vis->mobj->colorized) if (mobj->colorized)
return R_GetTranslationColormap(TC_RAINBOW, vis->color, GTC_CACHE); return R_GetTranslationColormap(TC_RAINBOW, color, GTC_CACHE);
else if (vis->mobj->player && vis->mobj->player->dashmode >= DASHMODE_THRESHOLD else if (mobj->player && mobj->player->dashmode >= DASHMODE_THRESHOLD
&& (vis->mobj->player->charflags & SF_DASHMODE) && (mobj->player->charflags & SF_DASHMODE)
&& ((leveltime/2) & 1)) && ((leveltime/2) & 1))
{ {
if (vis->mobj->player->charflags & SF_MACHINE) if (mobj->player->charflags & SF_MACHINE)
return R_GetTranslationColormap(TC_DASHMODE, 0, GTC_CACHE); return R_GetTranslationColormap(TC_DASHMODE, 0, GTC_CACHE);
else else
return R_GetTranslationColormap(TC_RAINBOW, vis->color, GTC_CACHE); return R_GetTranslationColormap(TC_RAINBOW, color, GTC_CACHE);
} }
else if (vis->mobj->skin && vis->mobj->sprite == SPR_PLAY) // This thing is a player! else if (mobj->skin && mobj->sprite == SPR_PLAY) // This thing is a player!
{ {
size_t skinnum = (skin_t*)vis->mobj->skin-skins; size_t skinnum = (skin_t*)mobj->skin-skins;
return R_GetTranslationColormap((INT32)skinnum, vis->color, GTC_CACHE); return R_GetTranslationColormap((INT32)skinnum, color, GTC_CACHE);
} }
else // Use the defaults else // Use the defaults
return R_GetTranslationColormap(TC_DEFAULT, vis->color, GTC_CACHE); return R_GetTranslationColormap(TC_DEFAULT, color, GTC_CACHE);
} }
else if (vis->mobj->sprite == SPR_PLAY) // Looks like a player, but doesn't have a color? Get rid of green sonic syndrome. else if (mobj->sprite == SPR_PLAY) // Looks like a player, but doesn't have a color? Get rid of green sonic syndrome.
return R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_BLUE, GTC_CACHE); return R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_BLUE, GTC_CACHE);
return NULL; return NULL;
@ -853,7 +853,7 @@ static void R_DrawVisSprite(vissprite_t *vis)
colfunc = colfuncs[BASEDRAWFUNC]; // hack: this isn't resetting properly somewhere. colfunc = colfuncs[BASEDRAWFUNC]; // hack: this isn't resetting properly somewhere.
dc_colormap = vis->colormap; dc_colormap = vis->colormap;
dc_translation = R_GetSpriteTranslation(vis); dc_translation = R_GetTranslationForThing(vis->mobj, vis->color, vis->translation);
if (R_ThingIsFlashing(vis->mobj)) // Bosses "flash" if (R_ThingIsFlashing(vis->mobj)) // Bosses "flash"
colfunc = colfuncs[COLDRAWFUNC_TRANS]; // translate certain pixels to white colfunc = colfuncs[COLDRAWFUNC_TRANS]; // translate certain pixels to white

View file

@ -90,6 +90,8 @@ boolean R_ThingIsFullDark (mobj_t *thing);
boolean R_ThingIsFlashing (mobj_t *thing); boolean R_ThingIsFlashing (mobj_t *thing);
UINT8 *R_GetTranslationForThing(mobj_t *mobj, skincolornum_t color, UINT16 translation);
// -------------- // --------------
// MASKED DRAWING // MASKED DRAWING
// -------------- // --------------
@ -229,8 +231,6 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal);
void R_DrawThingBoundingBox(vissprite_t *spr); void R_DrawThingBoundingBox(vissprite_t *spr);
UINT8 *R_GetSpriteTranslation(vissprite_t *vis);
// ---------- // ----------
// DRAW NODES // DRAW NODES
// ---------- // ----------