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.
This commit is contained in:
Sally Coolatta 2022-05-24 15:28:36 -04:00
parent 529a99bc17
commit a896d73334
7 changed files with 63 additions and 9 deletions

View file

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

View file

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

View file

@ -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)
{

View file

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

View file

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

View file

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

View file

@ -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)
{