From 0c5b42a07e2456e7902785d07cbabb722dce18c3 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sat, 10 Sep 2022 03:59:04 -0400 Subject: [PATCH] Stop lag when bots respawn They try to predict their direction while they respawn, which makes them go a bit nuts when air time compensation kicks in. Cap it so that this can't happen. --- src/k_bot.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/k_bot.c b/src/k_bot.c index a2c9f0a11..360bc006d 100644 --- a/src/k_bot.c +++ b/src/k_bot.c @@ -298,7 +298,7 @@ boolean K_BotCanTakeCut(player_t *player) /*-------------------------------------------------- static fixed_t K_BotSpeedScaled(player_t *player, fixed_t speed) - Gets the bot's speed value, adjusted for predictions. + What the bot "thinks" their speed is, for predictions. Mainly to make bots brake earlier when on friction sectors. Input Arguments:- @@ -312,6 +312,12 @@ static fixed_t K_BotSpeedScaled(player_t *player, fixed_t speed) { fixed_t result = speed; + if (P_IsObjectOnGround(player->mo) == false) + { + // You have no air control, so don't predict too far ahead. + return 0; + } + if (player->mo->movefactor != FRACUNIT) { fixed_t moveFactor = player->mo->movefactor; @@ -650,7 +656,8 @@ static botprediction_t *K_CreateBotPrediction(player_t *player) const fixed_t speed = K_BotSpeedScaled(player, P_AproxDistance(player->mo->momx, player->mo->momy)); const INT32 startDist = (DEFAULT_WAYPOINT_RADIUS * 2 * mapobjectscale) / FRACUNIT; - const INT32 distance = ((speed / FRACUNIT) * futuresight) + startDist; + const INT32 maxDist = startDist * 4; // This function gets very laggy when it goes far distances, and going too far isn't very helpful anyway. + const INT32 distance = min(((speed / FRACUNIT) * futuresight) + startDist, maxDist); // Halves radius when encountering a wall on your way to your destination. fixed_t radreduce = FRACUNIT;