update graphics

This commit is contained in:
2026-03-10 07:52:51 -07:00
parent c8eb2f7878
commit f82d860822
9 changed files with 74 additions and 81 deletions

View File

@@ -2,6 +2,7 @@ use strafesnet_common::instruction::TimedInstruction;
use strafesnet_common::session::Time as SessionTime;
use strafesnet_common::timer::TimerState;
use strafesnet_roblox_bot_player::{bot::CompleteBot,graphics::Graphics,head::{PlaybackHead,Time as PlaybackTime}};
use strafesnet_graphics::surface::Surface;
pub enum SessionControlInstruction{
SetPaused(bool),
@@ -35,22 +36,22 @@ struct Playback{
}
pub struct PlayerWorker<'a>{
surface:wgpu::Surface<'a>,
graphics_thread:Graphics,
surface:Surface<'a>,
playback:Option<Playback>,
}
impl<'a> PlayerWorker<'a>{
pub fn new(
surface:wgpu::Surface<'a>,
graphics_thread:Graphics,
surface:Surface<'a>,
)->Self{
Self{
surface,
graphics_thread,
surface,
playback:None,
}
}
pub fn send(&mut self,ins:TimedInstruction<Instruction,SessionTime>){
pub fn send(&mut self,device:&wgpu::Device,queue:&wgpu::Queue,ins:TimedInstruction<Instruction,SessionTime>){
match ins.instruction{
Instruction::SessionControl(SessionControlInstruction::SetPaused(paused))=>if let Some(playback)=&mut self.playback{
playback.playback_head.set_paused(ins.time,paused);
@@ -77,15 +78,28 @@ impl<'a> PlayerWorker<'a>{
Instruction::Render=>if let Some(playback)=&mut self.playback{
playback.playback_head.advance_time(&playback.bot,ins.time);
let (pos,angles)=playback.playback_head.get_position_angles(&playback.bot,ins.time);
self.graphics_thread.render(&self.surface,pos,angles);
//this has to go deeper somehow
let frame=self.surface.new_frame(device);
let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None});
self.graphics_thread.encode_commands(&mut encoder,frame.view(),pos,angles);
queue.submit([encoder.finish()]);
frame.present();
},
Instruction::Resize(physical_size)=>if let Some(playback)=&self.playback{
let fov_y=playback.playback_head.state().get_fov_y();
let fov_x=fov_y*physical_size.width as f64/physical_size.height as f64;
self.graphics_thread.resize(&self.surface,glam::uvec2(physical_size.width,physical_size.height),glam::vec2(fov_x as f32,fov_y as f32));
let fov=glam::vec2(fov_x as f32,fov_y as f32);
let size=glam::uvec2(physical_size.width,physical_size.height);
self.surface.configure(device,size);
self.graphics_thread.resize(device,size,fov);
},
Instruction::ChangeMap(complete_map)=>{
self.graphics_thread.change_map(&complete_map);
self.graphics_thread.change_map(device,queue,&complete_map);
},
Instruction::LoadReplay(bot)=>{
let bot=CompleteBot::new(bot);

View File

@@ -22,7 +22,7 @@ pub async fn setup_and_start(title:&str){
let (device,queue)=setup::step4::request_device(&adapter).await.unwrap();
let size=window.inner_size();
let config=setup::step5::configure_surface(&adapter,&device,&surface,(size.width,size.height)).unwrap();
let surface=setup::step5::configure_surface(&adapter,&device,surface,(size.width,size.height)).unwrap();
//dedicated thread to ping request redraw back and resize the window doesn't seem logical
@@ -32,7 +32,6 @@ pub async fn setup_and_start(title:&str){
device,
queue,
surface,
config,
);
for arg in std::env::args().skip(1){

View File

@@ -13,15 +13,20 @@ pub struct WindowContext<'a>{
simulation_paused:bool,
window:&'a winit::window::Window,
physics_thread:PlayerWorker<'a>,
device:wgpu::Device,
queue:wgpu::Queue,
}
impl WindowContext<'_>{
fn phys(&mut self,ins:TimedInstruction<crate::player::Instruction,strafesnet_common::session::Time>){
self.physics_thread.send(&self.device,&self.queue,ins);
}
fn window_event(&mut self,time:SessionTime,event:winit::event::WindowEvent){
match event{
winit::event::WindowEvent::DroppedFile(path)=>{
match crate::file::load(path.as_path()){
Ok(LoadFormat::Map(map))=>self.physics_thread.send(TimedInstruction{time,instruction:PhysicsWorkerInstruction::ChangeMap(map)}),
Ok(LoadFormat::Bot(bot))=>self.physics_thread.send(TimedInstruction{time,instruction:PhysicsWorkerInstruction::LoadReplay(bot)}),
Ok(LoadFormat::Map(map))=>self.phys(TimedInstruction{time,instruction:PhysicsWorkerInstruction::ChangeMap(map)}),
Ok(LoadFormat::Bot(bot))=>self.phys(TimedInstruction{time,instruction:PhysicsWorkerInstruction::LoadReplay(bot)}),
Err(e)=>println!("Failed to load file: {e}"),
}
},
@@ -31,7 +36,7 @@ impl WindowContext<'_>{
return;
}
//pause unpause
self.physics_thread.send(TimedInstruction{
self.phys(TimedInstruction{
time,
instruction:PhysicsWorkerInstruction::SessionControl(SessionControlInstruction::SetPaused(!state)),
});
@@ -74,7 +79,7 @@ impl WindowContext<'_>{
},
_=>None,
}{
self.physics_thread.send(TimedInstruction{
self.phys(TimedInstruction{
time,
instruction,
});
@@ -83,7 +88,7 @@ impl WindowContext<'_>{
}
},
winit::event::WindowEvent::Resized(size)=>{
self.physics_thread.send(
self.phys(
TimedInstruction{
time,
instruction:PhysicsWorkerInstruction::Resize(size)
@@ -92,7 +97,7 @@ impl WindowContext<'_>{
},
winit::event::WindowEvent::RedrawRequested=>{
self.window.request_redraw();
self.physics_thread.send(
self.phys(
TimedInstruction{
time,
instruction:PhysicsWorkerInstruction::Render
@@ -121,17 +126,19 @@ impl WindowContext<'_>{
window:&'a winit::window::Window,
device:wgpu::Device,
queue:wgpu::Queue,
surface:wgpu::Surface<'a>,
config:wgpu::SurfaceConfiguration,
surface:strafesnet_graphics::surface::Surface<'a>,
)->WindowContext<'a>{
let graphics=strafesnet_roblox_bot_player::graphics::Graphics::new(device,queue,config);
let size=surface.size();
let graphics=strafesnet_roblox_bot_player::graphics::Graphics::new(&device,&queue,size,surface.view_format());
WindowContext{
simulation_paused:false,
window,
physics_thread:crate::player::PlayerWorker::new(
surface,
graphics,
surface,
),
device,
queue,
}
}
}