diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:21 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:21 +0100 |
commit | 2111c1248b08236a839dcf22036f92735bceb31c (patch) | |
tree | 9313da344b7134a913d1d917162e55b35fe1e74f /stockton-render/src/lib.rs | |
parent | 102e166b040030b590df83888a1d1a47d0130f10 (diff) |
chore(all): style formatting and clippy fixes
Diffstat (limited to 'stockton-render/src/lib.rs')
-rw-r--r-- | stockton-render/src/lib.rs | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/stockton-render/src/lib.rs b/stockton-render/src/lib.rs index 0db4b76..7e7ea5b 100644 --- a/stockton-render/src/lib.rs +++ b/stockton-render/src/lib.rs @@ -21,58 +21,57 @@ extern crate gfx_hal as hal; extern crate shaderc; extern crate winit; -extern crate nalgebra_glm as na; extern crate image; extern crate log; +extern crate nalgebra_glm as na; -extern crate stockton_types; extern crate stockton_levels; +extern crate stockton_types; extern crate arrayvec; +mod culling; pub mod draw; mod error; mod types; -mod culling; -use stockton_types::World; use stockton_levels::prelude::*; +use stockton_types::World; -use error::{CreationError, FrameError}; -use draw::RenderingContext; use culling::get_visible_faces; +use draw::RenderingContext; +use error::{CreationError, FrameError}; /// Renders a world to a window when you tell it to. pub struct Renderer<'a, T: MinBSPFeatures<VulkanSystem>> { - world: World<T>, - pub context: RenderingContext<'a> + world: World<T>, + pub context: RenderingContext<'a>, } - impl<'a, T: MinBSPFeatures<VulkanSystem>> Renderer<'a, T> { - /// Create a new Renderer. - /// This initialises all the vulkan context, etc needed. - pub fn new(world: World<T>, window: &winit::window::Window) -> Result<Self, CreationError> { - let context = RenderingContext::new(window, &world.map)?; - - Ok(Renderer { - world, context - }) - } - - /// Render a single frame of the world - pub fn render_frame(&mut self) -> Result<(), FrameError>{ - // Get visible faces - let faces = get_visible_faces(self.context.camera_pos(), &self.world.map); - - // Then draw them - if let Err(_) = self.context.draw_vertices(&self.world.map, &faces) { - unsafe {self.context.handle_surface_change().unwrap()}; - - // If it fails twice, then error - self.context.draw_vertices(&self.world.map, &faces).map_err(|_| FrameError::PresentError)?; - } - - Ok(()) - } + /// Create a new Renderer. + /// This initialises all the vulkan context, etc needed. + pub fn new(world: World<T>, window: &winit::window::Window) -> Result<Self, CreationError> { + let context = RenderingContext::new(window, &world.map)?; + + Ok(Renderer { world, context }) + } + + /// Render a single frame of the world + pub fn render_frame(&mut self) -> Result<(), FrameError> { + // Get visible faces + let faces = get_visible_faces(self.context.camera_pos(), &self.world.map); + + // Then draw them + if self.context.draw_vertices(&self.world.map, &faces).is_err() { + unsafe { self.context.handle_surface_change().unwrap() }; + + // If it fails twice, then error + self.context + .draw_vertices(&self.world.map, &faces) + .map_err(|_| FrameError::PresentError)?; + } + + Ok(()) + } } |