From d34ec2ef067596dad022da9b559fb6e87d9d3024 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 11 Apr 2022 11:22:54 -0500 Subject: [PATCH] Reset view interpolation on level load --- src/p_setup.c | 6 ++++++ src/r_fps.c | 24 +++++++++++++++++++----- src/r_fps.h | 2 ++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index b4675b27d..547ad4575 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -33,6 +33,7 @@ #include "r_picformats.h" #include "r_sky.h" #include "r_draw.h" +#include "r_fps.h" // R_ResetViewInterpolation in level load #include "s_sound.h" #include "st_stuff.h" @@ -4479,6 +4480,11 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) P_MapEnd(); // tmthing is no longer needed from this point onwards + if (rendermode != render_none) + { + R_ResetViewInterpolation(); + } + // Took me 3 hours to figure out why my progression kept on getting overwritten with the titlemap... if (!titlemapinaction) { diff --git a/src/r_fps.c b/src/r_fps.c index ce30fd48e..f9f1d60c0 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -34,6 +34,7 @@ static viewvars_t sky2view_old; static viewvars_t sky2view_new; static viewvars_t *oldview = &p1view_old; +static BOOL oldview_valid = FALSE; viewvars_t *newview = &p1view_new; @@ -87,18 +88,25 @@ static void R_SetupFreelook(player_t *player, boolean skybox) void R_InterpolateView(fixed_t frac) { + viewvars_t* prevview = oldview; boolean skybox = 0; if (FIXED_TO_FLOAT(frac) < 0) frac = 0; if (frac > FRACUNIT) frac = FRACUNIT; - viewx = oldview->x + R_LerpFixed(oldview->x, newview->x, frac); - viewy = oldview->y + R_LerpFixed(oldview->y, newview->y, frac); - viewz = oldview->z + R_LerpFixed(oldview->z, newview->z, frac); + if (oldview_valid == FALSE) + { + // interpolate from newview to newview + prevview = newview; + } - viewangle = oldview->angle + R_LerpAngle(oldview->angle, newview->angle, frac); - aimingangle = oldview->aim + R_LerpAngle(oldview->aim, newview->aim, frac); + viewx = prevview->x + R_LerpFixed(prevview->x, newview->x, frac); + viewy = prevview->y + R_LerpFixed(prevview->y, newview->y, frac); + viewz = prevview->z + R_LerpFixed(prevview->z, newview->z, frac); + + viewangle = prevview->angle + R_LerpAngle(prevview->angle, newview->angle, frac); + aimingangle = prevview->aim + R_LerpAngle(prevview->aim, newview->aim, frac); viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); @@ -123,6 +131,12 @@ void R_UpdateViewInterpolation(void) p2view_old = p2view_new; sky1view_old = sky1view_new; sky2view_old = sky2view_new; + oldview_valid = TRUE; +} + +void R_ResetViewInterpolation(void) +{ + oldview_valid = FALSE; } void R_SetViewContext(enum viewcontext_e _viewcontext) diff --git a/src/r_fps.h b/src/r_fps.h index 6e3ff3adb..831ffbdc8 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -48,6 +48,8 @@ extern viewvars_t *newview; void R_InterpolateView(fixed_t frac); // Buffer the current new views into the old views. Call once after each real tic. void R_UpdateViewInterpolation(void); +// Reset the view states (e.g. after level load) so R_InterpolateView doesn't interpolate invalid data +void R_ResetViewInterpolation(void); // Set the current view context (the viewvars pointed to by newview) void R_SetViewContext(enum viewcontext_e _viewcontext);