From d3f8b55aa971d1ef00345e80bc40365927bf08e5 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 27 Nov 2023 20:51:26 +0100 Subject: feat(engine): add support for custom camera implementations --- engine/src/lib.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'engine/src/lib.rs') diff --git a/engine/src/lib.rs b/engine/src/lib.rs index c4711f2..806d7ec 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -33,23 +33,29 @@ pub use glfw::window::Key; pub use glfw::WindowSize; #[derive(Debug)] -pub struct Engine +pub struct Engine { /// Objects have to be dropped before window. Otherwise, UB. objects: BTreeMap, light_source: Option, window: Window, - renderer: Renderer, + renderer: Renderer, delta_time: Duration, } -impl Engine +impl Engine +where + CameraT: Camera, { /// Creates and initializes a new engine. /// /// # Errors /// Will return `Err` if window creation or window configuration fails. - pub fn new(window_size: &WindowSize, window_title: &str) -> Result + pub fn new( + window_size: &WindowSize, + window_title: &str, + camera: CameraT, + ) -> Result { let window_builder = WindowBuilder::new(); @@ -66,10 +72,11 @@ impl Engine .map_err(Error::ConfigureWindowFailed)?; window.set_framebuffer_size_callback(move |new_window_size| { - Renderer::set_viewport(&Vec2::ZERO, &new_window_size); + Renderer::::set_viewport(&Vec2::ZERO, &new_window_size); }); - let renderer = Renderer::new(&window).map_err(Error::InitializeRendererFailed)?; + let renderer = + Renderer::new(&window, camera).map_err(Error::InitializeRendererFailed)?; Ok(Self { window, @@ -156,12 +163,12 @@ impl Engine } #[must_use] - pub fn camera(&self) -> &Camera + pub fn camera(&self) -> &CameraT { self.renderer.camera() } - pub fn camera_mut(&mut self) -> &mut Camera + pub fn camera_mut(&mut self) -> &mut CameraT { self.renderer.camera_mut() } -- cgit v1.2.3-18-g5258