bizzare slow motion gameplay

This commit is contained in:
Quaternions 2023-10-24 23:37:07 -07:00
parent de7b7ba7be
commit 08f6d928cf
4 changed files with 28 additions and 24 deletions

View File

@ -16,14 +16,15 @@ WorkerDescription{
//up to three frames in flight, dropping new frame requests when all three are busy, and dropping output frames when one renders out of order
pub fn new<'a>(
scope:&'a std::thread::Scope<'a,'_>,
mut graphics:crate::graphics::GraphicsState,
mut config:wgpu::SurfaceConfiguration,
surface:wgpu::Surface,
device:wgpu::Device,
queue:wgpu::Queue,
)->crate::compat_worker::INWorker<'a,Instruction>{
)->crate::worker::INWorker<'a,Instruction>{
let mut resize=None;
crate::compat_worker::INWorker::new(move |ins:Instruction|{
crate::worker::INWorker::new(scope,move |ins:Instruction|{
match ins{
Instruction::GenerateModels(indexed_model_instances)=>{
graphics.generate_models(&device,&queue,indexed_model_instances);

View File

@ -23,11 +23,11 @@ pub enum Instruction{
//Graphics(crate::graphics_worker::Instruction),
}
pub fn new(mut physics:crate::physics::PhysicsState,mut graphics_worker:crate::compat_worker::INWorker<crate::graphics_worker::Instruction>)->crate::compat_worker::QNWorker<TimedInstruction<Instruction>>{
pub fn new<'a>(scope:&'a std::thread::Scope<'a,'_>,mut physics:crate::physics::PhysicsState,graphics_worker:crate::worker::INWorker<'a,crate::graphics_worker::Instruction>)->crate::worker::QNWorker<'a,TimedInstruction<Instruction>>{
let mut mouse_blocking=true;
let mut last_mouse_time=physics.next_mouse.time;
let mut timeline=std::collections::VecDeque::new();
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
crate::worker::QNWorker::new(scope,move |ins:TimedInstruction<Instruction>|{
if if let Some(phys_input)=match &ins.instruction{
Instruction::Input(input_instruction)=>match input_instruction{
&InputInstruction::MoveMouse(m)=>{
@ -113,10 +113,11 @@ pub enum Instruction{
}
match ins.instruction{
Instruction::Render=>{
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.next_mouse.pos)).unwrap();
let _=graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.next_mouse.pos));
},
Instruction::Resize(size,user_settings)=>{
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
//block!
graphics_worker.blocking_send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
},
Instruction::GenerateModels(indexed_model_instances)=>{
physics.generate_models(&indexed_model_instances);

View File

@ -232,20 +232,22 @@ impl SetupContextSetup{
let (window,event_loop,setup_context)=self.into_split();
//dedicated thread to ping request redraw back and resize the window doesn't seem logical
//but here I am doing it
let root_time=std::time::Instant::now();
std::thread::scope(|s|{
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 window_thread=window.into_worker(s,setup_context);
println!("Entering event loop...");
let root_time=std::time::Instant::now();
run_event_loop(event_loop,window_thread,root_time).unwrap();
});
}
}
fn run_event_loop(
event_loop:winit::event_loop::EventLoop<()>,
mut window_thread:crate::compat_worker::QNWorker<TimedInstruction<WindowInstruction>>,
window_thread:crate::worker::QNWorker<TimedInstruction<WindowInstruction>>,
root_time:std::time::Instant
)->Result<(),winit::error::EventLoopError>{
event_loop.run(move |event,elwt|{

View File

@ -16,7 +16,7 @@ struct WindowContext<'a>{
screen_size:glam::UVec2,
user_settings:crate::settings::UserSettings,
window:winit::window::Window,
physics_thread:crate::compat_worker::QNWorker<'a, TimedInstruction<crate::physics_worker::Instruction>>,
physics_thread:crate::worker::QNWorker<'a,TimedInstruction<crate::physics_worker::Instruction>>,
}
impl WindowContext<'_>{
@ -194,9 +194,9 @@ impl WindowContextSetup{
}
}
fn into_context<'a>(self,setup_context:crate::setup::SetupContext)->WindowContext<'a>{
fn into_context<'a>(self,scope:&'a std::thread::Scope<'a,'_>,setup_context:crate::setup::SetupContext)->WindowContext<'a>{
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(scope,self.graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue);
WindowContext{
manual_mouse_lock:false,
mouse:crate::physics::MouseState::default(),
@ -204,13 +204,13 @@ impl WindowContextSetup{
screen_size,
user_settings:self.user_settings,
window:self.window,
physics_thread:crate::physics_worker::new(self.physics,graphics_thread),
physics_thread:crate::physics_worker::new(scope,self.physics,graphics_thread),
}
}
pub fn into_worker<'a>(self,setup_context:crate::setup::SetupContext)->crate::compat_worker::QNWorker<'a,TimedInstruction<WindowInstruction>>{
let mut window_context=self.into_context(setup_context);
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<WindowInstruction>|{
pub fn into_worker<'a>(self,scope:&'a std::thread::Scope<'a,'_>,setup_context:crate::setup::SetupContext)->crate::worker::QNWorker<'a,TimedInstruction<WindowInstruction>>{
let mut window_context=self.into_context(scope,setup_context);
crate::worker::QNWorker::new(scope,move |ins:TimedInstruction<WindowInstruction>|{
match ins.instruction{
WindowInstruction::RequestRedraw=>{
window_context.window.request_redraw();