vulkano_test/src/core/scene/mod.rs

74 lines
2 KiB
Rust

use std::error::Error;
use bevy_ecs::{schedule::Schedule, world::World};
use vulkano::sync::GpuFuture;
use crate::core::{app::context::WindowContext, scene::schedule::SceneScedule};
mod extract;
pub mod manager;
pub mod schedule;
/// Structure Scene qui contient le world et l'implémentation AsScene
pub struct Scene {
pub world: World,
pub loop_schedule: Schedule,
pub implementation: Box<dyn AsScene>,
}
impl Scene {
pub fn new(implementation: Box<dyn AsScene>, world: World) -> Self {
Self {
world,
loop_schedule: SceneScedule::base_schedule(),
implementation,
}
}
pub fn loaded(&self) -> bool {
self.implementation.loaded()
}
pub fn load(&mut self, window_context: &mut WindowContext) -> Result<(), Box<dyn Error>> {
self.implementation.load(&mut self.world, window_context)
}
pub fn update(&mut self, window_context: &WindowContext) -> Result<(), Box<dyn Error>> {
self.implementation.update(&mut self.world, window_context)
}
pub fn render(
&mut self,
acquire_future: Box<dyn GpuFuture>,
window_context: &mut WindowContext,
) -> Result<Box<dyn GpuFuture>, Box<dyn Error>> {
self.implementation
.render(acquire_future, &mut self.world, window_context)
}
pub fn unload(&mut self) {
self.implementation.unload()
}
}
/// Trait pour les implémentations de scènes
pub trait AsScene {
fn loaded(&self) -> bool;
fn load(
&mut self,
world: &mut World,
window_context: &mut WindowContext,
) -> Result<(), Box<dyn Error>>;
fn update(
&mut self,
world: &mut World,
window_context: &WindowContext,
) -> Result<(), Box<dyn Error>>;
fn render(
&mut self,
acquire_future: Box<dyn GpuFuture>,
world: &mut World,
window_context: &mut WindowContext,
) -> Result<Box<dyn GpuFuture>, Box<dyn Error>>;
fn unload(&mut self);
}