From 6e5de4aa467ce368a305237ea52004e4d54ad70e Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 18 Oct 2023 15:59:38 -0700 Subject: [PATCH] overhaul TempIndexedAttributes + add Wormhole indexing --- src/load_roblox.rs | 13 +++++----- src/model.rs | 42 ++++++++++++++++++++++----------- src/physics.rs | 59 ++++++++++++++++++++++------------------------ 3 files changed, 63 insertions(+), 51 deletions(-) diff --git a/src/load_roblox.rs b/src/load_roblox.rs index 751e42dc..bc737f1b 100644 --- a/src/load_roblox.rs +++ b/src/load_roblox.rs @@ -263,16 +263,17 @@ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::Index if let Some(attr)=match &object.name[..]{ "MapStart"=>{ 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=>{ - 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) { match &captures[1]{ - "BonusStart"=>Some(crate::model::TempIndexedAttributes::Start{mode_id:captures[2].parse::().unwrap()}), - "Spawn"|"ForceSpawn"=>Some(crate::model::TempIndexedAttributes::Spawn{mode_id:0,stage_id:captures[2].parse::().unwrap()}), - "OrderedCheckpoint"=>Some(crate::model::TempIndexedAttributes::OrderedCheckpoint{mode_id:0,checkpoint_id:captures[2].parse::().unwrap()}), + "BonusStart"=>Some(crate::model::TempIndexedAttributes::Start(crate::model::TempAttrStart{mode_id:captures[2].parse::().unwrap()})), + "Spawn"|"ForceSpawn"=>Some(crate::model::TempIndexedAttributes::Spawn(crate::model::TempAttrSpawn{mode_id:0,stage_id:captures[2].parse::().unwrap()})), + "OrderedCheckpoint"=>Some(crate::model::TempIndexedAttributes::OrderedCheckpoint(crate::model::TempAttrOrderedCheckpoint{mode_id:0,checkpoint_id:captures[2].parse::().unwrap()})), + "WormholeOut"=>Some(crate::model::TempIndexedAttributes::Wormhole(crate::model::TempAttrWormhole{wormhole_id:captures[2].parse::().unwrap()})), _=>None, } }else{ diff --git a/src/model.rs b/src/model.rs index f04db02f..a7bd22a3 100644 --- a/src/model.rs +++ b/src/model.rs @@ -65,21 +65,35 @@ impl ModeDescription{ 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{ - Start{ - mode_id:u32, - }, - Spawn{ - mode_id:u32, - stage_id:u32, - }, - OrderedCheckpoint{ - mode_id:u32, - checkpoint_id:u32, - }, - UnorderedCheckpoint{ - mode_id:u32, - }, + Start(TempAttrStart), + Spawn(TempAttrSpawn), + OrderedCheckpoint(TempAttrOrderedCheckpoint), + UnorderedCheckpoint(TempAttrUnorderedCheckpoint), + Wormhole(TempAttrWormhole), } //you have this effect while in contact diff --git a/src/physics.rs b/src/physics.rs index 66cfd2cf..3937d2fd 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -865,13 +865,14 @@ impl PhysicsState { //make aabb and run vertices to get realistic bounds for model_instance in &model.instances{ 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{ match attr{ - crate::model::TempIndexedAttributes::Start{mode_id}=>starts.push((*mode_id,model_id)), - crate::model::TempIndexedAttributes::Spawn{mode_id,stage_id}=>spawns.push((*mode_id,model_id,*stage_id)), - crate::model::TempIndexedAttributes::OrderedCheckpoint{mode_id,checkpoint_id}=>ordered_checkpoints.push((*mode_id,model_id,*checkpoint_id)), - crate::model::TempIndexedAttributes::UnorderedCheckpoint{mode_id}=>unordered_checkpoints.push((*mode_id,model_id)), + crate::model::TempIndexedAttributes::Start(s)=>starts.push((model_id,s.clone())), + crate::model::TempIndexedAttributes::Spawn(s)=>spawns.push((model_id,s.clone())), + crate::model::TempIndexedAttributes::OrderedCheckpoint(s)=>ordered_checkpoints.push((model_id,s.clone())), + 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()); //I don't wanna write structs for temporary structures //this code builds ModeDescriptions from the unsorted lists at the top of the function - starts.sort_by_key(|tup|tup.0); - let mut eshmep=std::collections::HashMap::new(); - let mut modedatas:Vec<(u32,Vec<(u32,u32)>,Vec<(u32,u32)>,Vec)>=starts.into_iter().enumerate().map(|(i,tup)|{ - eshmep.insert(tup.0,i); - (tup.1,Vec::new(),Vec::new(),Vec::new()) + starts.sort_by_key(|tup|tup.1.mode_id); + let mut mode_id_from_map_mode_id=std::collections::HashMap::new(); + let mut modedatas:Vec<(usize,Vec<(u32,usize)>,Vec<(u32,usize)>,Vec,u32)>=starts.into_iter().enumerate().map(|(i,(model_id,s))|{ + mode_id_from_map_mode_id.insert(s.mode_id,i); + (model_id,Vec::new(),Vec::new(),Vec::new(),s.mode_id) }).collect(); - for tup in spawns{ - if let Some(mode_id)=eshmep.get(&tup.0){ + for (model_id,s) in spawns{ + if let Some(mode_id)=mode_id_from_map_mode_id.get(&s.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{ - if let Some(mode_id)=eshmep.get(&tup.0){ + for (model_id,s) in ordered_checkpoints{ + if let Some(mode_id)=mode_id_from_map_mode_id.get(&s.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{ - if let Some(mode_id)=eshmep.get(&tup.0){ + for (model_id,s) in unordered_checkpoints{ + if let Some(mode_id)=mode_id_from_map_mode_id.get(&s.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 (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|{ + for mut tup in modedatas.into_iter(){ 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(); - crate::model::ModeDescription{ - start:tup.0 as usize, - spawns:tup.1.into_iter().enumerate().map(|(i,tup)|{eshmep1.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 as usize}).collect(), - unordered_checkpoints:tup.3.into_iter().map(|v|v as usize).collect(), + self.modes.insert(tup.4,crate::model::ModeDescription{ + start:tup.0, + 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.models.models.len()); }