mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-12-28 10:42:34 +00:00
Sprite offset code
This commit is contained in:
parent
c2b18a989c
commit
f210b4a417
4 changed files with 49 additions and 15 deletions
|
|
@ -87,7 +87,10 @@ enum mobj_e {
|
|||
#endif
|
||||
mobj_colorized,
|
||||
mobj_shadowscale,
|
||||
mobj_whiteshadow
|
||||
mobj_whiteshadow,
|
||||
mobj_sprxoff,
|
||||
mobj_spryoff,
|
||||
mobj_sprzoff
|
||||
};
|
||||
|
||||
static const char *const mobj_opt[] = {
|
||||
|
|
@ -153,6 +156,9 @@ static const char *const mobj_opt[] = {
|
|||
"colorized",
|
||||
"shadowscale",
|
||||
"whiteshadow",
|
||||
"sprxoff",
|
||||
"spryoff",
|
||||
"sprzoff",
|
||||
NULL};
|
||||
|
||||
#define UNIMPLEMENTED luaL_error(L, LUA_QL("mobj_t") " field " LUA_QS " is not implemented for Lua and cannot be accessed.", mobj_opt[field])
|
||||
|
|
@ -370,6 +376,15 @@ static int mobj_get(lua_State *L)
|
|||
case mobj_whiteshadow:
|
||||
lua_pushboolean(L, mo->whiteshadow);
|
||||
break;
|
||||
case mobj_sprxoff:
|
||||
lua_pushfixed(L, mo->sprxoff);
|
||||
break;
|
||||
case mobj_spryoff:
|
||||
lua_pushfixed(L, mo->spryoff);
|
||||
break;
|
||||
case mobj_sprzoff:
|
||||
lua_pushfixed(L, mo->sprzoff);
|
||||
break;
|
||||
default: // extra custom variables in Lua memory
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS);
|
||||
I_Assert(lua_istable(L, -1));
|
||||
|
|
@ -693,6 +708,15 @@ static int mobj_set(lua_State *L)
|
|||
case mobj_whiteshadow:
|
||||
mo->whiteshadow = luaL_checkboolean(L, 3);
|
||||
break;
|
||||
case mobj_sprxoff:
|
||||
mo->sprxoff = luaL_checkfixed(L, 3);
|
||||
break;
|
||||
case mobj_spryoff:
|
||||
mo->spryoff = luaL_checkfixed(L, 3);
|
||||
break;
|
||||
case mobj_sprzoff:
|
||||
mo->sprzoff = luaL_checkfixed(L, 3);
|
||||
break;
|
||||
default:
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS);
|
||||
I_Assert(lua_istable(L, -1));
|
||||
|
|
|
|||
|
|
@ -378,6 +378,8 @@ typedef struct mobj_s
|
|||
fixed_t shadowscale; // If this object casts a shadow, and the size relative to radius
|
||||
boolean whiteshadow; // Use white shadow, set to true by default for fullbright objects
|
||||
|
||||
fixed_t sprxoff, spryoff, sprzoff; // Sprite offsets in real space, does NOT affect position or collision
|
||||
|
||||
// WARNING: New fields must be added separately to savegame and Lua.
|
||||
} mobj_t;
|
||||
|
||||
|
|
|
|||
|
|
@ -1674,6 +1674,10 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj)
|
|||
ghost->modeltilt = mobj->modeltilt;
|
||||
#endif
|
||||
|
||||
ghost->sprxoff = mobj->sprxoff;
|
||||
ghost->spryoff = mobj->spryoff;
|
||||
ghost->sprzoff = mobj->sprzoff;
|
||||
|
||||
if (mobj->flags2 & MF2_OBJECTFLIP)
|
||||
ghost->flags |= MF2_OBJECTFLIP;
|
||||
|
||||
|
|
|
|||
|
|
@ -1435,6 +1435,10 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale,
|
|||
//
|
||||
static void R_ProjectSprite(mobj_t *thing)
|
||||
{
|
||||
const fixed_t thingxpos = thing->x + thing->sprxoff;
|
||||
const fixed_t thingypos = thing->y + thing->spryoff;
|
||||
const fixed_t thingzpos = thing->z + thing->sprzoff;
|
||||
|
||||
fixed_t tr_x, tr_y;
|
||||
fixed_t gxt, gyt;
|
||||
fixed_t tx, tz;
|
||||
|
|
@ -1471,8 +1475,8 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
fixed_t this_scale = thing->scale;
|
||||
|
||||
// transform the origin point
|
||||
tr_x = thing->x - viewx;
|
||||
tr_y = thing->y - viewy;
|
||||
tr_x = thingxpos - viewx;
|
||||
tr_y = thingypos - viewy;
|
||||
|
||||
gxt = FixedMul(tr_x, viewcos);
|
||||
gyt = -FixedMul(tr_y, viewsin);
|
||||
|
|
@ -1538,9 +1542,9 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
if (sprframe->rotate != SRF_SINGLE || papersprite)
|
||||
{
|
||||
if (thing->player)
|
||||
ang = R_PointToAngle (thing->x, thing->y) - thing->player->frameangle;
|
||||
ang = R_PointToAngle (thingxpos, thingypos) - thing->player->frameangle;
|
||||
else
|
||||
ang = R_PointToAngle (thing->x, thing->y) - thing->angle;
|
||||
ang = R_PointToAngle (thingxpos, thingypos) - thing->angle;
|
||||
}
|
||||
|
||||
if (sprframe->rotate == SRF_SINGLE)
|
||||
|
|
@ -1553,7 +1557,7 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
else
|
||||
{
|
||||
// choose a different rotation based on player view
|
||||
//ang = R_PointToAngle (thing->x, thing->y) - thing->angle;
|
||||
//ang = R_PointToAngle (thingxpos, thingypos) - thing->angle;
|
||||
|
||||
if ((ang < ANGLE_180) && (sprframe->rotate & SRF_RIGHT)) // See from right
|
||||
rot = 6; // F7 slot
|
||||
|
|
@ -1700,7 +1704,7 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
if (x2 < portalclipstart || x1 > portalclipend)
|
||||
return;
|
||||
|
||||
if (P_PointOnLineSide(thing->x, thing->y, portalclipline) != 0)
|
||||
if (P_PointOnLineSide(thingxpos, thingypos, portalclipline) != 0)
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1710,12 +1714,12 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
// When vertical flipped, draw sprites from the top down, at least as far as offsets are concerned.
|
||||
// sprite height - sprite topoffset is the proper inverse of the vertical offset, of course.
|
||||
// remember gz and gzt should be seperated by sprite height, not thing height - thing height can be shorter than the sprite itself sometimes!
|
||||
gz = thing->z + thing->height - FixedMul(spritecachedinfo[lump].topoffset, this_scale);
|
||||
gz = thingzpos + thing->height - FixedMul(spritecachedinfo[lump].topoffset, this_scale);
|
||||
gzt = gz + FixedMul(spritecachedinfo[lump].height, this_scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
gzt = thing->z + FixedMul(spritecachedinfo[lump].topoffset, this_scale);
|
||||
gzt = thingzpos + FixedMul(spritecachedinfo[lump].topoffset, this_scale);
|
||||
gz = gzt - FixedMul(spritecachedinfo[lump].height, this_scale);
|
||||
}
|
||||
|
||||
|
|
@ -1732,7 +1736,7 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
light = thing->subsector->sector->numlights - 1;
|
||||
|
||||
for (lightnum = 1; lightnum < thing->subsector->sector->numlights; lightnum++) {
|
||||
fixed_t h = thing->subsector->sector->lightlist[lightnum].slope ? P_GetZAt(thing->subsector->sector->lightlist[lightnum].slope, thing->x, thing->y)
|
||||
fixed_t h = thing->subsector->sector->lightlist[lightnum].slope ? P_GetZAt(thing->subsector->sector->lightlist[lightnum].slope, thingxpos, thingypos)
|
||||
: thing->subsector->sector->lightlist[lightnum].height;
|
||||
if (h <= gzt) {
|
||||
light = lightnum - 1;
|
||||
|
|
@ -1761,12 +1765,12 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
if (heightsec != -1 && phs != -1) // only clip things which are in special sectors
|
||||
{
|
||||
if (viewz < sectors[phs].floorheight ?
|
||||
thing->z >= sectors[heightsec].floorheight :
|
||||
thingzpos >= sectors[heightsec].floorheight :
|
||||
gzt < sectors[heightsec].floorheight)
|
||||
return;
|
||||
if (viewz > sectors[phs].ceilingheight ?
|
||||
gzt < sectors[heightsec].ceilingheight && viewz >= sectors[heightsec].ceilingheight :
|
||||
thing->z >= sectors[heightsec].ceilingheight)
|
||||
thingzpos >= sectors[heightsec].ceilingheight)
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1777,12 +1781,12 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
vis->scale = yscale; //<<detailshift;
|
||||
vis->sortscale = sortscale;
|
||||
vis->dispoffset = thing->info->dispoffset; // Monster Iestyn: 23/11/15
|
||||
vis->gx = thing->x;
|
||||
vis->gy = thing->y;
|
||||
vis->gx = thingxpos;
|
||||
vis->gy = thingypos;
|
||||
vis->gz = gz;
|
||||
vis->gzt = gzt;
|
||||
vis->thingheight = thing->height;
|
||||
vis->pz = thing->z;
|
||||
vis->pz = thingzpos;
|
||||
vis->pzt = vis->pz + vis->thingheight;
|
||||
vis->texturemid = vis->gzt - viewz;
|
||||
vis->scalestep = scalestep;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue