From 90286681041aa5e10b47db293a64dd8198e8b184 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Tue, 9 Jan 2024 18:17:50 -0600 Subject: [PATCH] Make ticcmd throwdir -1, 0, or 1, add deadzone --- src/d_clisrv.c | 4 ++-- src/g_build_ticcmd.cpp | 11 +++++++---- src/k_bot.cpp | 12 ++++++------ src/k_botitem.cpp | 4 ++-- src/k_kart.c | 25 +++++++++++++------------ src/p_user.c | 13 ++++++------- 6 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1d1b2b0ba..4935299e1 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4799,7 +4799,7 @@ static void FuzzTiccmd(ticcmd_t* target) { target->forwardmove = P_RandomRange(PR_FUZZ, -MAXPLMOVE, MAXPLMOVE); target->turning = P_RandomRange(PR_FUZZ, -KART_FULLTURN, KART_FULLTURN); - target->throwdir = P_RandomRange(PR_FUZZ, -KART_FULLTURN, KART_FULLTURN); + target->throwdir = P_RandomRange(PR_FUZZ, -1, 1); target->buttons = P_RandomRange(PR_FUZZ, 0, 255); // Make fuzzed players more likely to do impactful things @@ -6002,7 +6002,7 @@ static void SV_Maketic(void) for (i = 0; i < MAXPLAYERS; i++) { packetloss[i][maketic%PACKETMEASUREWINDOW] = false; - + if (!playeringame[i]) continue; diff --git a/src/g_build_ticcmd.cpp b/src/g_build_ticcmd.cpp index 6dca175da..5e3a776cf 100644 --- a/src/g_build_ticcmd.cpp +++ b/src/g_build_ticcmd.cpp @@ -164,7 +164,7 @@ class TiccmdBuilder cmd->forwardmove = clamp(cmd->forwardmove, MAXPLMOVE); cmd->turning = clamp(cmd->turning, KART_FULLTURN); - cmd->throwdir = clamp(cmd->throwdir, KART_FULLTURN); + cmd->throwdir = clamp(cmd->throwdir, 1); // Send leveltime when this tic was generated to the server for control lag calculations. // Only do this when in a level. Also do this after the hook, so that it can't overwrite this. @@ -338,9 +338,12 @@ class TiccmdBuilder } // But forward/backward IS used for aiming. - if (joystickvector.yaxis != 0) + // throwdir > 0 throws forward, throwdir < 0 throws backward + // but we always use -1, 0 or 1 for consistency here. + // this allows the throw deadzone to be adjusted in the future without breaking demos + if (std::abs(joystickvector.yaxis) > JOYAXISRANGE / 2) { - cmd->throwdir -= (joystickvector.yaxis * KART_FULLTURN) / JOYAXISRANGE; + cmd->throwdir = -std::clamp(joystickvector.yaxis, -1, 1); } } @@ -374,7 +377,7 @@ class TiccmdBuilder kart_analog_input(); // Digital users can input diagonal-back for shallow turns. - // + // // There's probably some principled way of doing this in the gamepad handler itself, // by only applying this filtering to inputs sourced from an axis. This is a little // ugly with the current abstractions, though, and there's a fortunate trick here: diff --git a/src/k_bot.cpp b/src/k_bot.cpp index 6f7af8b32..53724dded 100644 --- a/src/k_bot.cpp +++ b/src/k_bot.cpp @@ -498,7 +498,7 @@ fixed_t K_BotMapModifier(void) { constexpr INT32 complexity_scale = 10000; constexpr fixed_t modifier_max = FRACUNIT * 2; - + const fixed_t complexity_value = std::clamp( FixedDiv(K_GetTrackComplexity(), complexity_scale), -FixedDiv(FRACUNIT, modifier_max), @@ -1204,10 +1204,10 @@ static void K_BotTrick(const player_t *player, ticcmd_t *cmd, const botcontrolle cmd->turning = -KART_FULLTURN; break; case TMBOTTR_UP: - cmd->throwdir = KART_FULLTURN; + cmd->throwdir = 1; break; case TMBOTTR_DOWN: - cmd->throwdir = -KART_FULLTURN; + cmd->throwdir = -1; break; } } @@ -1298,7 +1298,7 @@ static INT32 K_HandleBotTrack(const player_t *player, ticcmd_t *cmd, botpredicti { turnsign = 1; } - else + else { turnsign = -1; } @@ -1434,7 +1434,7 @@ static INT32 K_HandleBotReverse(const player_t *player, ticcmd_t *cmd, botpredic turnsign = -1; // Turn right anglediff = AngleFixed(angle)>>FRACBITS; } - else + else { turnsign = 1; // Turn left anglediff = 360-(AngleFixed(angle)>>FRACBITS); @@ -1455,7 +1455,7 @@ static INT32 K_HandleBotReverse(const player_t *player, ticcmd_t *cmd, botpredic { momdiff = AngleFixed(angle)>>FRACBITS; } - else + else { momdiff = 360-(AngleFixed(angle)>>FRACBITS); } diff --git a/src/k_botitem.cpp b/src/k_botitem.cpp index 84baaab6b..b35221433 100644 --- a/src/k_botitem.cpp +++ b/src/k_botitem.cpp @@ -366,7 +366,7 @@ static boolean K_BotGenericPressItem(const player_t *player, ticcmd_t *cmd, SINT return false; } - cmd->throwdir = KART_FULLTURN * dir; + cmd->throwdir = std::clamp(static_cast(dir), -1, 1); cmd->buttons |= BT_ATTACK; //player->botvars.itemconfirm = 0; return true; @@ -1023,7 +1023,7 @@ static void K_BotItemBallhog(const player_t *player, ticcmd_t *cmd) if (hold == true) { - cmd->throwdir = KART_FULLTURN * throwdir; + cmd->throwdir = std::clamp(static_cast(throwdir), -1, 1); cmd->buttons |= BT_ATTACK; } } diff --git a/src/k_kart.c b/src/k_kart.c index 0054b2163..eed407236 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3792,14 +3792,14 @@ void K_DoPowerClash(mobj_t *t1, mobj_t *t2) { { t1->player->instashield = 1; t1->player->speedpunt += 20; - lag1 -= min(lag1, t1->player->speedpunt/10); + lag1 -= min(lag1, t1->player->speedpunt/10); } if (t2->player) { t2->player->instashield = 1; t2->player->speedpunt += 20; - lag2 -= min(lag1, t2->player->speedpunt/10); + lag2 -= min(lag1, t2->player->speedpunt/10); } S_StartSound(t1, sfx_parry); @@ -8149,7 +8149,7 @@ static void K_UpdateTripwire(player_t *player) if (triplevel != TRIPWIRE_CONSUME) player->tripwireLeniency = max(player->tripwireLeniency, TRIPWIRETIME); } - + // TRIPWIRE_CONSUME is only applied in very specific cases (currently, riding Garden Top) // and doesn't need leniency; however, it should track leniency from other pass conditions, // so that stripping Garden Top feels consistent. @@ -8496,10 +8496,10 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) if (P_PlayerInPain(player)) { - player->ringboost = 0; + player->ringboost = 0; } else if (player->ringboost) - { + { // These values can get FUCKED ever since ring-stacking speed changes. // If we're not actively being awarded rings, roll off extreme ringboost durations. if (player->superring == 0) @@ -8524,7 +8524,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) if (player->flamedash) { player->flamedash--; - + if (player->flamedash == 0) S_StopSoundByID(player->mo, sfx_fshld1); else if (player->flamedash == 3 && player->curshield == KSHIELD_FLAME) // "Why 3?" We can't blend sounds so this is the best shit I've got @@ -11573,7 +11573,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) UINT32 behind = K_GetItemRouletteDistance(player, player->itemRoulette.playing); UINT32 behindMulti = behind / 500; behindMulti = min(behindMulti, 60); - + UINT32 award = 5*player->ringboxaward + 10; if (!cv_thunderdome.value) @@ -12043,7 +12043,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) player->ballhogcharge++; if (player->ballhogcharge % BALLHOGINCREMENT == 0) { - sfxenum_t hogsound[] = + sfxenum_t hogsound[] = { sfx_bhog00, sfx_bhog01, @@ -12588,11 +12588,12 @@ void K_MoveKartPlayer(player_t *player, boolean onground) const angle_t angledelta = FixedAngle(36*FRACUNIT); angle_t baseangle = player->mo->angle + angledelta/2; - INT16 aimingcompare = abs(cmd->throwdir) - abs(cmd->turning); + boolean throwing = cmd->throwdir != 0; + INT16 turnmagnitude = abs(cmd->turning); // Uses cmd->turning over steering intentionally. #define TRICKTHRESHOLD (KART_FULLTURN/4) - if (aimingcompare < -TRICKTHRESHOLD) // side trick + if (abs(turnmagnitude) > TRICKTHRESHOLD && !throwing) // side trick { S_StartSoundAtVolume(player->mo, sfx_trick0, 255/2); player->dotrickfx = true; @@ -12631,7 +12632,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) P_SetPlayerMobjState(player->mo, S_KART_FAST_LOOK_R); } } - else if (aimingcompare > TRICKTHRESHOLD) // forward/back trick + else if (abs(turnmagnitude) <= TRICKTHRESHOLD && throwing) // forward/back trick { S_StartSoundAtVolume(player->mo, sfx_trick0, 255/2); player->dotrickfx = true; @@ -12702,7 +12703,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) if (P_MobjWasRemoved(player->trickIndicator) == false) trickcolor = player->trickIndicator->color; - if (player->trickpanel == TRICKSTATE_FORWARD) + if (player->trickpanel == TRICKSTATE_FORWARD) { for (j = 0; j < 2; j++) { diff --git a/src/p_user.c b/src/p_user.c index 9fb1d06b4..7d46aa6e4 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2193,7 +2193,7 @@ static INT16 P_FindClosestTurningForAngle(player_t *player, INT32 targetAngle, I // Slightly frumpy binary search for the ideal turning input. // We do this instead of reversing K_GetKartTurnValue so that future handling changes are automatically accounted for. - + while (attempts++ < 20) // Practical calls of this function search maximum 10 times, this is solely for safety. { // These need to be treated as signed, or situations where boundaries straddle 0 are a mess. @@ -2314,7 +2314,7 @@ static void P_UpdatePlayerAngle(player_t *player) // Corrections via fake turn go through easing. // That means undoing them takes the same amount of time as doing them. // This can lead to oscillating death spiral states on a multi-tic correction, as we swing past the target angle. - // So before we go into death-spirals, if our predicton is _almost_ right... + // So before we go into death-spirals, if our predicton is _almost_ right... angle_t leniency = (4*ANG1/3) * min(player->cmd.latency, 6); // Don't force another turning tic, just give them the desired angle! @@ -2413,7 +2413,7 @@ void P_MovePlayer(player_t *player) ////////////////////// P_UpdatePlayerAngle(player); - + ticruned++; if (!(cmd->flags & TICCMD_RECEIVED)) ticmiss++; @@ -4131,12 +4131,11 @@ void P_PlayerThink(player_t *player) // Save the dir the player is holding // to allow items to be thrown forward or backward. { - const INT16 threshold = 0; //(KART_FULLTURN / 2); - if (cmd->throwdir > threshold) + if (cmd->throwdir > 0) { player->throwdir = 1; } - else if (cmd->throwdir < -threshold) + else if (cmd->throwdir < 0) { player->throwdir = -1; } @@ -4452,7 +4451,7 @@ void P_PlayerThink(player_t *player) { player->stairjank--; } - + // Random skin / "ironman" { UINT32 skinflags = (demo.playback)