diff --git a/include/battle.h b/include/battle.h index 6f77ea88cf..cdb21340b1 100644 --- a/include/battle.h +++ b/include/battle.h @@ -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]; diff --git a/include/global.h b/include/global.h index c033ab9b35..a6e494f03a 100644 --- a/include/global.h +++ b/include/global.h @@ -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 { diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index e04ca63e68..b823e6e23e 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -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; } diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 96404e031e..5ff81bf673 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -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; }