From 7843c882bfbb44a397624ef4292d3314eaf61440 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 17 Jul 2025 00:06:13 +0200 Subject: [PATCH] optimization K_KartUpdatePosition this checked the distance to every single waypoint on the map always and unconditionally, but we dont need the distance unconditionally so only check if we need to +5fps in techbatics hadal classic timedemo --- src/k_kart.c | 59 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 319675196..a481f2750 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -6201,32 +6201,47 @@ void K_KartUpdatePosition(player_t *player) // This checks every thing on the map, and looks for MT_BOSS3WAYPOINT (the thing we're using for checkpoint wp's, for now) for (mo = waypointcap; mo != NULL; mo = mo->tracer) { - pmo = P_AproxDistance(P_AproxDistance( mo->x - player->mo->x, - mo->y - player->mo->y), - mo->z - player->mo->z) / FRACUNIT; - imo = P_AproxDistance(P_AproxDistance( mo->x - players[i].mo->x, - mo->y - players[i].mo->y), - mo->z - players[i].mo->z) / FRACUNIT; + const boolean isprevcheckpointp = mo->health == player->starpostnum; + const boolean isnextcheckpointp = mo->health == (player->starpostnum + 1); - if (mo->health == player->starpostnum && (!mo->movecount || mo->movecount == player->laps+1)) + if ((isprevcheckpointp || isnextcheckpointp) && (!mo->movecount || mo->movecount == player->laps+1)) { - player->kartstuff[k_prevcheck] += pmo; - ppcd++; + pmo = P_AproxDistance(P_AproxDistance( mo->x - player->mo->x, + mo->y - player->mo->y), + mo->z - player->mo->z) / FRACUNIT; + + if (isprevcheckpointp) + { + player->kartstuff[k_prevcheck] += pmo; + ppcd++; + } + + if (isnextcheckpointp) + { + player->kartstuff[k_nextcheck] += pmo; + pncd++; + } } - if (mo->health == (player->starpostnum + 1) && (!mo->movecount || mo->movecount == player->laps+1)) + + const boolean isprevcheckpointi = mo->health == players[i].starpostnum; + const boolean isnextcheckpointi = mo->health == (players[i].starpostnum + 1); + + if ((isprevcheckpointi || isnextcheckpointi) && (!mo->movecount || mo->movecount == players[i].laps+1)) { - player->kartstuff[k_nextcheck] += pmo; - pncd++; - } - if (mo->health == players[i].starpostnum && (!mo->movecount || mo->movecount == players[i].laps+1)) - { - players[i].kartstuff[k_prevcheck] += imo; - ipcd++; - } - if (mo->health == (players[i].starpostnum + 1) && (!mo->movecount || mo->movecount == players[i].laps+1)) - { - players[i].kartstuff[k_nextcheck] += imo; - incd++; + imo = P_AproxDistance(P_AproxDistance( mo->x - players[i].mo->x, + mo->y - players[i].mo->y), + mo->z - players[i].mo->z) / FRACUNIT; + + if (isprevcheckpointi) + { + players[i].kartstuff[k_prevcheck] += imo; + ipcd++; + } + if (isnextcheckpointi ) + { + players[i].kartstuff[k_nextcheck] += imo; + incd++; + } } }