diff options
| -rw-r--r-- | src/main.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 6e1322a..9089daf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,9 +84,7 @@ fn main() { canvas.clear(); canvas.present(); let mut event_pump = sdl_context.event_pump().unwrap(); - let start = std::time::Instant::now(); let frame_duration = std::time::Duration::new(0, 1_000_000_000u32 / 60); - let mut frame_count = 0; let mut state: state::State<gates::Gates, gates::GatesBullet> = state::State::new(); let mut won = false; let player_surface: sdl2::surface::Surface = sdl2::image::LoadSurface::from_file("assets/stallman.png").unwrap(); @@ -100,6 +98,7 @@ fn main() { let pbullet_texture = texture_creator.create_texture_from_surface(pbullet_surface).unwrap(); let surfaces = Textures { player: player_texture, enemy: enemy_texture, pbullet: pbullet_texture, ebullet: ebullet_texture }; 'running: loop { + let start = std::time::Instant::now(); if won { for event in event_pump.poll_iter() { match event { @@ -127,11 +126,10 @@ fn main() { } } } - let calc_time = frame_duration * frame_count; - match calc_time.checked_sub(start.elapsed()) { + /* Make sure this iteration took a whole frame */ + match frame_duration.checked_sub(start.elapsed()) { Some(t) => std::thread::sleep(t), None => (), } - frame_count += 1; } } |
