Add 'translation' object property

This commit is contained in:
Lactozilla 2023-10-29 23:34:18 -03:00
parent 4f873d5f8f
commit 6de7fc3223
7 changed files with 62 additions and 12 deletions

View file

@ -39,6 +39,7 @@
#include "../m_cheat.h" #include "../m_cheat.h"
#include "../f_finale.h" #include "../f_finale.h"
#include "../r_things.h" // R_GetShadowZ #include "../r_things.h" // R_GetShadowZ
#include "../r_translation.h"
#include "../d_main.h" #include "../d_main.h"
#include "../p_slopes.h" #include "../p_slopes.h"
#include "hw_md2.h" #include "hw_md2.h"
@ -5504,6 +5505,12 @@ static void HWR_ProjectSprite(mobj_t *thing)
else else
vis->colormap = R_GetTranslationColormap(TC_BOSS, vis->color, GTC_CACHE); vis->colormap = R_GetTranslationColormap(TC_BOSS, vis->color, GTC_CACHE);
} }
else if (vis->mobj->translation)
{
remaptable_t *tr = R_GetTranslationByID(vis->mobj->translation);
if (tr != NULL)
vis->colormap = tr->remap;
}
else if (vis->color) else if (vis->color)
{ {
// New colormap stuff for skins Tails 06-07-2002 // New colormap stuff for skins Tails 06-07-2002

View file

@ -14,6 +14,7 @@
#include "fastcmp.h" #include "fastcmp.h"
#include "r_data.h" #include "r_data.h"
#include "r_skins.h" #include "r_skins.h"
#include "r_translation.h"
#include "p_local.h" #include "p_local.h"
#include "g_game.h" #include "g_game.h"
#include "p_setup.h" #include "p_setup.h"
@ -66,6 +67,7 @@ enum mobj_e {
mobj_renderflags, mobj_renderflags,
mobj_skin, mobj_skin,
mobj_color, mobj_color,
mobj_translation,
mobj_blendmode, mobj_blendmode,
mobj_bnext, mobj_bnext,
mobj_bprev, mobj_bprev,
@ -146,6 +148,7 @@ static const char *const mobj_opt[] = {
"renderflags", "renderflags",
"skin", "skin",
"color", "color",
"translation",
"blendmode", "blendmode",
"bnext", "bnext",
"bprev", "bprev",
@ -338,6 +341,12 @@ static int mobj_get(lua_State *L)
case mobj_color: case mobj_color:
lua_pushinteger(L, mo->color); lua_pushinteger(L, mo->color);
break; break;
case mobj_translation:
if (mo->translation)
lua_pushinteger(L, mo->translation);
else
lua_pushnil(L);
break;
case mobj_blendmode: case mobj_blendmode:
lua_pushinteger(L, mo->blendmode); lua_pushinteger(L, mo->blendmode);
break; break;
@ -692,12 +701,21 @@ static int mobj_set(lua_State *L)
} }
case mobj_color: case mobj_color:
{ {
UINT16 newcolor = (UINT16)luaL_checkinteger(L,3); UINT16 newcolor = (UINT16)luaL_checkinteger(L, 3);
if (newcolor >= numskincolors) if (newcolor >= numskincolors)
return luaL_error(L, "mobj.color %d out of range (0 - %d).", newcolor, numskincolors-1); return luaL_error(L, "mobj.color %d out of range (0 - %d).", newcolor, numskincolors-1);
mo->color = newcolor; mo->color = newcolor;
break; break;
} }
case mobj_translation:
{
int id = R_FindCustomTranslation(luaL_checkstring(L, 3));
if (id != -1)
mo->translation = id;
else
mo->translation = 0;
break;
}
case mobj_blendmode: case mobj_blendmode:
{ {
INT32 blendmode = (INT32)luaL_checkinteger(L, 3); INT32 blendmode = (INT32)luaL_checkinteger(L, 3);

View file

@ -331,9 +331,14 @@ typedef struct mobj_s
UINT16 eflags; // extra flags UINT16 eflags; // extra flags
void *skin; // overrides 'sprite' when non-NULL (for player bodies to 'remember' the skin) void *skin; // overrides 'sprite' when non-NULL (for player bodies to 'remember' the skin)
// Player and mobj sprites in multiplayer modes are modified // Player and mobj sprites in multiplayer modes are modified
// using an internal color lookup table for re-indexing. // using an internal color lookup table for re-indexing.
UINT16 color; // This replaces MF_TRANSLATION. Use 0 for default (no translation). UINT16 color;
// This replaces MF_TRANSLATION. Use 0 for default (no translation).
UINT16 translation;
struct player_s *drawonlyforplayer; // If set, hides the mobj for everyone except this player and their spectators struct player_s *drawonlyforplayer; // If set, hides the mobj for everyone except this player and their spectators
struct mobj_s *dontdrawforviewmobj; // If set, hides the mobj if dontdrawforviewmobj is the current camera (first-person player or awayviewmobj) struct mobj_s *dontdrawforviewmobj; // If set, hides the mobj if dontdrawforviewmobj is the current camera (first-person player or awayviewmobj)

View file

@ -1578,7 +1578,8 @@ typedef enum
MD2_FLOORSPRITESLOPE = 1<<22, MD2_FLOORSPRITESLOPE = 1<<22,
MD2_DISPOFFSET = 1<<23, MD2_DISPOFFSET = 1<<23,
MD2_DRAWONLYFORPLAYER = 1<<24, MD2_DRAWONLYFORPLAYER = 1<<24,
MD2_DONTDRAWFORVIEWMOBJ = 1<<25 MD2_DONTDRAWFORVIEWMOBJ = 1<<25,
MD2_TRANSLATION = 1<<26
} mobj_diff2_t; } mobj_diff2_t;
typedef enum typedef enum
@ -1767,6 +1768,8 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type)
diff2 |= MD2_CVMEM; diff2 |= MD2_CVMEM;
if (mobj->color) if (mobj->color)
diff2 |= MD2_COLOR; diff2 |= MD2_COLOR;
if (mobj->translation)
diff2 |= MD2_TRANSLATION;
if (mobj->skin) if (mobj->skin)
diff2 |= MD2_SKIN; diff2 |= MD2_SKIN;
if (mobj->extravalue1) if (mobj->extravalue1)
@ -2000,6 +2003,8 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type)
WRITEUINT32(save_p, mobj->dontdrawforviewmobj->mobjnum); WRITEUINT32(save_p, mobj->dontdrawforviewmobj->mobjnum);
if (diff2 & MD2_DISPOFFSET) if (diff2 & MD2_DISPOFFSET)
WRITEINT32(save_p, mobj->dispoffset); WRITEINT32(save_p, mobj->dispoffset);
if (diff2 & MD2_TRANSLATION)
WRITEUINT16(save_p, mobj->translation);
WRITEUINT32(save_p, mobj->mobjnum); WRITEUINT32(save_p, mobj->mobjnum);
} }
@ -3062,6 +3067,8 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
mobj->dispoffset = READINT32(save_p); mobj->dispoffset = READINT32(save_p);
else else
mobj->dispoffset = mobj->info->dispoffset; mobj->dispoffset = mobj->info->dispoffset;
if (diff2 & MD2_TRANSLATION)
mobj->translation = READUINT16(save_p);
if (diff & MD_REDFLAG) if (diff & MD_REDFLAG)
{ {

View file

@ -25,6 +25,7 @@
#include "i_system.h" #include "i_system.h"
#include "r_fps.h" #include "r_fps.h"
#include "r_things.h" #include "r_things.h"
#include "r_translation.h"
#include "r_patch.h" #include "r_patch.h"
#include "r_patchrotation.h" #include "r_patchrotation.h"
#include "r_picformats.h" #include "r_picformats.h"
@ -785,13 +786,18 @@ UINT8 *R_GetSpriteTranslation(vissprite_t *vis)
else else
return R_GetTranslationColormap(TC_BOSS, vis->color, GTC_CACHE); return R_GetTranslationColormap(TC_BOSS, vis->color, GTC_CACHE);
} }
else if (vis->translation)
{
remaptable_t *tr = R_GetTranslationByID(vis->translation);
if (tr != NULL)
return tr->remap;
}
else if (vis->color) else if (vis->color)
{ {
// New colormap stuff for skins Tails 06-07-2002 // New colormap stuff for skins Tails 06-07-2002
if (!(vis->cut & SC_PRECIP) && vis->mobj->colorized) if (vis->mobj->colorized)
return R_GetTranslationColormap(TC_RAINBOW, vis->color, GTC_CACHE); return R_GetTranslationColormap(TC_RAINBOW, vis->color, GTC_CACHE);
else if (!(vis->cut & SC_PRECIP) else if (vis->mobj->player && vis->mobj->player->dashmode >= DASHMODE_THRESHOLD
&& vis->mobj->player && vis->mobj->player->dashmode >= DASHMODE_THRESHOLD
&& (vis->mobj->player->charflags & SF_DASHMODE) && (vis->mobj->player->charflags & SF_DASHMODE)
&& ((leveltime/2) & 1)) && ((leveltime/2) & 1))
{ {
@ -800,7 +806,7 @@ UINT8 *R_GetSpriteTranslation(vissprite_t *vis)
else else
return R_GetTranslationColormap(TC_RAINBOW, vis->color, GTC_CACHE); return R_GetTranslationColormap(TC_RAINBOW, vis->color, GTC_CACHE);
} }
else if (!(vis->cut & SC_PRECIP) && vis->mobj->skin && vis->mobj->sprite == SPR_PLAY) // This thing is a player! else if (vis->mobj->skin && vis->mobj->sprite == SPR_PLAY) // This thing is a player!
{ {
size_t skinnum = (skin_t*)vis->mobj->skin-skins; size_t skinnum = (skin_t*)vis->mobj->skin-skins;
return R_GetTranslationColormap((INT32)skinnum, vis->color, GTC_CACHE); return R_GetTranslationColormap((INT32)skinnum, vis->color, GTC_CACHE);
@ -1407,6 +1413,7 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale,
shadow->mobj = thing; // Easy access! Tails 06-07-2002 shadow->mobj = thing; // Easy access! Tails 06-07-2002
shadow->color = thing->color; shadow->color = thing->color;
shadow->translation = 0;
shadow->x1 = x1 < portalclipstart ? portalclipstart : x1; shadow->x1 = x1 < portalclipstart ? portalclipstart : x1;
shadow->x2 = x2 >= portalclipend ? portalclipend-1 : x2; shadow->x2 = x2 >= portalclipend ? portalclipend-1 : x2;
@ -2232,6 +2239,11 @@ static void R_ProjectSprite(mobj_t *thing)
else else
vis->color = oldthing->color; vis->color = oldthing->color;
if ((oldthing->flags2 & MF2_LINKDRAW) && oldthing->tracer && oldthing->translation == 0)
vis->translation = oldthing->tracer->translation;
else
vis->translation = oldthing->translation;
vis->x1 = x1 < portalclipstart ? portalclipstart : x1; vis->x1 = x1 < portalclipstart ? portalclipstart : x1;
vis->x2 = x2 >= portalclipend ? portalclipend-1 : x2; vis->x2 = x2 >= portalclipend ? portalclipend-1 : x2;
@ -2502,6 +2514,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing)
vis->extra_colormap = thing->subsector->sector->extra_colormap; vis->extra_colormap = thing->subsector->sector->extra_colormap;
vis->heightsec = thing->subsector->sector->heightsec; vis->heightsec = thing->subsector->sector->heightsec;
vis->color = SKINCOLOR_NONE; vis->color = SKINCOLOR_NONE;
vis->translation = 0;
// Fullbright // Fullbright
vis->colormap = colormaps; vis->colormap = colormaps;

View file

@ -214,6 +214,7 @@ typedef struct vissprite_s
fixed_t shadowscale; fixed_t shadowscale;
skincolornum_t color; skincolornum_t color;
UINT16 translation;
INT16 clipbot[MAXVIDWIDTH], cliptop[MAXVIDWIDTH]; INT16 clipbot[MAXVIDWIDTH], cliptop[MAXVIDWIDTH];

View file

@ -653,8 +653,7 @@ int R_FindCustomTranslation(const char *name)
for (unsigned i = 0; i < numcustomtranslations; i++) for (unsigned i = 0; i < numcustomtranslations; i++)
{ {
if (hash == customtranslations[i].hash if (hash == customtranslations[i].hash && strcmp(name, customtranslations[i].name) == 0)
&& strcmp(name, customtranslations[i].name) == 0)
return (int)customtranslations[i].id; return (int)customtranslations[i].id;
} }
@ -668,10 +667,10 @@ void R_AddCustomTranslation(const char *name, int trnum)
for (unsigned i = 0; i < numcustomtranslations; i++) for (unsigned i = 0; i < numcustomtranslations; i++)
{ {
tr = &customtranslations[i]; struct CustomTranslation *lookup = &customtranslations[i];
if (hash == tr->hash if (hash == lookup->hash && strcmp(name, lookup->name) == 0)
&& strcmp(name, tr->name) == 0)
{ {
tr = lookup;
break; break;
} }
} }