From 28cad39b1021b8c24ce1c1a580397d902f189061 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 21 Sep 2023 14:05:08 -0700 Subject: [PATCH] TEMP: teleport to spawn point --- src/body.rs | 14 +++++++++++++- src/load_roblox.rs | 39 ++++++++++++++++++++++----------------- src/main.rs | 6 ++++++ 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/body.rs b/src/body.rs index 64436d9..27ff28c 100644 --- a/src/body.rs +++ b/src/body.rs @@ -16,6 +16,8 @@ pub enum PhysicsInstruction { // bool,//true = Trigger; false = teleport // bool,//true = Force // ) + //temp + SetPosition(glam::Vec3), } pub struct Body { @@ -756,6 +758,7 @@ impl crate::instruction::InstructionConsumer for PhysicsStat //selectively update body match &ins.instruction { PhysicsInstruction::SetWalkTargetVelocity(_) + |PhysicsInstruction::SetPosition(_) |PhysicsInstruction::SetControlDir(_) => self.time=ins.time,//TODO: queue instructions PhysicsInstruction::RefreshWalkTarget |PhysicsInstruction::ReachWalkTargetVelocity @@ -765,6 +768,15 @@ impl crate::instruction::InstructionConsumer for PhysicsStat |PhysicsInstruction::Jump => self.advance_time(ins.time), } match ins.instruction { + PhysicsInstruction::SetPosition(position)=>{ + //temp + self.body.position=position; + //manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))} + self.contacts.clear(); + self.body.acceleration=self.gravity; + self.walk.state=WalkEnum::Reached; + self.grounded=false; + } PhysicsInstruction::CollisionStart(c) => { //check ground match &c.face { @@ -854,4 +866,4 @@ impl crate::instruction::InstructionConsumer for PhysicsStat }, } } -} \ No newline at end of file +} diff --git a/src/load_roblox.rs b/src/load_roblox.rs index f8cb69f..149c8f8 100644 --- a/src/load_roblox.rs +++ b/src/load_roblox.rs @@ -53,6 +53,7 @@ impl std::str::FromStr for RobloxAssetId { } pub fn generate_modeldatas_roblox(dom:&rbx_dom_weak::WeakDom) -> Result<(Vec,Vec), Box>{ //ModelData includes texture dds + let mut spawn_point=glam::Vec3::ZERO; //TODO: generate unit Block, Wedge, etc. after based on part shape lists let mut modeldatas=crate::model::generate_modeldatas(primitives::the_unit_cube_lol(),ModelData::COLOR_FLOATS_WHITE); @@ -80,6 +81,26 @@ pub fn generate_modeldatas_roblox(dom:&rbx_dom_weak::WeakDom) -> Result<(Vec Result<(Vecmodeldatas[(texture_id+1) as usize].instances.push(model_instance), @@ -134,5 +139,5 @@ pub fn generate_modeldatas_roblox(dom:&rbx_dom_weak::WeakDom) -> Result<(Vec,_>=asset_id_from_texture_id.iter().map(|asset_id|{ std::fs::File::open(std::path::Path::new(&format!("textures/{}.dds",asset_id))) }).collect(); - Ok((modeldatas,texture_files?)) + Ok((modeldatas,texture_files?,spawn_point)) } diff --git a/src/main.rs b/src/main.rs index 27a72e9..3412cad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -760,6 +760,12 @@ impl framework::Example for GraphicsData { //self.physics.models.clear(); //self.generate_model_physics(&modeldatas); //self.generate_model_graphics(device,queue,modeldatas,textures); + //manual reset + //let time=self.physics.time; + //instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{ + // time, + // instruction: body::PhysicsInstruction::SetPosition(spawn_point), + //}) }else{ println!("Could not open file"); }