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 "../f_finale.h"
#include "../r_things.h" // R_GetShadowZ
#include "../r_translation.h"
#include "../d_main.h"
#include "../p_slopes.h"
#include "hw_md2.h"
@ -5504,6 +5505,12 @@ static void HWR_ProjectSprite(mobj_t *thing)
else
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)
{
// New colormap stuff for skins Tails 06-07-2002

View file

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

View file

@ -331,9 +331,14 @@ typedef struct mobj_s
UINT16 eflags; // extra flags
void *skin; // overrides 'sprite' when non-NULL (for player bodies to 'remember' the skin)
// Player and mobj sprites in multiplayer modes are modified
// 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 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_DISPOFFSET = 1<<23,
MD2_DRAWONLYFORPLAYER = 1<<24,
MD2_DONTDRAWFORVIEWMOBJ = 1<<25
MD2_DONTDRAWFORVIEWMOBJ = 1<<25,
MD2_TRANSLATION = 1<<26
} mobj_diff2_t;
typedef enum
@ -1767,6 +1768,8 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type)
diff2 |= MD2_CVMEM;
if (mobj->color)
diff2 |= MD2_COLOR;
if (mobj->translation)
diff2 |= MD2_TRANSLATION;
if (mobj->skin)
diff2 |= MD2_SKIN;
if (mobj->extravalue1)
@ -2000,6 +2003,8 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type)
WRITEUINT32(save_p, mobj->dontdrawforviewmobj->mobjnum);
if (diff2 & MD2_DISPOFFSET)
WRITEINT32(save_p, mobj->dispoffset);
if (diff2 & MD2_TRANSLATION)
WRITEUINT16(save_p, mobj->translation);
WRITEUINT32(save_p, mobj->mobjnum);
}
@ -3062,6 +3067,8 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
mobj->dispoffset = READINT32(save_p);
else
mobj->dispoffset = mobj->info->dispoffset;
if (diff2 & MD2_TRANSLATION)
mobj->translation = READUINT16(save_p);
if (diff & MD_REDFLAG)
{

View file

@ -25,6 +25,7 @@
#include "i_system.h"
#include "r_fps.h"
#include "r_things.h"
#include "r_translation.h"
#include "r_patch.h"
#include "r_patchrotation.h"
#include "r_picformats.h"
@ -785,13 +786,18 @@ UINT8 *R_GetSpriteTranslation(vissprite_t *vis)
else
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)
{
// 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);
else if (!(vis->cut & SC_PRECIP)
&& vis->mobj->player && vis->mobj->player->dashmode >= DASHMODE_THRESHOLD
else if (vis->mobj->player && vis->mobj->player->dashmode >= DASHMODE_THRESHOLD
&& (vis->mobj->player->charflags & SF_DASHMODE)
&& ((leveltime/2) & 1))
{
@ -800,7 +806,7 @@ UINT8 *R_GetSpriteTranslation(vissprite_t *vis)
else
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;
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->color = thing->color;
shadow->translation = 0;
shadow->x1 = x1 < portalclipstart ? portalclipstart : x1;
shadow->x2 = x2 >= portalclipend ? portalclipend-1 : x2;
@ -2232,6 +2239,11 @@ static void R_ProjectSprite(mobj_t *thing)
else
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->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->heightsec = thing->subsector->sector->heightsec;
vis->color = SKINCOLOR_NONE;
vis->translation = 0;
// Fullbright
vis->colormap = colormaps;

View file

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

View file

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