perf: don't check scheduler every iteration of runFrame loop

~20fps gain in Pokemon Emerald, nice
This commit is contained in:
Rekai Nyangadzayi Musuka 2022-05-25 12:15:11 -03:00
parent 8f5d054195
commit 41ee32b118
1 changed files with 9 additions and 6 deletions

View File

@ -50,14 +50,17 @@ pub fn run(kind: RunKind, quit: *Atomic(bool), fps: *FpsTracker, sched: *Schedul
pub fn runFrame(sched: *Scheduler, cpu: *Arm7tdmi) void { pub fn runFrame(sched: *Scheduler, cpu: *Arm7tdmi) void {
const frame_end = sched.tick + cycles_per_frame; const frame_end = sched.tick + cycles_per_frame;
while (sched.tick < frame_end) { while (true) {
if (cpu.bus.io.haltcnt == .Halt) sched.tick += 1; const next = sched.nextTimestamp();
if (cpu.bus.io.haltcnt == .Execute) cpu.step(); const run_until = std.math.min(next, frame_end);
cpu.handleDMATransfers();
while (sched.tick >= sched.nextTimestamp()) { while (sched.tick < run_until) {
sched.handleEvent(cpu); if (cpu.bus.io.haltcnt == .Execute) cpu.step() else sched.tick += 1;
cpu.handleDMATransfers();
} }
if (sched.tick >= frame_end) break;
sched.handleEvent(cpu);
} }
} }