Use static string literals instead of String for scene IDs

This commit is contained in:
reo 2025-08-31 12:56:05 +03:00
parent 3692736a61
commit b3b69756e6
2 changed files with 8 additions and 6 deletions

View file

@ -29,7 +29,7 @@ impl AsMut<Scene> for Scene {
}
}
type SceneID = String;
type SceneID = &'static str;
pub struct SceneManager {
scenes: HashMap<SceneID, Scene>,
@ -55,7 +55,7 @@ impl SceneManager {
pub fn current_mut(&mut self) -> &mut Scene {
match &mut self.active_scene {
Some(id) => self.scenes.get_mut(id.as_mut()).unwrap().as_mut(),
Some(id) => self.scenes.get_mut(id).unwrap().as_mut(),
None => panic!("No active scene"),
}
}

View file

@ -12,6 +12,9 @@ use raidillon_glium::GliumPlatform;
const TEST_GLTF: &str = "pink-monkey.gltf";
const RENDERING_TEST_SYSTEM: &str = "rendering_test_system";
const MAIN_SCENE_ID: &str = "main_scene";
struct RenderingTestSystem;
impl System for RenderingTestSystem {
@ -52,13 +55,12 @@ fn main() {
engine.system_manager.add_system(RENDERING_TEST_SYSTEM, Box::new(RenderingTestSystem));
// Set up the scene
let main_scene_id = "Main".to_owned();
let main_scene = Scene::new(
main_scene_id.clone(),
MAIN_SCENE_ID.to_owned(),
None,
);
engine.scene_manager.add_scene(main_scene_id.clone(), main_scene);
engine.scene_manager.set_active_scene(main_scene_id.clone());
engine.scene_manager.add_scene(MAIN_SCENE_ID, main_scene);
engine.scene_manager.set_active_scene(MAIN_SCENE_ID);
#[cfg(feature = "glium")]
{