From c842e518b1556de0a361ce093a6193e5c3978eb3 Mon Sep 17 00:00:00 2001 From: Jonathan Balls Date: Fri, 4 Oct 2024 18:18:51 +0100 Subject: [PATCH] Fix FPS timing --- src/mmu/ppu.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mmu/ppu.rs b/src/mmu/ppu.rs index 5c7d142..cf2423c 100644 --- a/src/mmu/ppu.rs +++ b/src/mmu/ppu.rs @@ -111,14 +111,15 @@ impl PPU { if self.ly == 0 { // Calculate how long to sleep let elapsed = self.last_frame_time.elapsed(); + // Update last frame time + self.last_frame_time = Instant::now(); + let frame_duration = Duration::from_secs_f64(1.0 / TARGET_FPS); if elapsed < frame_duration { thread::sleep(frame_duration - elapsed); } - // Update last frame time - self.last_frame_time = Instant::now(); self.frame_number += 1; self.frame_available = true;