From b9553e4c9eebb130e4c542275520bfc32fa245fd Mon Sep 17 00:00:00 2001 From: minenice55 Date: Thu, 23 Apr 2026 12:59:06 -0400 Subject: [PATCH] redo kart tilt offsetting code also caught some more issues with sprite offsets, should be perfect now(?) --- src/hardware/hw_things.c | 10 +++++++--- src/k_kart.c | 26 ++++++++++++++------------ src/r_things.cpp | 27 +++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/hardware/hw_things.c b/src/hardware/hw_things.c index ee810b6af..1023f883c 100644 --- a/src/hardware/hw_things.c +++ b/src/hardware/hw_things.c @@ -1855,7 +1855,10 @@ static void HWR_ProjectSprite(mobj_t *thing) } else { - use_xoffset += (FixedDiv(interp.spritexoffset,highresscale) * (flip ? -1 : 1)); + SINT8 flipoffset = 1; + if ((thing->renderflags & RF_FLIPOFFSETS) && flip) + flipoffset = -1; + use_xoffset += (FixedDiv(interp.spritexoffset,highresscale) * flipoffset); } affine_pivotoffsetdiff.x = FIXED_TO_FLOAT(affine_pivot.x - use_xoffset); @@ -1870,8 +1873,9 @@ static void HWR_ProjectSprite(mobj_t *thing) angle = R_ConvToRollAngle(spriterotangle) * flipsign; - const fixed_t rolloffs_x = FixedDiv(interptarg->rollingxoffset * FRACUNIT, highresscale) * (((thing->renderflags & RF_FLIPOFFSETS) && flip) ? -1 : 1); - const fixed_t rolloffs_y = FixedDiv(interptarg->rollingyoffset * FRACUNIT, highresscale); + const boolean renderflip = ((thing->renderflags & RF_FLIPOFFSETS) == RF_FLIPOFFSETS); + const fixed_t rolloffs_x = FixedDiv(interptarg->rollingxoffset * FRACUNIT, highresscale) * (((!renderflip) && flip) ? -1 : 1); + const fixed_t rolloffs_y = FixedDiv(interptarg->rollingyoffset * FRACUNIT, highresscale) * (((!renderflip) && vflip) ? -1 : 1); fixed_t y_piv = affine_pivot.y; if (vflip) diff --git a/src/k_kart.c b/src/k_kart.c index 6b9e7c5d0..0b1055d37 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7873,8 +7873,15 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) if (player->karttilt) { //todo: a way for skins(?) to define the tyre offset - player->mo->spriteyoffset += abs(FixedMul(player->mo->info->radius, FINESINE(FixedAngle(abs(player->karttilt))>>ANGLETOFINESHIFT))) * P_MobjFlip(player->mo); - player->mo->spritexoffset -= FixedMul(4*player->mo->info->radius, FINESINE(FixedAngle(player->karttilt)>>ANGLETOFINESHIFT)); + vector2_t tyreoffs = {player->mo->info->radius * intsign(player->karttilt), 0}; + FV2_Rotate(&tyreoffs, -player->karttilt); + player->mo->spritexoffset -= FixedMul(5 * player->mo->info->radius / 2, FSIN(FixedAngle(-player->karttilt))) - ((player->mo->info->radius * intsign(player->karttilt)) - tyreoffs.x); + player->mo->spriteyoffset += (-tyreoffs.y/2) * P_MobjFlip(player->mo); + + CONS_Debug(DBG_PLAYER, "kart tilt : %4.3f\n", FIXED_TO_FLOAT(player->karttilt)); + CONS_Debug(DBG_PLAYER, "tyreoffs x: %4.3f, y: %4.3f\n", FIXED_TO_FLOAT(tyreoffs.x), FIXED_TO_FLOAT(tyreoffs.y)); + CONS_Debug(DBG_PLAYER, "radius fac: %4.3f\n", FIXED_TO_FLOAT(player->mo->info->radius * intsign(player->karttilt))); + CONS_Debug(DBG_PLAYER, "spritexoff: %4.3f, y: %4.3f\n", FIXED_TO_FLOAT(player->mo->spritexoffset), FIXED_TO_FLOAT(player->mo->spriteyoffset)); } } @@ -9491,7 +9498,7 @@ static void K_HandleKartTilt(player_t *player) return; } - angulargravity = abs(lineargravity) * (P_IsObjectOnGround(player->mo) ? 11 : 5); + angulargravity = abs(lineargravity) * (P_IsObjectOnGround(player->mo) ? 12 : 5); // O = (linear velocity) / (distance from CoM) angaccelgravity = FixedDiv(angulargravity, abs(FixedMul(player->mo->radius, FRACUNIT + abs(FINESINE(FixedAngle(player->karttilt)>>ANGLETOFINESHIFT))))); @@ -9501,12 +9508,12 @@ static void K_HandleKartTilt(player_t *player) player->karttiltmomentum = PLAYERTILTMOMENTUMCAP * intsign(player->karttiltmomentum); } - player->karttilt += FixedMul(player->karttiltmomentum, FIXEDRADTODEG)/TICRATE; + player->karttilt = CLAMP(player->karttilt + FixedMul(player->karttiltmomentum, FIXEDRADTODEG)/TICRATE, -PLAYERTILTCAP + 1, PLAYERTILTCAP - 1); // angular drag if (player->mo->eflags & MFE_UNDERWATER) { - player->karttiltmomentum = FixedMul(player->karttiltmomentum, 75*FRACUNIT/100); + player->karttiltmomentum = FixedMul(player->karttiltmomentum, 80*FRACUNIT/100); } else { @@ -9521,19 +9528,14 @@ static void K_HandleKartTilt(player_t *player) if ((player->karttilt < 0 && startsign > 0) || (player->karttilt > 0 && startsign < 0)) { - player->karttiltmomentum = abs(player->karttiltmomentum) * intsign(player->karttilt); + player->karttiltmomentum = abs(90*player->karttiltmomentum/100) * intsign(player->karttilt); player->karttiltmomentum /= 2; - if (abs(player->karttiltmomentum) < FRACUNIT/3) + if (abs(player->karttiltmomentum) < FRACUNIT/2) { player->karttiltmomentum = 0; } player->karttilt = 0; } - else if (abs(player->karttilt) >= PLAYERTILTCAP) - { - player->karttiltmomentum = 0; - player->karttilt = CLAMP(player->karttilt, -PLAYERTILTCAP + 1, PLAYERTILTCAP - 1); - } } #undef FIXEDRADTODEG diff --git a/src/r_things.cpp b/src/r_things.cpp index a274882a1..2dbb31dde 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2398,7 +2398,26 @@ static void R_ProjectSprite(mobj_t *thing) sprinfo, (thing->frame & FF_FRAMEMASK)); - affine_pivotoffsetdiff.x = FIXED_TO_FLOAT(affine_pivot.x - spr_offset); + fixed_t use_xoffset = spr_offset; + + if (flip) + { + use_xoffset = spr_width - spr_offset; + } + + if (thing->renderflags & RF_ABSOLUTEOFFSETS) + { + use_xoffset = FixedDiv(interp.spritexoffset,highresscale); + } + else + { + SINT8 flipoffset = 1; + if ((thing->renderflags & RF_FLIPOFFSETS) && flip) + flipoffset = -1; + use_xoffset += (FixedDiv(interp.spritexoffset,highresscale) * flipoffset); + } + + affine_pivotoffsetdiff.x = FIXED_TO_FLOAT(affine_pivot.x - use_xoffset); affine_pivotoffsetdiff.y = FIXED_TO_FLOAT(affine_pivot.y - spr_topoffset); affine_scale.x = FixedMul(affine_scale.x, FixedMul(spritexscale, this_scale)); @@ -2463,7 +2482,7 @@ static void R_ProjectSprite(mobj_t *thing) if (thing->renderflags & RF_ABSOLUTEOFFSETS) { - spr_offset = FixedDiv(use_sprxoff, highresscale); + spr_offset = FixedDiv(interp.spritexoffset, highresscale); #ifdef ROTSPRITE spr_topoffset = thingyoffset; #else @@ -2477,7 +2496,7 @@ static void R_ProjectSprite(mobj_t *thing) if ((thing->renderflags & RF_FLIPOFFSETS) && flip) flipoffset = -1; - spr_offset += FixedDiv(use_sprxoff, highresscale) * flipoffset; + spr_offset += FixedDiv(interp.spritexoffset, highresscale) * flipoffset; #ifdef ROTSPRITE thingyoffset *= flipoffset; @@ -2490,7 +2509,7 @@ static void R_ProjectSprite(mobj_t *thing) #endif } - if (flip) + if ((thing->renderflags & RF_FLIPOFFSETS) && flip) offset = spr_offset - spr_width; else offset = -spr_offset;