Refactor app context and render pass manager
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 9m10s

This commit is contained in:
Florian RICHER 2025-05-30 19:04:46 +02:00
parent f1ae54bc73
commit 2c169548b9
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
12 changed files with 846 additions and 466 deletions

View file

@ -1,52 +1,84 @@
use std::error::Error;
use super::{Scene, SceneContext};
use crate::core::app::context::ApplicationContext;
use super::Scene;
pub struct SceneManager {
current_scene: Option<Box<dyn Scene>>,
scenes: Vec<Box<dyn Scene>>,
current_scene_index: Option<usize>,
}
impl SceneManager {
pub fn new() -> Self {
Self {
current_scene: None,
scenes: Vec::new(),
current_scene_index: None,
}
}
pub fn load_scene(&mut self, scene: Box<dyn Scene>) {
self.scenes.push(scene);
self.current_scene_index = Some(self.scenes.len() - 1);
}
pub fn replace_current_scene(&mut self, scene: Box<dyn Scene>) {
if let Some(index) = self.current_scene_index {
if index < self.scenes.len() {
self.scenes[index].unload();
self.scenes[index] = scene;
}
} else {
self.load_scene(scene);
}
}
pub fn current_scene(&self) -> Option<&Box<dyn Scene>> {
if let Some(index) = self.current_scene_index {
self.scenes.get(index)
} else {
None
}
}
pub fn current_scene_mut(&mut self) -> Option<&mut Box<dyn Scene>> {
log::debug!(
"current_scene_mut called - index: {:?}, scenes len: {}",
self.current_scene_index,
self.scenes.len()
);
if let Some(index) = self.current_scene_index {
log::debug!("Getting scene at index {}", index);
self.scenes.get_mut(index)
} else {
log::debug!("No current scene index set");
None
}
}
pub fn load_scene_if_not_loaded(
&mut self,
scene_context: &SceneContext,
app_context: &mut ApplicationContext,
) -> Result<(), Box<dyn Error>> {
if let Some(current_scene) = self.current_scene.as_mut() {
if !current_scene.loaded() {
current_scene.load(scene_context)?;
log::debug!("SceneManager::load_scene_if_not_loaded called");
log::debug!(
"Current scene index: {:?}, scenes count: {}",
self.current_scene_index,
self.scenes.len()
);
if let Some(scene) = self.current_scene_mut() {
log::debug!("Scene found, checking if loaded: {}", scene.loaded());
if !scene.loaded() {
log::debug!("Scene not loaded, loading...");
scene.load(app_context)?;
log::debug!("Scene loaded successfully");
} else {
log::debug!("Scene already loaded");
}
} else {
log::warn!("No scene found in SceneManager!");
}
Ok(())
}
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
}
}