diff --git a/src/body.rs b/src/body.rs index c60be98..c05480e 100644 --- a/src/body.rs +++ b/src/body.rs @@ -329,6 +329,7 @@ pub struct PhysicsState{ pub models:Vec, pub modes:Vec, + pub mode_from_mode_id:std::collections::HashMap::, //the spawn point is where you spawn when you load into the map. //This is not the same as Reset which teleports you to Spawn0 pub spawn_point:glam::Vec3, @@ -557,6 +558,13 @@ impl PhysicsState { self.models.clear(); self.modes.clear(); } + pub fn get_mode(&self,mode_id:u32)->Option<&crate::model::ModeDescription>{ + if let Some(&mode)=self.mode_from_mode_id.get(&mode_id){ + self.modes.get(mode) + }else{ + None + } + } //tickless gaming pub fn run(&mut self, time_limit:TIME){ //prepare is ommitted - everything is done via instructions. diff --git a/src/main.rs b/src/main.rs index 8e14f2a..a231736 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,14 +147,22 @@ impl GlobalState{ } } } + let num_modes=self.physics.modes.len(); + for (mode_id,mode) in eshmep{ + self.physics.mode_from_mode_id.insert(mode_id,num_modes+mode); + } self.physics.modes.append(&mut modedatas.into_iter().map(|mut tup|{ tup.1.sort_by_key(|tup|tup.0); tup.2.sort_by_key(|tup|tup.0); + let mut eshmep1=std::collections::HashMap::new(); + let mut eshmep2=std::collections::HashMap::new(); model::ModeDescription{ start:tup.0, - spawns:tup.1.into_iter().map(|tup|tup.1).collect(), - ordered_checkpoints:tup.2.into_iter().map(|tup|tup.1).collect(), + spawns:tup.1.into_iter().enumerate().map(|(i,tup)|{eshmep1.insert(tup.0,i);tup.1}).collect(), + ordered_checkpoints:tup.2.into_iter().enumerate().map(|(i,tup)|{eshmep2.insert(tup.0,i);tup.1}).collect(), unordered_checkpoints:tup.3, + spawn_from_stage_id:eshmep1, + ordered_checkpoint_from_checkpoint_id:eshmep2, } }).collect()); println!("Physics Objects: {}",self.physics.models.len()); @@ -590,6 +598,7 @@ impl framework::Example for GlobalState { world:body::WorldState{}, game:body::GameMechanicsState::default(), modes:Vec::new(), + mode_from_mode_id:std::collections::HashMap::new(), }; //load textures diff --git a/src/model.rs b/src/model.rs index 0386abf..6434734 100644 --- a/src/model.rs +++ b/src/model.rs @@ -85,6 +85,24 @@ pub struct ModeDescription{ pub spawns:Vec,//spawns[spawn_id]=model_id pub ordered_checkpoints:Vec,//ordered_checkpoints[checkpoint_id]=model_id pub unordered_checkpoints:Vec,//unordered_checkpoints[checkpoint_id]=model_id + pub spawn_from_stage_id:std::collections::HashMap::, + pub ordered_checkpoint_from_checkpoint_id:std::collections::HashMap::, +} +impl ModeDescription{ + pub fn get_spawn_model_id(&self,stage_id:u32)->Option<&u32>{ + if let Some(&spawn)=self.spawn_from_stage_id.get(&stage_id){ + self.spawns.get(spawn) + }else{ + None + } + } + pub fn get_ordered_checkpoint_model_id(&self,checkpoint_id:u32)->Option<&u32>{ + if let Some(&checkpoint)=self.ordered_checkpoint_from_checkpoint_id.get(&checkpoint_id){ + self.ordered_checkpoints.get(checkpoint) + }else{ + None + } + } } pub enum TempIndexedAttributes{ Start{