From 14f3b4fb0d90f5232fc3435b3d1c6a8e9584ceba Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 25 Oct 2023 15:29:18 -0700 Subject: [PATCH] runtime map loading! --- src/graphics_worker.rs | 9 ++++++++- src/physics.rs | 1 + src/physics_worker.rs | 13 +++++++++++++ src/window.rs | 13 +++++-------- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/graphics_worker.rs b/src/graphics_worker.rs index f26f86b..b7ff573 100644 --- a/src/graphics_worker.rs +++ b/src/graphics_worker.rs @@ -1,8 +1,9 @@ -#[derive(Clone)] pub enum Instruction{ Render(crate::physics::PhysicsOutputState,crate::integer::Time,glam::IVec2), //UpdateModel(crate::graphics::ModelUpdate), Resize(winit::dpi::PhysicalSize,crate::settings::UserSettings), + GenerateModels(crate::model::IndexedModelInstances), + ClearModels, } //Ideally the graphics thread worker description is: @@ -23,6 +24,12 @@ pub fn new<'a>( )->crate::compat_worker::INWorker<'a,Instruction>{ crate::compat_worker::INWorker::new(move |ins:Instruction|{ match ins{ + Instruction::GenerateModels(indexed_model_instances)=>{ + graphics.generate_models(&device,&queue,indexed_model_instances); + }, + Instruction::ClearModels=>{ + graphics.clear(); + }, Instruction::Resize(size,user_settings)=>{ println!("Resizing to {:?}",size); config.width=size.width.max(1); diff --git a/src/physics.rs b/src/physics.rs index 9aa219d..9080525 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -734,6 +734,7 @@ impl PhysicsState { self.models.clear(); self.modes.clear(); self.touching.clear(); + self.bvh=crate::bvh::BvhNode::default(); } pub fn output(&self)->PhysicsOutputState{ diff --git a/src/physics_worker.rs b/src/physics_worker.rs index f3b764f..093d807 100644 --- a/src/physics_worker.rs +++ b/src/physics_worker.rs @@ -18,6 +18,8 @@ pub enum Instruction{ Input(InputInstruction), Render, Resize(winit::dpi::PhysicalSize,crate::settings::UserSettings), + GenerateModels(crate::model::IndexedModelInstances), + ClearModels, //Graphics(crate::graphics_worker::Instruction), } @@ -61,6 +63,8 @@ pub enum Instruction{ &InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)), InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset), }, + Instruction::GenerateModels(_)=>Some(PhysicsInputInstruction::Idle), + Instruction::ClearModels=>Some(PhysicsInputInstruction::Idle), Instruction::Resize(_,_)=>Some(PhysicsInputInstruction::Idle), Instruction::Render=>Some(PhysicsInputInstruction::Idle), }{ @@ -114,6 +118,15 @@ pub enum Instruction{ Instruction::Resize(size,user_settings)=>{ graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap(); }, + Instruction::GenerateModels(indexed_model_instances)=>{ + physics.generate_models(&indexed_model_instances); + physics.spawn(indexed_model_instances.spawn_point); + graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(indexed_model_instances)).unwrap(); + }, + Instruction::ClearModels=>{ + physics.clear(); + graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap(); + }, _=>(), } }) diff --git a/src/window.rs b/src/window.rs index a5b34e2..e53dc18 100644 --- a/src/window.rs +++ b/src/window.rs @@ -26,14 +26,11 @@ impl WindowContext<'_>{ fn window_event(&mut self,time:crate::integer::Time,event: winit::event::WindowEvent) { match event { winit::event::WindowEvent::DroppedFile(path)=>{ - // let sender=self.sender.clone();//mpsc - // std::thread::spawn(move ||{ - // let indexed_model_instances=crate::load_file(path); - // sender.send(Instruction::Die(indexed_model_instances)); - // }); - let indexed_model_instances=crate::load_file(path); - //self.physics= - println!("unimplemented"); + //blocking because it's simpler... + if let Some(indexed_model_instances)=crate::load_file(path){ + 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(); + } }, winit::event::WindowEvent::Focused(state)=>{ //pause unpause