From fb2e2afeb930e3e76bfe0ab73470918cc708bb79 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 4 Oct 2023 14:13:25 -0700 Subject: [PATCH] hashmap map ids into internal structure ids --- src/body.rs | 8 ++++++++ src/main.rs | 13 +++++++++++-- src/model.rs | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/body.rs b/src/body.rs index c60be988..c05480e9 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 8e14f2a3..a2317369 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 0386abf9..64347340 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{