From ed850d3f6c09aa7fccaf5bdfa073402a4275851f Mon Sep 17 00:00:00 2001 From: Martin Griffin Date: Sat, 30 Dec 2023 10:10:40 +0000 Subject: [PATCH] VSync BENCHMARKs and avoid AdvanceRandom in tests (#3866) --- include/test/test.h | 3 +++ src/main.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/test/test.h b/include/test/test.h index 74e10ec691..790563e772 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -166,6 +166,9 @@ struct Benchmark { s32 ticks; }; static inline void BenchmarkStart(void) { gTestRunnerState.inBenchmark = TRUE; + // Wait for a v-blank so that comparing two benchmarks is not affected + // by the v-count (different numbers of IRQs may run). + VBlankIntrWait(); REG_TM3CNT = (TIMER_ENABLE | TIMER_64CLK) << 16; } diff --git a/src/main.c b/src/main.c index 537af7191b..54d25c1c10 100644 --- a/src/main.c +++ b/src/main.c @@ -23,6 +23,7 @@ #include "intro.h" #include "main.h" #include "trainer_hill.h" +#include "test_runner.h" #include "constants/rgb.h" static void VBlankIntr(void); @@ -372,7 +373,7 @@ static void VBlankIntr(void) m4aSoundMain(); TryReceiveLinkBattleData(); - if (!gMain.inBattle || !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_FRONTIER | BATTLE_TYPE_RECORDED))) + if (!gTestRunnerEnabled && (!gMain.inBattle || !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_FRONTIER | BATTLE_TYPE_RECORDED)))) AdvanceRandom(); UpdateWirelessStatusIndicatorSprite();