rename run to window

This commit is contained in:
Quaternions 2023-10-25 14:07:52 -07:00
parent f81a1c82bf
commit 6377885d6d
3 changed files with 33 additions and 33 deletions

View File

@ -1,8 +1,8 @@
mod bvh; mod bvh;
mod run;
mod aabb; mod aabb;
mod model; mod model;
mod setup; mod setup;
mod window;
mod worker; mod worker;
mod zeroes; mod zeroes;
mod integer; mod integer;
@ -120,5 +120,5 @@ pub fn default_models()->model::IndexedModelInstances{
fn main(){ fn main(){
let context=setup::setup(format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")).as_str()); let context=setup::setup(format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")).as_str());
context.start();//creates and runs a run context context.start();//creates and runs a window context
} }

View File

@ -1,5 +1,5 @@
use crate::instruction::TimedInstruction; use crate::instruction::TimedInstruction;
use crate::run::RunInstruction; use crate::window::WindowInstruction;
fn optional_features()->wgpu::Features{ fn optional_features()->wgpu::Features{
wgpu::Features::TEXTURE_COMPRESSION_ASTC wgpu::Features::TEXTURE_COMPRESSION_ASTC
@ -230,19 +230,19 @@ impl SetupContextSetup{
//dedicated thread to ping request redraw back and resize the window doesn't seem logical //dedicated thread to ping request redraw back and resize the window doesn't seem logical
let run=crate::run::RunContextSetup::new(&setup_context,window); let window=crate::window::WindowContextSetup::new(&setup_context,window);
//the thread that spawns the physics thread //the thread that spawns the physics thread
let run_thread=run.into_worker(setup_context); let window_thread=window.into_worker(setup_context);
println!("Entering event loop..."); println!("Entering event loop...");
let root_time=std::time::Instant::now(); let root_time=std::time::Instant::now();
run_event_loop(event_loop,run_thread,root_time).unwrap(); run_event_loop(event_loop,window_thread,root_time).unwrap();
} }
} }
fn run_event_loop( fn run_event_loop(
event_loop:winit::event_loop::EventLoop<()>, event_loop:winit::event_loop::EventLoop<()>,
mut run_thread:crate::compat_worker::QNWorker<TimedInstruction<RunInstruction>>, mut window_thread:crate::compat_worker::QNWorker<TimedInstruction<WindowInstruction>>,
root_time:std::time::Instant root_time:std::time::Instant
)->Result<(),winit::error::EventLoopError>{ )->Result<(),winit::error::EventLoopError>{
event_loop.run(move |event,elwt|{ event_loop.run(move |event,elwt|{
@ -254,7 +254,7 @@ fn run_event_loop(
// }; // };
match event{ match event{
winit::event::Event::AboutToWait=>{ winit::event::Event::AboutToWait=>{
run_thread.send(TimedInstruction{time,instruction:RunInstruction::RequestRedraw}).unwrap(); window_thread.send(TimedInstruction{time,instruction:WindowInstruction::RequestRedraw}).unwrap();
} }
winit::event::Event::WindowEvent { winit::event::Event::WindowEvent {
event: event:
@ -266,7 +266,7 @@ fn run_event_loop(
winit::event::WindowEvent::Resized(size),//ignoring scale factor changed for now because mutex bruh winit::event::WindowEvent::Resized(size),//ignoring scale factor changed for now because mutex bruh
window_id:_, window_id:_,
} => { } => {
run_thread.send(TimedInstruction{time,instruction:RunInstruction::Resize(size)}).unwrap(); window_thread.send(TimedInstruction{time,instruction:WindowInstruction::Resize(size)}).unwrap();
} }
winit::event::Event::WindowEvent{event,..}=>match event{ winit::event::Event::WindowEvent{event,..}=>match event{
winit::event::WindowEvent::KeyboardInput{ winit::event::WindowEvent::KeyboardInput{
@ -282,17 +282,17 @@ fn run_event_loop(
elwt.exit(); elwt.exit();
} }
winit::event::WindowEvent::RedrawRequested=>{ winit::event::WindowEvent::RedrawRequested=>{
run_thread.send(TimedInstruction{time,instruction:RunInstruction::Render}).unwrap(); window_thread.send(TimedInstruction{time,instruction:WindowInstruction::Render}).unwrap();
} }
_=>{ _=>{
run_thread.send(TimedInstruction{time,instruction:RunInstruction::WindowEvent(event)}).unwrap(); window_thread.send(TimedInstruction{time,instruction:WindowInstruction::WindowEvent(event)}).unwrap();
} }
}, },
winit::event::Event::DeviceEvent{ winit::event::Event::DeviceEvent{
event, event,
.. ..
} => { } => {
run_thread.send(TimedInstruction{time,instruction:RunInstruction::DeviceEvent(event)}).unwrap(); window_thread.send(TimedInstruction{time,instruction:WindowInstruction::DeviceEvent(event)}).unwrap();
}, },
_=>{} _=>{}
} }

View File

@ -1,7 +1,7 @@
use crate::instruction::TimedInstruction; use crate::instruction::TimedInstruction;
use crate::physics_worker::InputInstruction; use crate::physics_worker::InputInstruction;
pub enum RunInstruction{ pub enum WindowInstruction{
Resize(winit::dpi::PhysicalSize<u32>), Resize(winit::dpi::PhysicalSize<u32>),
WindowEvent(winit::event::WindowEvent), WindowEvent(winit::event::WindowEvent),
DeviceEvent(winit::event::DeviceEvent), DeviceEvent(winit::event::DeviceEvent),
@ -10,7 +10,7 @@ pub enum RunInstruction{
} }
//holds thread handles to dispatch to //holds thread handles to dispatch to
struct RunContext<'a>{ struct WindowContext<'a>{
manual_mouse_lock:bool, manual_mouse_lock:bool,
mouse:crate::physics::MouseState,//std::sync::Arc<std::sync::Mutex<>> mouse:crate::physics::MouseState,//std::sync::Arc<std::sync::Mutex<>>
screen_size:glam::UVec2, screen_size:glam::UVec2,
@ -19,7 +19,7 @@ struct RunContext<'a>{
physics_thread:crate::compat_worker::QNWorker<'a, TimedInstruction<crate::physics_worker::Instruction>>, physics_thread:crate::compat_worker::QNWorker<'a, TimedInstruction<crate::physics_worker::Instruction>>,
} }
impl RunContext<'_>{ impl WindowContext<'_>{
fn get_middle_of_screen(&self)->winit::dpi::PhysicalPosition<f32>{ fn get_middle_of_screen(&self)->winit::dpi::PhysicalPosition<f32>{
winit::dpi::PhysicalPosition::new(self.screen_size.x as f32/2.0, self.screen_size.y as f32/2.0) winit::dpi::PhysicalPosition::new(self.screen_size.x as f32/2.0, self.screen_size.y as f32/2.0)
} }
@ -161,14 +161,14 @@ impl RunContext<'_>{
} }
} }
pub struct RunContextSetup{ pub struct WindowContextSetup{
user_settings:crate::settings::UserSettings, user_settings:crate::settings::UserSettings,
window:winit::window::Window, window:winit::window::Window,
physics:crate::physics::PhysicsState, physics:crate::physics::PhysicsState,
graphics:crate::graphics::GraphicsState, graphics:crate::graphics::GraphicsState,
} }
impl RunContextSetup{ impl WindowContextSetup{
pub fn new(context:&crate::setup::SetupContext,window:winit::window::Window)->Self{ pub fn new(context:&crate::setup::SetupContext,window:winit::window::Window)->Self{
//wee //wee
let user_settings=crate::settings::read_user_settings(); let user_settings=crate::settings::read_user_settings();
@ -197,10 +197,10 @@ impl RunContextSetup{
} }
} }
fn into_context<'a>(self,setup_context:crate::setup::SetupContext)->RunContext<'a>{ fn into_context<'a>(self,setup_context:crate::setup::SetupContext)->WindowContext<'a>{
let screen_size=glam::uvec2(setup_context.config.width,setup_context.config.height); let screen_size=glam::uvec2(setup_context.config.width,setup_context.config.height);
let graphics_thread=crate::graphics_worker::new(self.graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue); let graphics_thread=crate::graphics_worker::new(self.graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue);
RunContext{ WindowContext{
manual_mouse_lock:false, manual_mouse_lock:false,
mouse:crate::physics::MouseState::default(), mouse:crate::physics::MouseState::default(),
//make sure to update this!!!!! //make sure to update this!!!!!
@ -211,29 +211,29 @@ impl RunContextSetup{
} }
} }
pub fn into_worker<'a>(self,setup_context:crate::setup::SetupContext)->crate::compat_worker::QNWorker<'a,TimedInstruction<RunInstruction>>{ pub fn into_worker<'a>(self,setup_context:crate::setup::SetupContext)->crate::compat_worker::QNWorker<'a,TimedInstruction<WindowInstruction>>{
let mut run_context=self.into_context(setup_context); let mut window_context=self.into_context(setup_context);
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<RunInstruction>|{ crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<WindowInstruction>|{
match ins.instruction{ match ins.instruction{
RunInstruction::RequestRedraw=>{ WindowInstruction::RequestRedraw=>{
run_context.window.request_redraw(); window_context.window.request_redraw();
} }
RunInstruction::WindowEvent(window_event)=>{ WindowInstruction::WindowEvent(window_event)=>{
run_context.window_event(ins.time,window_event); window_context.window_event(ins.time,window_event);
}, },
RunInstruction::DeviceEvent(device_event)=>{ WindowInstruction::DeviceEvent(device_event)=>{
run_context.device_event(ins.time,device_event); window_context.device_event(ins.time,device_event);
}, },
RunInstruction::Resize(size)=>{ WindowInstruction::Resize(size)=>{
run_context.physics_thread.send( window_context.physics_thread.send(
TimedInstruction{ TimedInstruction{
time:ins.time, time:ins.time,
instruction:crate::physics_worker::Instruction::Resize(size,run_context.user_settings.clone()) instruction:crate::physics_worker::Instruction::Resize(size,window_context.user_settings.clone())
} }
).unwrap(); ).unwrap();
} }
RunInstruction::Render=>{ WindowInstruction::Render=>{
run_context.physics_thread.send( window_context.physics_thread.send(
TimedInstruction{ TimedInstruction{
time:ins.time, time:ins.time,
instruction:crate::physics_worker::Instruction::Render instruction:crate::physics_worker::Instruction::Render