Skip to content

Commit

Permalink
Fix FPS timing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanballs committed Oct 4, 2024
1 parent c6634a6 commit c842e51
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/mmu/ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c842e51

Please sign in to comment.