From 66a72eb1be1b7654c615e25a194c87c4e4d1228d Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 08:25:54 +0100 Subject: [PATCH] Copy Interpolation to Shields and Overlays, Splitscreen Overlays from https://git.do.srb2.org/STJr/SRB2/-/merge_requests/1992 --- src/hardware/hw_main.c | 2 ++ src/hardware/hw_md2.c | 2 ++ src/p_mobj.c | 47 ++++++++++++++++++------------------------ src/r_things.c | 46 +++++++++++++++++++++++++++++++++++++++++ src/r_things.h | 2 ++ 5 files changed, 72 insertions(+), 27 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d24d19b02..2c463ee9a 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -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; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 67e76a86a..fc0b4f354 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -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; diff --git a/src/p_mobj.c b/src/p_mobj.c index c2b169950..35532e3ae 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -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); diff --git a/src/r_things.c b/src/r_things.c index af5a582b1..db285b8f0 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -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 // diff --git a/src/r_things.h b/src/r_things.h index 966ff3df1..437740c0a 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -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 // ----------