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.
This commit is contained in:
Sally Coolatta 2022-09-10 03:59:04 -04:00
parent 5107160a27
commit 0c5b42a07e

View file

@ -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;