From a896d7333400d52ac90ced388ced77224ca4ce1e Mon Sep 17 00:00:00 2001 From: Sally Coolatta <tehrealsalt@gmail.com> Date: Tue, 24 May 2022 15:28:36 -0400 Subject: [PATCH] Precalculate bot controller & rubberbanding These both require a couple loops to preform each, which probably adds up over multiple bots. Let's just precalculate them at the start of bot ticcmd. --- src/d_player.h | 3 +++ src/g_game.c | 3 +++ src/k_bot.c | 42 +++++++++++++++++++++++++++++++++++------- src/k_bot.h | 16 ++++++++++++++++ src/k_kart.c | 2 +- src/p_saveg.c | 4 ++++ src/p_user.c | 2 +- 7 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 606415a717..24a0c0403e 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -290,6 +290,9 @@ typedef struct botvars_s UINT8 diffincrease; // In GP: bot difficulty will increase this much next round boolean rival; // If true, they're the GP rival + fixed_t rubberband; // Bot rubberband value + UINT16 controller; // Special bot controller linedef ID + tic_t itemdelay; // Delay before using item at all tic_t itemconfirm; // When high enough, they will use their item diff --git a/src/g_game.c b/src/g_game.c index 21467e592a..13194abf98 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2403,6 +2403,9 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps) p->kickstartaccel = kickstartaccel; p->tripWireState = TRIP_NONE; + p->botvars.rubberband = FRACUNIT; + p->botvars.controller = UINT16_MAX; + memcpy(&p->respawn, &respawn, sizeof (p->respawn)); if (follower) diff --git a/src/k_bot.c b/src/k_bot.c index 0b8c753715..f9dad809a2 100644 --- a/src/k_bot.c +++ b/src/k_bot.c @@ -489,7 +489,6 @@ fixed_t K_BotRubberband(player_t *player) fixed_t rubberband = FRACUNIT; fixed_t rubbermax, rubbermin; player_t *firstplace = NULL; - line_t *botController = NULL; UINT8 i; if (player->exiting) @@ -498,14 +497,17 @@ fixed_t K_BotRubberband(player_t *player) return FRACUNIT; } - botController = K_FindBotController(player->mo); - - if (botController != NULL) + if (player->botvars.controller != UINT16_MAX) { - // No Climb Flag: Disable rubberbanding - if (botController->flags & ML_NOCLIMB) + const line_t *botController = &lines[player->botvars.controller]; + + if (botController != NULL) { - return FRACUNIT; + // No Climb Flag: Disable rubberbanding + if (botController->flags & ML_NOCLIMB) + { + return FRACUNIT; + } } } @@ -571,6 +573,22 @@ fixed_t K_BotRubberband(player_t *player) return rubberband; } +/*-------------------------------------------------- + fixed_t K_UpdateRubberband(player_t *player) + + See header file for description. +--------------------------------------------------*/ +fixed_t K_UpdateRubberband(player_t *player) +{ + fixed_t dest = K_BotRubberband(player); + fixed_t ret = player->botvars.rubberband; + + // Ease into the new value. + ret += (dest - player->botvars.rubberband) >> 3; + + return ret; +} + /*-------------------------------------------------- fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y, fixed_t cx, fixed_t cy) @@ -1269,6 +1287,16 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd) } botController = K_FindBotController(player->mo); + if (botController == NULL) + { + player->botvars.controller = UINT16_MAX; + } + else + { + player->botvars.controller = lines - botController; + } + + player->botvars.rubberband = K_UpdateRubberband(player); if (player->trickpanel != 0) { diff --git a/src/k_bot.h b/src/k_bot.h index 0762c86e9d..f031872057 100644 --- a/src/k_bot.h +++ b/src/k_bot.h @@ -87,6 +87,22 @@ boolean K_BotCanTakeCut(player_t *player); fixed_t K_BotRubberband(player_t *player); +/*-------------------------------------------------- + fixed_t K_UpdateRubberband(player_t *player); + + Eases the current rubberbanding value to the + new one, calculated by K_BotRubberband. + + Input Arguments:- + player - Player to update. + + Return:- + The new rubberband multiplier, in fixed point scale. +--------------------------------------------------*/ + +fixed_t K_UpdateRubberband(player_t *player); + + /*-------------------------------------------------- fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y, fixed_t cx, fixed_t cy); diff --git a/src/k_kart.c b/src/k_kart.c index 609bb63232..1248714eb4 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3190,7 +3190,7 @@ fixed_t K_GetKartSpeed(player_t *player, boolean doboostpower, boolean dorubberb if (dorubberband == true && K_PlayerUsesBotMovement(player) == true) { - finalspeed = FixedMul(finalspeed, K_BotRubberband(player)); + finalspeed = FixedMul(finalspeed, player->botvars.rubberband); } return finalspeed; diff --git a/src/p_saveg.c b/src/p_saveg.c index f6819eb9c3..bcd12e8e30 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -371,6 +371,8 @@ static void P_NetArchivePlayers(void) WRITEUINT8(save_p, players[i].botvars.difficulty); WRITEUINT8(save_p, players[i].botvars.diffincrease); WRITEUINT8(save_p, players[i].botvars.rival); + WRITEFIXED(save_p, players[i].botvars.rubberband); + WRITEUINT16(save_p, players[i].botvars.controller); WRITEUINT32(save_p, players[i].botvars.itemdelay); WRITEUINT32(save_p, players[i].botvars.itemconfirm); WRITESINT8(save_p, players[i].botvars.turnconfirm); @@ -647,6 +649,8 @@ static void P_NetUnArchivePlayers(void) players[i].botvars.difficulty = READUINT8(save_p); players[i].botvars.diffincrease = READUINT8(save_p); players[i].botvars.rival = (boolean)READUINT8(save_p); + players[i].botvars.rubberband = READFIXED(save_p); + players[i].botvars.controller = READUINT16(save_p); players[i].botvars.itemdelay = READUINT32(save_p); players[i].botvars.itemconfirm = READUINT32(save_p); players[i].botvars.turnconfirm = READSINT8(save_p); diff --git a/src/p_user.c b/src/p_user.c index 22d52b2583..fde4465c37 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1939,7 +1939,7 @@ static void P_3dMovement(player_t *player) // Make rubberbanding bots slow down faster if (K_PlayerUsesBotMovement(player)) { - fixed_t rubberband = K_BotRubberband(player) - FRACUNIT; + fixed_t rubberband = player->botvars.rubberband - FRACUNIT; if (rubberband > 0) { -- GitLab