First scene refactor working
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m13s

This commit is contained in:
Florian RICHER 2025-05-26 19:55:34 +02:00
parent 5b74eef561
commit 7401a9b5f3
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
6 changed files with 251 additions and 110 deletions

View file

@ -1,11 +1,16 @@
use vulkano_util::renderer::VulkanoWindowRenderer;
use vulkano::command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer};
use super::{input::InputState, render::vulkan_context::VulkanContext, timer::Timer};
use super::{input::InputState, render::render_context::RenderContext, timer::Timer};
pub trait Scene {
fn load(&mut self, app: &mut App);
fn update(&mut self, app: &mut App);
fn render(&self);
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<PrimaryAutoCommandBuffer>,
);
fn unload(&mut self);
}
@ -20,10 +25,36 @@ impl SceneManager {
}
}
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<dyn Scene>) {
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<dyn Scene>> {
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<dyn Scene>> {
if let Some(current_scene) = self.current_scene.as_mut() {
if current_scene.loaded() {
return Some(current_scene);
}
}
None
}
}