Add AI thinking cycle count display to frame count (#6509)

This commit is contained in:
hedara90 2025-03-31 20:35:10 +02:00 committed by GitHub
commit 3366595138
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 9 deletions

View File

@ -797,8 +797,9 @@ struct BattleStruct
u8 itemMoveIndex[MAX_BATTLERS_COUNT];
u8 pledgeMove:1;
u8 isSkyBattle:1;
u32 aiDelayTimer; // Counts number of frames AI takes to choose an action.
u32 aiDelayFrames; // Number of frames it took to choose an action.
s32 aiDelayTimer; // Counts number of frames AI takes to choose an action.
s32 aiDelayFrames; // Number of frames it took to choose an action.
s32 aiDelayCycles; // Number of cycles it took to choose an action.
u8 timesGotHit[NUM_BATTLE_SIDES][PARTY_SIZE];
u8 transformZeroToHero[NUM_BATTLE_SIDES];
u8 stickySyrupdBy[MAX_BATTLERS_COUNT];

View File

@ -131,7 +131,7 @@
#define FEATURE_FLAG_ASSERT(flag, id) STATIC_ASSERT(flag > TEMP_FLAGS_END || flag == 0, id)
#ifndef NDEBUG
// NOTE: This uses hardware timers 2 and 3; this will not work during active link connections or with the eReader
static inline void CycleCountStart()
{
REG_TM2CNT_H = 0;
@ -154,7 +154,6 @@ static inline u32 CycleCountEnd()
// return result
return REG_TM2CNT_L | (REG_TM3CNT_L << 16u);
}
#endif
struct Coords8
{

View File

@ -473,6 +473,8 @@ void SetAiLogicDataForTurn(struct AiLogicData *aiData)
battlersCount = gBattlersCount;
AI_DATA->aiCalcInProgress = TRUE;
if (DEBUG_AI_DELAY_TIMER)
CycleCountStart();
for (battlerAtk = 0; battlerAtk < battlersCount; battlerAtk++)
{
if (!IsBattlerAlive(battlerAtk))
@ -488,6 +490,9 @@ void SetAiLogicDataForTurn(struct AiLogicData *aiData)
SetBattlerAiMovesData(aiData, battlerAtk, battlersCount, weather);
}
if (DEBUG_AI_DELAY_TIMER)
// We add to existing to compound multiple calls
gBattleStruct->aiDelayCycles += CycleCountEnd();
AI_DATA->aiCalcInProgress = FALSE;
}

View File

@ -2011,14 +2011,18 @@ static void HandleChooseActionAfterDma3(u32 battler)
{
gBattleStruct->aiDelayFrames = gMain.vblankCounter1 - gBattleStruct->aiDelayTimer;
gBattleStruct->aiDelayTimer = 0;
#if DEBUG_AI_DELAY_TIMER
if (DEBUG_AI_DELAY_TIMER)
{
static const u8 sText_AIDelay[] = _("AI delay:\n{B_BUFF1} frames");
PREPARE_HWORD_NUMBER_BUFFER(gBattleTextBuff1, 3, gBattleStruct->aiDelayFrames);
BattleStringExpandPlaceholdersToDisplayedString(sText_AIDelay);
static const u8 sFramesText[] = _(" frames thinking\n");
static const u8 sCyclesText[] = _(" cycles");
ConvertIntToDecimalStringN(gDisplayedStringBattle, gBattleStruct->aiDelayFrames, STR_CONV_MODE_RIGHT_ALIGN, 3);
u8* end = StringAppend(gDisplayedStringBattle, sFramesText);
ConvertIntToDecimalStringN(end, gBattleStruct->aiDelayCycles, STR_CONV_MODE_RIGHT_ALIGN, 8);
// Clear old result once read out
gBattleStruct->aiDelayCycles = 0;
StringAppend(gDisplayedStringBattle, sCyclesText);
BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_ACTION_PROMPT);
}
#endif // DEBUG_AI_DELAY_TIMER
}
gBattlerControllerFuncs[battler] = HandleInputChooseAction;
}