From fcc52a121532ee0323c171b7e26425f48a36734e Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 8 Feb 2024 19:27:59 -0800 Subject: [PATCH] fix all type errors --- src/model_physics.rs | 2 +- src/physics.rs | 27 +++++++++++++++++++-------- src/setup.rs | 4 ++-- src/window.rs | 28 ++++++++++++++-------------- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/model_physics.rs b/src/model_physics.rs index 4f51c15..dd0980a 100644 --- a/src/model_physics.rs +++ b/src/model_physics.rs @@ -122,7 +122,7 @@ impl From for PhysicsMeshId{ Self::new(value.get()) } } -#[derive(Debug,Clone,Copy,Hash,id::Id,Eq,PartialEq)] +#[derive(Debug,Default,Clone,Copy,Hash,id::Id,Eq,PartialEq)] pub struct PhysicsSubmeshId(u32); pub struct PhysicsMesh{ data:PhysicsMeshData, diff --git a/src/physics.rs b/src/physics.rs index cffc838..b204010 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -521,12 +521,12 @@ impl From for PhysicsAttributesId{ } } //unique physics meshes indexed by this -#[derive(Debug,Clone,Copy,Eq,Hash,PartialEq)] +#[derive(Debug,Default,Clone,Copy,Eq,Hash,PartialEq)] struct ConvexMeshId{ model_id:PhysicsModelId, submesh_id:PhysicsSubmeshId, } -#[derive(Debug,Clone,Copy,Hash,id::Id,Eq,PartialEq)] +#[derive(Debug,Default,Clone,Copy,Hash,id::Id,Eq,PartialEq)] struct PhysicsModelId(u32); impl Into for PhysicsModelId{ fn into(self)->ModelId{ @@ -869,6 +869,16 @@ impl Default for PhysicsState{ } } } +impl Default for PhysicsData{ + fn default()->Self{ + Self{ + bvh:bvh::BvhNode::default(), + models:Default::default(), + modes:Default::default(), + hitbox_mesh:StyleModifiers::default().calculate_mesh(), + } + } +} impl PhysicsState { pub fn clear(&mut self){ @@ -952,6 +962,7 @@ impl PhysicsState { } } } +#[derive(Default)] pub struct PhysicsContext{ pub state:PhysicsState,//this captures the entire state of the physics. data:PhysicsData,//data currently loaded into memory which is needded for physics to run, but is not part of the state. @@ -1375,7 +1386,7 @@ fn run_teleport_behaviour(wormhole:&Option,mode_s } }, PhysicsInstruction::Input(input_instruction) => { - let mut refresh_walk_target=true; + let mut b_refresh_walk_target=true; match input_instruction{ PhysicsInputInstruction::SetNextMouse(m) => { state.camera.move_mouse(state.next_mouse.pos); @@ -1400,11 +1411,11 @@ fn run_teleport_behaviour(wormhole:&Option,mode_s (state.move_state,state.body.acceleration)=state.touching.get_move_state(&state.body,&data.models,&state.style,&data.hitbox_mesh,&state.camera,state.controls,&state.next_mouse,state.time); } } - refresh_walk_target=false; + b_refresh_walk_target=false; }, PhysicsInputInstruction::SetZoom(s) => { state.set_control(StyleModifiers::CONTROL_ZOOM,s); - refresh_walk_target=false; + b_refresh_walk_target=false; }, PhysicsInputInstruction::Reset => { //it matters which of these runs first, but I have not thought it through yet as it doesn't matter yet @@ -1418,11 +1429,11 @@ fn run_teleport_behaviour(wormhole:&Option,mode_s set_position(&mut state.body,&mut state.touching,spawn_point); set_velocity(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,Planar64Vec3::ZERO); (state.move_state,state.body.acceleration)=state.touching.get_move_state(&state.body,&data.models,&state.style,&data.hitbox_mesh,&state.camera,state.controls,&state.next_mouse,state.time); - refresh_walk_target=false; + b_refresh_walk_target=false; }, - PhysicsInputInstruction::Idle => {refresh_walk_target=false;},//literally idle! + PhysicsInputInstruction::Idle => {b_refresh_walk_target=false;},//literally idle! } - if refresh_walk_target{ + if b_refresh_walk_target{ let a=refresh_walk_target(state,data); if set_acceleration_cull(&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,a){ (state.move_state,state.body.acceleration)=state.touching.get_move_state(&state.body,&data.models,&state.style,&data.hitbox_mesh,&state.camera,state.controls,&state.next_mouse,state.time); diff --git a/src/setup.rs b/src/setup.rs index 8167c12..1902203 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -214,13 +214,13 @@ pub fn setup_and_start(title:String){ let window=crate::window::WindowContextSetup::new(&setup_context,&window); //the thread that spawns the physics thread - let window_thread=window.into_worker(setup_context); + let mut window_thread=window.into_worker(setup_context); let args:Vec=std::env::args().collect(); let indexed_model_instances=if args.len()==2{ let path=std::path::PathBuf::from(&args[1]); window_thread.send(TimedInstruction{ - time:0, + time:integer::Time::ZERO, instruction:WindowInstruction::WindowEvent(winit::event::WindowEvent::DroppedFile(path)), }); }; diff --git a/src/window.rs b/src/window.rs index bbd0aca..c59e1ca 100644 --- a/src/window.rs +++ b/src/window.rs @@ -29,17 +29,17 @@ impl WindowContext<'_>{ winit::event::WindowEvent::DroppedFile(path)=>{ //blocking because it's simpler... if let Ok(file)=std::fs::File::open(path){ - match strafesnet_snf::read_snf(std::io::BufReader::new(file)){ - Ok(strafesnet_snf::SNF::Map(streamable_map))=>{ - if let Ok(indexed_model_instances)=streamable_map.load_all(){ - self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::ClearModels}).unwrap(); - self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::GenerateModels(indexed_model_instances)}).unwrap(); - } - }, - Ok(strafesnet_snf::SNF::Bot(streamable_map))=>println!("File type not yet supported"), - Ok(strafesnet_snf::SNF::Demo(streamable_map))=>println!("File type not yet supported"), - Err(e)=>println!("Error reading file: {e:?}"), - } + // match strafesnet_snf::read_snf(std::io::BufReader::new(file)){ + // Ok(strafesnet_snf::SNF::Map(streamable_map))=>{ + // if let Ok(indexed_model_instances)=streamable_map.load_all(){ + // self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::ClearModels}).unwrap(); + // self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::GenerateModels(indexed_model_instances)}).unwrap(); + // } + // }, + // Ok(strafesnet_snf::SNF::Bot(streamable_map))=>println!("File type not yet supported"), + // Ok(strafesnet_snf::SNF::Demo(streamable_map))=>println!("File type not yet supported"), + // Err(e)=>println!("Error reading file: {e:?}"), + // } }else{ println!("Failed to open file {path:?}"); } @@ -173,7 +173,7 @@ impl WindowContext<'_>{ pub struct WindowContextSetup<'a>{ user_settings:crate::settings::UserSettings, window:&'a winit::window::Window, - physics:crate::physics::PhysicsState, + physics:crate::physics::PhysicsContext, graphics:crate::graphics::GraphicsState, } @@ -181,8 +181,8 @@ impl<'a> WindowContextSetup<'a>{ pub fn new(context:&crate::setup::SetupContext,window:&'a winit::window::Window)->Self{ let user_settings=crate::settings::read_user_settings(); - let mut physics=crate::physics::PhysicsState::default(); - physics.load_user_settings(&user_settings); + let mut physics=crate::physics::PhysicsContext::default(); + physics.state.load_user_settings(&user_settings); let mut graphics=crate::graphics::GraphicsState::new(&context.device,&context.queue,&context.config); graphics.load_user_settings(&user_settings);