use vulkano::command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer}; use super::{input::InputState, render::render_context::RenderContext, timer::Timer}; pub trait Scene { fn loaded(&self) -> bool; fn load(&mut self, render_context: &RenderContext); fn update(&mut self, render_context: &RenderContext, input_state: &InputState, timer: &Timer); fn render( &self, render_context: &RenderContext, builder: &mut AutoCommandBufferBuilder, ); fn unload(&mut self); } pub struct SceneManager { current_scene: Option>, } impl SceneManager { pub fn new() -> Self { Self { current_scene: None, } } pub fn load_scene_if_not_loaded(&mut self, render_context: &RenderContext) { if let Some(current_scene) = self.current_scene.as_mut() { if !current_scene.loaded() { current_scene.load(render_context); } } } pub fn load_scene(&mut self, scene: Box) { if let Some(current_scene) = self.current_scene.as_mut() { current_scene.unload(); } self.current_scene = Some(scene); } pub fn current_scene(&self) -> Option<&Box> { if let Some(current_scene) = self.current_scene.as_ref() { if current_scene.loaded() { return Some(current_scene); } } None } pub fn current_scene_mut(&mut self) -> Option<&mut Box> { if let Some(current_scene) = self.current_scene.as_mut() { if current_scene.loaded() { return Some(current_scene); } } None } }