Copy Interpolation to Shields and Overlays, Splitscreen Overlays

from https://git.do.srb2.org/STJr/SRB2/-/merge_requests/1992
This commit is contained in:
Alug committed 2024-01-15 08:25:54 +01:00
1 parent ad77f11859
commit 66a72eb1be
5 files changed
+72 -27

No files matched your search

+2
View File
@@ -5314,6 +5314,8 @@ void HWR_ProjectSprite(mobj_t *thing)
// transform the origin point
if (thing->type == MT_OVERLAY) // Handle overlays
R_ThingOffsetOverlay(thing, &interp.x, &interp.y);
tr_x = FIXED_TO_FLOAT(interp.x) - gr_viewx;
tr_y = FIXED_TO_FLOAT(interp.y) - gr_viewy;
+2
View File
@@ -1329,6 +1329,8 @@ void HWR_DrawMD2(gr_vissprite_t *spr)
}
#endif
if (spr->mobj->type == MT_OVERLAY) // Handle overlays
R_ThingOffsetOverlay(spr->mobj, &interp.x, &interp.y);
//Hurdler: it seems there is still a small problem with mobj angle
p.x = FIXED_TO_FLOAT(interp.x);
p.y = FIXED_TO_FLOAT(interp.y)+md2->offset;
+20 -27
View File
@@ -5972,10 +5972,11 @@ void P_RunOverlays(void)
{
// run overlays
mobj_t *mo, *next = NULL;
fixed_t destx,desty,zoffs;
for (mo = overlaycap; mo; mo = next)
{
fixed_t zoffs;
I_Assert(!P_MobjWasRemoved(mo));
// grab next in chain, then unset the chain target
@@ -5984,31 +5985,12 @@ void P_RunOverlays(void)
if (!mo->target)
continue;
if (!splitscreen /*&& rendermode != render_soft*/)
{
angle_t viewingangle;
if (players[displayplayers[0]].awayviewtics)
viewingangle = R_PointToAngle2(mo->target->x, mo->target->y, players[displayplayers[0]].awayviewmobj->x, players[displayplayers[0]].awayviewmobj->y);
else if (!camera[0].chase && players[displayplayers[0]].mo)
viewingangle = R_PointToAngle2(mo->target->x, mo->target->y, players[displayplayers[0]].mo->x, players[displayplayers[0]].mo->y);
else
viewingangle = R_PointToAngle2(mo->target->x, mo->target->y, camera[0].x, camera[0].y);
if (!(mo->state->frame & FF_ANIMATE) && mo->state->var1)
viewingangle += ANGLE_180;
destx = mo->target->x + P_ReturnThrustX(mo->target, viewingangle, FixedMul(FRACUNIT/4, mo->scale));
desty = mo->target->y + P_ReturnThrustY(mo->target, viewingangle, FixedMul(FRACUNIT/4, mo->scale));
}
else
{
destx = mo->target->x;
desty = mo->target->y;
}
mo->eflags = (mo->eflags & ~MFE_VERTICALFLIP) | (mo->target->eflags & MFE_VERTICALFLIP);
mo->scale = mo->destscale = mo->target->scale;
mo->old_scale = mo->target->old_scale;
mo->angle = mo->target->angle;
mo->old_angle = (mo->target->player ? mo->target->player->old_frameangle : mo->target->old_angle) + mo->movedir;
if ((mo->flags & MF_DONTENCOREMAP) != (mo->target->flags & MF_DONTENCOREMAP))
mo->flags ^= MF_DONTENCOREMAP;
@@ -6021,15 +6003,26 @@ void P_RunOverlays(void)
zoffs = 0;
P_UnsetThingPosition(mo);
mo->x = destx;
mo->y = desty;
mo->x = mo->target->x;
mo->y = mo->target->y;
mo->old_x = mo->target->old_x;
mo->old_y = mo->target->old_y;
mo->radius = mo->target->radius;
mo->height = mo->target->height;
if (mo->eflags & MFE_VERTICALFLIP)
mo->z = (mo->target->z + mo->target->height - mo->height) - zoffs;
{
mo->z = mo->target->z + mo->target->height - mo->height - zoffs;
if (mo->scale == mo->old_scale)
mo->old_z = mo->target->old_z + mo->target->height - mo->height - zoffs;
else // Interpolate height scale changes - mo and mo->target have the same scales here, so don't interpolate them individually
mo->old_z = mo->target->old_z + FixedMul(mo->target->height - mo->height, FixedDiv(mo->old_scale, mo->scale)) - zoffs;
}
else
mo->z = mo->target->z + zoffs;
if (mo->state->var1)
{
mo->z = mo->target->z + zoffs;
mo->old_z = mo->target->old_z + zoffs;
}
if (!(mo->state->frame & FF_ANIMATE) && mo->state->var1)
P_SetUnderlayPosition(mo);
else
P_SetThingPosition(mo);
+46
View File
@@ -1367,6 +1367,8 @@ static void R_ProjectSprite(mobj_t *thing)
this_scale = interp.scale;
// transform the origin point
if (thing->type == MT_OVERLAY) // Handle overlays
R_ThingOffsetOverlay(thing, &interp.x, &interp.y);
tr_x = interp.x - viewx;
tr_y = interp.y - viewy;
@@ -2956,6 +2958,50 @@ void R_ClipSprites(void)
}
}
// Offsets MT_OVERLAY towards the camera at render-time - Works in splitscreen!
// The &x and &y arguments should be pre-interpolated, and will be modified
void R_ThingOffsetOverlay(mobj_t *thing, fixed_t *x, fixed_t *y)
{
mobj_t *mobj = thing;
INT16 offset = 0; // Offset towards or away from the camera, and how much
fixed_t offsetscale = thing->scale; // Occasionally needs to be interpolated
angle_t viewingangle;
UINT8 looplimit = 255; // Prevent infinite loops - A chain of 255 connected overlays is enough for any sane use case
#ifdef PARANOIA
if (P_MobjWasRemoved(mobj) || !x || !y)
I_Error("R_ThingOffsetOverlay: thing, x, or y is invalid");
#endif
do // Get the overlay's offset
{
// Does the overlay use FF_ANIMATE? If not, if var1 is non-zero, it's an underlay instead of an overlay
if (!(mobj->state->frame & FF_ANIMATE) && mobj->state->var1)
offset += 1; // Underlay below the target, away from the camera
else
offset -= 1; // Overlay on top of the target, towards the camera
looplimit -= 1;
mobj = mobj->target;
} while (!P_MobjWasRemoved(mobj) && mobj->type == MT_OVERLAY && looplimit > 0); // Handle overlays following other overlays
// Does the offset scale need to be interpolated?
if (thing->scale != thing->old_scale && R_UsingFrameInterpolation() && !paused)
{
interpmobjstate_t interp = {0};
R_InterpolateMobjState(thing, rendertimefrac, &interp);
offsetscale = interp.scale;
}
// Get the angle from the camera to the X and Y coordinates
viewingangle = R_PointToAngle(*x, *y);
// Finally, offset the X and Y coordinates towards or away from the camera
*x += P_ReturnThrustX(thing, viewingangle, FixedMul(offset * (FRACUNIT/4), offsetscale));
*y += P_ReturnThrustY(thing, viewingangle, FixedMul(offset * (FRACUNIT/4), offsetscale));
}
//
// R_DrawMasked
//
+2
View File
@@ -186,6 +186,8 @@ void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2);
UINT8 *R_GetSpriteTranslation(vissprite_t *vis);
void R_ThingOffsetOverlay (mobj_t *thing, fixed_t *outx, fixed_t *outy);
// ----------
// DRAW NODES
// ----------