From 76e16d6a718cfb5dde5163063c75f19c9cb0f84c Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Sun, 8 Dec 2024 23:44:04 +0200 Subject: [PATCH] improve fps emulation --- src/emulator.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/emulator.rs b/src/emulator.rs index 6a91e26..a6be727 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -114,15 +114,15 @@ where fn emulation_loop(&mut self) -> Result<(), anyhow::Error> { let mut timers_timer = Instant::now(); let mut tick_timer = Instant::now(); - let target_fps: f32 = 60.0; + let target_fps: u128 = 60; loop { // Handle sound and delay timer. self.handle_timers(&mut timers_timer); let now = Instant::now(); let elapsed_time = now.duration_since(tick_timer); - let elapsed_seconds = elapsed_time.as_secs_f32(); - if elapsed_seconds >= (1.0 / target_fps) { + let elapsed_ms = elapsed_time.as_millis(); + if elapsed_ms >= (1000 / target_fps) { for _ in 0..=7 { // fetch instruction & decode it let instruction = self.fetch_instruction()?;