forked from StrafesNET/strafe-client
hashmap map ids into internal structure ids
This commit is contained in:
parent
f30f246e5f
commit
fb2e2afeb9
@ -329,6 +329,7 @@ pub struct PhysicsState{
|
|||||||
pub models:Vec<ModelPhysics>,
|
pub models:Vec<ModelPhysics>,
|
||||||
|
|
||||||
pub modes:Vec<crate::model::ModeDescription>,
|
pub modes:Vec<crate::model::ModeDescription>,
|
||||||
|
pub mode_from_mode_id:std::collections::HashMap::<u32,usize>,
|
||||||
//the spawn point is where you spawn when you load into the map.
|
//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
|
//This is not the same as Reset which teleports you to Spawn0
|
||||||
pub spawn_point:glam::Vec3,
|
pub spawn_point:glam::Vec3,
|
||||||
@ -557,6 +558,13 @@ impl PhysicsState {
|
|||||||
self.models.clear();
|
self.models.clear();
|
||||||
self.modes.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
|
//tickless gaming
|
||||||
pub fn run(&mut self, time_limit:TIME){
|
pub fn run(&mut self, time_limit:TIME){
|
||||||
//prepare is ommitted - everything is done via instructions.
|
//prepare is ommitted - everything is done via instructions.
|
||||||
|
13
src/main.rs
13
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|{
|
self.physics.modes.append(&mut modedatas.into_iter().map(|mut tup|{
|
||||||
tup.1.sort_by_key(|tup|tup.0);
|
tup.1.sort_by_key(|tup|tup.0);
|
||||||
tup.2.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{
|
model::ModeDescription{
|
||||||
start:tup.0,
|
start:tup.0,
|
||||||
spawns:tup.1.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().map(|tup|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,
|
unordered_checkpoints:tup.3,
|
||||||
|
spawn_from_stage_id:eshmep1,
|
||||||
|
ordered_checkpoint_from_checkpoint_id:eshmep2,
|
||||||
}
|
}
|
||||||
}).collect());
|
}).collect());
|
||||||
println!("Physics Objects: {}",self.physics.models.len());
|
println!("Physics Objects: {}",self.physics.models.len());
|
||||||
@ -590,6 +598,7 @@ impl framework::Example for GlobalState {
|
|||||||
world:body::WorldState{},
|
world:body::WorldState{},
|
||||||
game:body::GameMechanicsState::default(),
|
game:body::GameMechanicsState::default(),
|
||||||
modes:Vec::new(),
|
modes:Vec::new(),
|
||||||
|
mode_from_mode_id:std::collections::HashMap::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
//load textures
|
//load textures
|
||||||
|
18
src/model.rs
18
src/model.rs
@ -85,6 +85,24 @@ pub struct ModeDescription{
|
|||||||
pub spawns:Vec<u32>,//spawns[spawn_id]=model_id
|
pub spawns:Vec<u32>,//spawns[spawn_id]=model_id
|
||||||
pub ordered_checkpoints:Vec<u32>,//ordered_checkpoints[checkpoint_id]=model_id
|
pub ordered_checkpoints:Vec<u32>,//ordered_checkpoints[checkpoint_id]=model_id
|
||||||
pub unordered_checkpoints:Vec<u32>,//unordered_checkpoints[checkpoint_id]=model_id
|
pub unordered_checkpoints:Vec<u32>,//unordered_checkpoints[checkpoint_id]=model_id
|
||||||
|
pub spawn_from_stage_id:std::collections::HashMap::<u32,usize>,
|
||||||
|
pub ordered_checkpoint_from_checkpoint_id:std::collections::HashMap::<u32,usize>,
|
||||||
|
}
|
||||||
|
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{
|
pub enum TempIndexedAttributes{
|
||||||
Start{
|
Start{
|
||||||
|
Loading…
Reference in New Issue
Block a user