From 2d8c10a694cf124f5c44d9a6c482b7eaa19d8abb Mon Sep 17 00:00:00 2001 From: luigi budd <4997-luigi-budd@users.noreply.git.do.srb2.org> Date: Sat, 10 May 2025 21:33:06 +0000 Subject: [PATCH] Interpolate hitlag jitters --- src/hardware/hw_main.c | 16 ++++++++++++---- src/hardware/hw_md2.c | 5 ++++- src/k_hitlag.h | 1 + src/k_hud.cpp | 6 +++++- src/r_things.cpp | 11 ++++++++--- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index a9a90fbed..de43b9958 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3115,11 +3115,15 @@ static void HWR_DrawDropShadow(mobj_t *thing, fixed_t scale) R_InterpolateMobjState(thing, FRACUNIT, &interp); } - // hitlag vibrating (todo: interp somehow?) + // hitlag vibrating if (thing->hitlag > 0 && (thing->eflags & MFE_DAMAGEHITLAG)) { - fixed_t mul = thing->hitlag * HITLAGJITTERS; + fixed_t jitters = HITLAGJITTERS; + if (R_UsingFrameInterpolation() && !paused) + jitters += (rendertimefrac / HITLAGDIV); + fixed_t mul = thing->hitlag * jitters; + // perhaps there could be a way to interp this too? if (leveltime & 1) { mul = -mul; @@ -4685,10 +4689,14 @@ static void HWR_ProjectSprite(mobj_t *thing) dispoffset = thing->dispoffset; - // hitlag vibrating (todo: interp somehow?) + // hitlag vibrating if (thing->hitlag > 0 && (thing->eflags & MFE_DAMAGEHITLAG)) { - fixed_t mul = thing->hitlag * HITLAGJITTERS; + fixed_t jitters = HITLAGJITTERS; + if (R_UsingFrameInterpolation() && !paused) + jitters += (rendertimefrac / HITLAGDIV); + + fixed_t mul = thing->hitlag * jitters; if (leveltime & 1) { diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 7a49edcb8..07dc450ef 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1402,7 +1402,10 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) // hitlag vibrating if (spr->mobj->hitlag > 0 && (spr->mobj->eflags & MFE_DAMAGEHITLAG)) { - fixed_t mul = spr->mobj->hitlag * HITLAGJITTERS; + fixed_t jitters = HITLAGJITTERS; + if (R_UsingFrameInterpolation() && !paused) + jitters += (rendertimefrac / HITLAGDIV); + fixed_t mul = spr->mobj->hitlag * jitters; if (leveltime & 1) { diff --git a/src/k_hitlag.h b/src/k_hitlag.h index c5c0944d5..f999c2181 100644 --- a/src/k_hitlag.h +++ b/src/k_hitlag.h @@ -22,6 +22,7 @@ extern "C" { #define MAXHITLAGTICS (30) #define HITLAGJITTERS (FRACUNIT / 20) +#define HITLAGDIV (20) // define this so we arent using a magic number for interp #define NUM_HITLAG_STATES (9) #define NUM_HITLAG_SOUNDS (4) diff --git a/src/k_hud.cpp b/src/k_hud.cpp index 4e6adebaa..7eaa48447 100644 --- a/src/k_hud.cpp +++ b/src/k_hud.cpp @@ -5317,7 +5317,11 @@ static void K_drawKartFirstPerson(void) // hitlag vibrating if (stplyr->mo->hitlag > 0 && (stplyr->mo->eflags & MFE_DAMAGEHITLAG)) { - fixed_t mul = stplyr->mo->hitlag * HITLAGJITTERS; + fixed_t jitters = HITLAGJITTERS; + if (R_UsingFrameInterpolation() && !paused) + jitters += (rendertimefrac / HITLAGDIV); + + fixed_t mul = stplyr->mo->hitlag * jitters; if (r_splitscreen && mul > FRACUNIT) mul = FRACUNIT; diff --git a/src/r_things.cpp b/src/r_things.cpp index ac23b679c..e48bb9b15 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1794,7 +1794,7 @@ static void R_ProjectSprite(mobj_t *thing) this_scale = interp.scale; - // hitlag vibrating (todo: interp somehow?) + // hitlag vibrating if (thing->hitlag > 0 && (thing->eflags & MFE_DAMAGEHITLAG)) { fixed_t mul = thing->hitlag * HITLAGJITTERS; @@ -2172,10 +2172,15 @@ static void R_ProjectSprite(mobj_t *thing) R_InterpolateMobjState(thing, FRACUNIT, &tracer_interp); } - // hitlag vibrating (todo: interp somehow?) + // hitlag vibrating if (thing->hitlag > 0 && (thing->eflags & MFE_DAMAGEHITLAG)) { - fixed_t mul = thing->hitlag * (FRACUNIT / 10); + // previous code multiplied by (FRACUNIT / 10) instead of HITLAGJITTERS, um wadaflip + fixed_t jitters = HITLAGJITTERS; + if (R_UsingFrameInterpolation() && !paused) + jitters += (rendertimefrac / HITLAGDIV); + + fixed_t mul = thing->hitlag * jitters; if (leveltime & 1) {