overhaul TempIndexedAttributes + add Wormhole indexing

This commit is contained in:
Quaternions 2023-10-18 15:59:38 -07:00
parent cc776e7cb4
commit 6e5de4aa46
3 changed files with 63 additions and 51 deletions

View File

@ -263,16 +263,17 @@ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::Index
if let Some(attr)=match &object.name[..]{ if let Some(attr)=match &object.name[..]{
"MapStart"=>{ "MapStart"=>{
spawn_point=model_transform.transform_point3(Planar64Vec3::ZERO)+Planar64Vec3::Y*5/2; spawn_point=model_transform.transform_point3(Planar64Vec3::ZERO)+Planar64Vec3::Y*5/2;
Some(crate::model::TempIndexedAttributes::Start{mode_id:0}) Some(crate::model::TempIndexedAttributes::Start(crate::model::TempAttrStart{mode_id:0}))
}, },
"UnorderedCheckpoint"=>Some(crate::model::TempIndexedAttributes::UnorderedCheckpoint{mode_id:0}), "UnorderedCheckpoint"=>Some(crate::model::TempIndexedAttributes::UnorderedCheckpoint(crate::model::TempAttrUnorderedCheckpoint{mode_id:0})),
other=>{ other=>{
let regman=lazy_regex::regex!(r"^(BonusStart|Spawn|ForceSpawn|OrderedCheckpoint)(\d+)$"); let regman=lazy_regex::regex!(r"^(BonusStart|Spawn|ForceSpawn|OrderedCheckpoint|WormholeOut)(\d+)$");
if let Some(captures) = regman.captures(other) { if let Some(captures) = regman.captures(other) {
match &captures[1]{ match &captures[1]{
"BonusStart"=>Some(crate::model::TempIndexedAttributes::Start{mode_id:captures[2].parse::<u32>().unwrap()}), "BonusStart"=>Some(crate::model::TempIndexedAttributes::Start(crate::model::TempAttrStart{mode_id:captures[2].parse::<u32>().unwrap()})),
"Spawn"|"ForceSpawn"=>Some(crate::model::TempIndexedAttributes::Spawn{mode_id:0,stage_id:captures[2].parse::<u32>().unwrap()}), "Spawn"|"ForceSpawn"=>Some(crate::model::TempIndexedAttributes::Spawn(crate::model::TempAttrSpawn{mode_id:0,stage_id:captures[2].parse::<u32>().unwrap()})),
"OrderedCheckpoint"=>Some(crate::model::TempIndexedAttributes::OrderedCheckpoint{mode_id:0,checkpoint_id:captures[2].parse::<u32>().unwrap()}), "OrderedCheckpoint"=>Some(crate::model::TempIndexedAttributes::OrderedCheckpoint(crate::model::TempAttrOrderedCheckpoint{mode_id:0,checkpoint_id:captures[2].parse::<u32>().unwrap()})),
"WormholeOut"=>Some(crate::model::TempIndexedAttributes::Wormhole(crate::model::TempAttrWormhole{wormhole_id:captures[2].parse::<u32>().unwrap()})),
_=>None, _=>None,
} }
}else{ }else{

View File

@ -65,21 +65,35 @@ impl ModeDescription{
self.ordered_checkpoints.get(*self.ordered_checkpoint_from_checkpoint_id.get(&checkpoint_id)?) self.ordered_checkpoints.get(*self.ordered_checkpoint_from_checkpoint_id.get(&checkpoint_id)?)
} }
} }
//I don't want this code to exist!
#[derive(Clone)]
pub struct TempAttrStart{
pub mode_id:u32,
}
#[derive(Clone)]
pub struct TempAttrSpawn{
pub mode_id:u32,
pub stage_id:u32,
}
#[derive(Clone)]
pub struct TempAttrOrderedCheckpoint{
pub mode_id:u32,
pub checkpoint_id:u32,
}
#[derive(Clone)]
pub struct TempAttrUnorderedCheckpoint{
pub mode_id:u32,
}
#[derive(Clone)]
pub struct TempAttrWormhole{
pub wormhole_id:u32,
}
pub enum TempIndexedAttributes{ pub enum TempIndexedAttributes{
Start{ Start(TempAttrStart),
mode_id:u32, Spawn(TempAttrSpawn),
}, OrderedCheckpoint(TempAttrOrderedCheckpoint),
Spawn{ UnorderedCheckpoint(TempAttrUnorderedCheckpoint),
mode_id:u32, Wormhole(TempAttrWormhole),
stage_id:u32,
},
OrderedCheckpoint{
mode_id:u32,
checkpoint_id:u32,
},
UnorderedCheckpoint{
mode_id:u32,
},
} }
//you have this effect while in contact //you have this effect while in contact

View File

@ -865,13 +865,14 @@ impl PhysicsState {
//make aabb and run vertices to get realistic bounds //make aabb and run vertices to get realistic bounds
for model_instance in &model.instances{ for model_instance in &model.instances{
if let Some(model_physics)=ModelPhysics::from_model(model,model_instance){ if let Some(model_physics)=ModelPhysics::from_model(model,model_instance){
let model_id=self.models.push(model_physics) as u32; let model_id=self.models.push(model_physics);
for attr in &model_instance.temp_indexing{ for attr in &model_instance.temp_indexing{
match attr{ match attr{
crate::model::TempIndexedAttributes::Start{mode_id}=>starts.push((*mode_id,model_id)), crate::model::TempIndexedAttributes::Start(s)=>starts.push((model_id,s.clone())),
crate::model::TempIndexedAttributes::Spawn{mode_id,stage_id}=>spawns.push((*mode_id,model_id,*stage_id)), crate::model::TempIndexedAttributes::Spawn(s)=>spawns.push((model_id,s.clone())),
crate::model::TempIndexedAttributes::OrderedCheckpoint{mode_id,checkpoint_id}=>ordered_checkpoints.push((*mode_id,model_id,*checkpoint_id)), crate::model::TempIndexedAttributes::OrderedCheckpoint(s)=>ordered_checkpoints.push((model_id,s.clone())),
crate::model::TempIndexedAttributes::UnorderedCheckpoint{mode_id}=>unordered_checkpoints.push((*mode_id,model_id)), crate::model::TempIndexedAttributes::UnorderedCheckpoint(s)=>unordered_checkpoints.push((model_id,s.clone())),
crate::model::TempIndexedAttributes::Wormhole(s)=>{self.models.model_id_from_wormhole_id.insert(s.wormhole_id,model_id);},
} }
} }
} }
@ -880,51 +881,47 @@ impl PhysicsState {
self.bvh=crate::bvh::generate_bvh(self.models.models.iter().map(|m|m.mesh().clone()).collect()); self.bvh=crate::bvh::generate_bvh(self.models.models.iter().map(|m|m.mesh().clone()).collect());
//I don't wanna write structs for temporary structures //I don't wanna write structs for temporary structures
//this code builds ModeDescriptions from the unsorted lists at the top of the function //this code builds ModeDescriptions from the unsorted lists at the top of the function
starts.sort_by_key(|tup|tup.0); starts.sort_by_key(|tup|tup.1.mode_id);
let mut eshmep=std::collections::HashMap::new(); let mut mode_id_from_map_mode_id=std::collections::HashMap::new();
let mut modedatas:Vec<(u32,Vec<(u32,u32)>,Vec<(u32,u32)>,Vec<u32>)>=starts.into_iter().enumerate().map(|(i,tup)|{ let mut modedatas:Vec<(usize,Vec<(u32,usize)>,Vec<(u32,usize)>,Vec<usize>,u32)>=starts.into_iter().enumerate().map(|(i,(model_id,s))|{
eshmep.insert(tup.0,i); mode_id_from_map_mode_id.insert(s.mode_id,i);
(tup.1,Vec::new(),Vec::new(),Vec::new()) (model_id,Vec::new(),Vec::new(),Vec::new(),s.mode_id)
}).collect(); }).collect();
for tup in spawns{ for (model_id,s) in spawns{
if let Some(mode_id)=eshmep.get(&tup.0){ if let Some(mode_id)=mode_id_from_map_mode_id.get(&s.mode_id){
if let Some(modedata)=modedatas.get_mut(*mode_id){ if let Some(modedata)=modedatas.get_mut(*mode_id){
modedata.1.push((tup.2,tup.1)); modedata.1.push((s.stage_id,model_id));
} }
} }
} }
for tup in ordered_checkpoints{ for (model_id,s) in ordered_checkpoints{
if let Some(mode_id)=eshmep.get(&tup.0){ if let Some(mode_id)=mode_id_from_map_mode_id.get(&s.mode_id){
if let Some(modedata)=modedatas.get_mut(*mode_id){ if let Some(modedata)=modedatas.get_mut(*mode_id){
modedata.2.push((tup.2,tup.1)); modedata.2.push((s.checkpoint_id,model_id));
} }
} }
} }
for tup in unordered_checkpoints{ for (model_id,s) in unordered_checkpoints{
if let Some(mode_id)=eshmep.get(&tup.0){ if let Some(mode_id)=mode_id_from_map_mode_id.get(&s.mode_id){
if let Some(modedata)=modedatas.get_mut(*mode_id){ if let Some(modedata)=modedatas.get_mut(*mode_id){
modedata.3.push(tup.1); modedata.3.push(model_id);
} }
} }
} }
let num_modes=self.modes.modes.len(); for mut tup in modedatas.into_iter(){
for (mode_id,mode) in eshmep{
self.modes.mode_from_mode_id.insert(mode_id,num_modes+mode);
}
self.modes.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 eshmep1=std::collections::HashMap::new();
let mut eshmep2=std::collections::HashMap::new(); let mut eshmep2=std::collections::HashMap::new();
crate::model::ModeDescription{ self.modes.insert(tup.4,crate::model::ModeDescription{
start:tup.0 as usize, start:tup.0,
spawns:tup.1.into_iter().enumerate().map(|(i,tup)|{eshmep1.insert(tup.0,i);tup.1 as usize}).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 as usize}).collect(), ordered_checkpoints:tup.2.into_iter().enumerate().map(|(i,tup)|{eshmep2.insert(tup.0,i);tup.1}).collect(),
unordered_checkpoints:tup.3.into_iter().map(|v|v as usize).collect(), unordered_checkpoints:tup.3,
spawn_from_stage_id:eshmep1, spawn_from_stage_id:eshmep1,
ordered_checkpoint_from_checkpoint_id:eshmep2, ordered_checkpoint_from_checkpoint_id:eshmep2,
} });
}).collect()); }
println!("Physics Objects: {}",self.models.models.len()); println!("Physics Objects: {}",self.models.models.len());
} }