From 4655f43f5f7340835edc3f43c47477054276788b Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 23 Oct 2023 20:22:06 -0700 Subject: [PATCH] work --- src/graphics_context.rs | 9 ++++++++- src/physics_context.rs | 18 ++++++------------ src/run.rs | 7 ++++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/graphics_context.rs b/src/graphics_context.rs index 9755715..5951be5 100644 --- a/src/graphics_context.rs +++ b/src/graphics_context.rs @@ -3,4 +3,11 @@ struct Context{ queue:wgpu::Queue, } -//?? \ No newline at end of file +impl Context{ + pub fn new(user_settings:&crate::settings::UserSettings,indexed_model_instances:&crate::model::IndexedModelInstances){ + let mut graphics=crate::graphics::GraphicsState::new(); + graphics.load_user_settings(user_settings); + graphics.generate_models(indexed_model_instances); + } + //into_worker +} \ No newline at end of file diff --git a/src/physics_context.rs b/src/physics_context.rs index 68e25a9..0fe379b 100644 --- a/src/physics_context.rs +++ b/src/physics_context.rs @@ -20,24 +20,18 @@ pub enum InputInstruction { //to be 1 instruction ahead to generate the next state for interpolation. } -pub struct RenderState{ - physics:crate::physics::PhysicsState, - graphics:crate::graphics::GraphicsState, +pub struct Context{ } -impl RenderState{ - pub fn new(user_settings:&crate::settings::UserSettings,indexed_model_instances:crate::model::IndexedModelInstances){ - +impl Context{ + pub fn new(user_settings:&crate::settings::UserSettings,indexed_model_instances:&crate::model::IndexedModelInstances){ let mut physics=crate::physics::PhysicsState::default(); physics.spawn(indexed_model_instances.spawn_point); physics.load_user_settings(user_settings); physics.generate_models(&indexed_model_instances); - - let mut graphics=Self::new_graphics_state(); - graphics.load_user_settings(user_settings); - graphics.generate_models(indexed_model_instances); - //manual reset } pub fn into_worker(mut self)->crate::worker::QNWorker>{ + let graphics_context=crate::graphics_context::Context::new(); + let graphics_thread=graphics_context.into_worker(); let mut mouse_blocking=true; let mut last_mouse_time=self.physics.next_mouse.time; let mut timeline=std::collections::VecDeque::new(); @@ -122,7 +116,7 @@ impl RenderState{ } } if render{ - self.graphics.render(); + graphics_thread.send(TimedInstruction{time:ins.time,instruction:crate::graphics_context::GraphicsInstruction::Render}); } }) } diff --git a/src/run.rs b/src/run.rs index c342b90..18150e2 100644 --- a/src/run.rs +++ b/src/run.rs @@ -194,7 +194,8 @@ impl RunState { pub fn into_worker(self,mut setup_context:crate::setup_context::SetupContext)->crate::worker::QNWorker>{ //create child context - let physics_context=PhysicsContext::new(()); + let physics_context=crate::physics_context::Context::new(indexed_models,&setup_context);//this needs all the context for graphics_context too + let physics_thread=physics_context.into_worker(); // crate::worker::QNWorker::new(move |ins:TimedInstruction|{ match ins.instruction{ @@ -207,8 +208,8 @@ impl RunState { RunInstruction::Resize(size)=>{ setup_context.config.width=size.width.max(1); setup_context.config.height=size.height.max(1); - self.graphics.resize(&setup_context.device,&setup_context.config); setup_context.surface.configure(&setup_context.device,&setup_context.config); + physics_thread.send(TimedInstruction{time:ins.time,instruction:PhysicsInstruction::Resize(size)}); } RunInstruction::Render=>{ let frame=match setup_context.surface.get_current_texture(){ @@ -225,7 +226,7 @@ impl RunState { ..wgpu::TextureViewDescriptor::default() }); - self.graphics.render(&view,&setup_context.device,&setup_context.queue); + physics_thread.send(TimedInstruction{time:ins.time,instruction:PhysicsInstruction::Render(view)}); frame.present(); }