diff --git a/src/main.rs b/src/main.rs index c4c471e..e448a7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ mod camera; mod renderer; +use std::time::Instant; + use anyhow::Result; use crawl::winit::event::{Event, WindowEvent}; use renderer::VoxelRenderer; @@ -39,6 +41,7 @@ fn main() -> Result<()> { let renderer = VoxelRenderer::new(&context, &camera_controller)?; let passes: Vec> = vec![Box::new(renderer)]; + let mut last_render_time = Instant::now(); event_loop.run(|event, elwt| match event { Event::WindowEvent { window_id, event } if window_id == context.window.id() => { if context.handle_window_event(&event, elwt) { @@ -50,6 +53,13 @@ fn main() -> Result<()> { } if let WindowEvent::RedrawRequested = event { + let now = Instant::now(); + let dt = now - last_render_time; + last_render_time = now; + + camera_controller.update(dt); + camera_controller.update_buffer(&context); + if let Err(err) = context.render(passes.as_slice()) { log::error!("{err:?}"); }