- Move engine to a different crate - Add engine trait - Refactor the rest of the codebase to work with these changes - Add debug ui buffer, use it to finish imgui support
76 lines
1.6 KiB
Rust
76 lines
1.6 KiB
Rust
use std::collections::HashMap;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
pub struct Scene {
|
|
pub title: String,
|
|
pub world: hecs::World,
|
|
pub skybox_texture_path: Option<PathBuf>,
|
|
}
|
|
|
|
impl Scene {
|
|
pub fn new(title: String, skybox_texture_path: Option<PathBuf>) -> Self {
|
|
Self {
|
|
title,
|
|
world: hecs::World::new(),
|
|
skybox_texture_path,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Scene {}
|
|
|
|
impl AsRef<Scene> for Scene {
|
|
fn as_ref(&self) -> &Scene {
|
|
&self
|
|
}
|
|
}
|
|
|
|
impl AsMut<Scene> for Scene {
|
|
fn as_mut(&mut self) -> &mut Scene {
|
|
self
|
|
}
|
|
}
|
|
|
|
type SceneID = &'static str;
|
|
|
|
pub struct SceneManager {
|
|
scenes: HashMap<SceneID, Scene>,
|
|
active_scene: Option<SceneID>,
|
|
}
|
|
|
|
impl SceneManager {
|
|
pub fn new() -> Self {
|
|
let scenes = HashMap::new();
|
|
Self {
|
|
scenes,
|
|
active_scene: None,
|
|
}
|
|
}
|
|
|
|
pub fn current(&self) -> &Scene {
|
|
match &self.active_scene {
|
|
Some(id) => self.scenes[id].as_ref(),
|
|
None => panic!("No active scene"),
|
|
}
|
|
|
|
}
|
|
|
|
pub fn current_mut(&mut self) -> &mut Scene {
|
|
match &mut self.active_scene {
|
|
Some(id) => self.scenes.get_mut(id).unwrap().as_mut(),
|
|
None => panic!("No active scene"),
|
|
}
|
|
}
|
|
|
|
pub fn set_active_scene(&mut self, scene: SceneID) {
|
|
self.active_scene = Some(scene);
|
|
}
|
|
|
|
pub fn add_scene(&mut self, id: SceneID, scene: Scene) {
|
|
self.scenes.insert(id, scene);
|
|
}
|
|
|
|
pub fn remove_scene(&mut self, id: SceneID) {
|
|
self.scenes.remove(&id);
|
|
}
|
|
}
|