forked from StrafesNET/strafe-client
delete window.rs, create run.rs
This commit is contained in:
parent
f6f2995ae0
commit
b445277346
@ -21,6 +21,16 @@ struct GraphicsContextPartial1{
|
|||||||
backends:wgpu::Backends,
|
backends:wgpu::Backends,
|
||||||
instance:wgpu::Instance,
|
instance:wgpu::Instance,
|
||||||
}
|
}
|
||||||
|
fn create_window(title:&str,event_loop:&winit::event_loop::EventLoop<()>)->Result<winit::window::Window,winit::error::OsError>{
|
||||||
|
let mut builder = winit::window::WindowBuilder::new();
|
||||||
|
builder = builder.with_title(title);
|
||||||
|
#[cfg(windows_OFF)] // TODO
|
||||||
|
{
|
||||||
|
use winit::platform::windows::WindowBuilderExtWindows;
|
||||||
|
builder = builder.with_no_redirection_bitmap(true);
|
||||||
|
}
|
||||||
|
builder.build(event_loop)
|
||||||
|
}
|
||||||
fn create_instance()->GraphicsContextPartial1{
|
fn create_instance()->GraphicsContextPartial1{
|
||||||
let backends=wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
|
let backends=wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
|
||||||
let dx12_shader_compiler=wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default();
|
let dx12_shader_compiler=wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default();
|
||||||
@ -178,7 +188,7 @@ pub struct GraphicsContext{
|
|||||||
pub fn setup(title:&str)->GraphicsContextSetup{
|
pub fn setup(title:&str)->GraphicsContextSetup{
|
||||||
let event_loop=winit::event_loop::EventLoop::new().unwrap();
|
let event_loop=winit::event_loop::EventLoop::new().unwrap();
|
||||||
|
|
||||||
let window=crate::window::WindowState::create_window(title,&event_loop).unwrap();
|
let window=create_window(title,&event_loop).unwrap();
|
||||||
|
|
||||||
println!("Initializing the surface...");
|
println!("Initializing the surface...");
|
||||||
|
|
||||||
@ -205,19 +215,19 @@ enum RunInstruction{
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GraphicsContext{
|
impl GraphicsContext{
|
||||||
fn into_worker(self,mut global_state:crate::GlobalState)->crate::worker::QNWorker<TimedInstruction<RunInstruction>>{
|
fn into_worker(self,mut run:crate::run::RunState)->crate::worker::QNWorker<TimedInstruction<RunInstruction>>{
|
||||||
crate::worker::QNWorker::new(move |ins:TimedInstruction<RunInstruction>|{
|
crate::worker::QNWorker::new(move |ins:TimedInstruction<RunInstruction>|{
|
||||||
match ins.instruction{
|
match ins.instruction{
|
||||||
RunInstruction::WindowEvent(window_event)=>{
|
RunInstruction::WindowEvent(window_event)=>{
|
||||||
global_state.window_event(window_event);
|
run.window_event(window_event);
|
||||||
},
|
},
|
||||||
RunInstruction::DeviceEvent(device_event)=>{
|
RunInstruction::DeviceEvent(device_event)=>{
|
||||||
global_state.device_event(device_event);
|
run.device_event(device_event);
|
||||||
},
|
},
|
||||||
RunInstruction::Resize(size)=>{
|
RunInstruction::Resize(size)=>{
|
||||||
self.config.width=size.width.max(1);
|
self.config.width=size.width.max(1);
|
||||||
self.config.height=size.height.max(1);
|
self.config.height=size.height.max(1);
|
||||||
global_state.graphics.resize(&self.device,&self.config);
|
run.graphics.resize(&self.device,&self.config);
|
||||||
self.surface.configure(&self.device,&self.config);
|
self.surface.configure(&self.device,&self.config);
|
||||||
}
|
}
|
||||||
RunInstruction::Render=>{
|
RunInstruction::Render=>{
|
||||||
@ -235,7 +245,7 @@ impl GraphicsContext{
|
|||||||
..wgpu::TextureViewDescriptor::default()
|
..wgpu::TextureViewDescriptor::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
global_state.graphics.render(&view,&self.device,&self.queue);
|
run.graphics.render(&view,&self.device,&self.queue);
|
||||||
|
|
||||||
frame.present();
|
frame.present();
|
||||||
}
|
}
|
||||||
@ -260,13 +270,13 @@ impl GraphicsContextSetup{
|
|||||||
self.partial_graphics_context.configure_surface(&size),
|
self.partial_graphics_context.configure_surface(&size),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
pub fn start(self,mut global_state:crate::GlobalState){
|
pub fn start(self,mut run:crate::run::RunState){
|
||||||
let (window,event_loop,graphics_context)=self.into_split();
|
let (window,event_loop,graphics_context)=self.into_split();
|
||||||
|
|
||||||
//dedicated thread to pigh request redraw back and resize the window doesn't seem logical
|
//dedicated thread to pigh request redraw back and resize the window doesn't seem logical
|
||||||
|
|
||||||
//physics and graphics render thread
|
//physics and graphics render thread
|
||||||
let run_thread=graphics_context.into_worker(global_state);
|
let run_thread=graphics_context.into_worker(run);
|
||||||
|
|
||||||
println!("Entering render loop...");
|
println!("Entering render loop...");
|
||||||
let root_time=std::time::Instant::now();
|
let root_time=std::time::Instant::now();
|
||||||
|
68
src/main.rs
68
src/main.rs
@ -1,12 +1,7 @@
|
|||||||
use std::time::Instant;
|
|
||||||
use physics::PhysicsInstruction;
|
|
||||||
use render_thread::InputInstruction;
|
|
||||||
use instruction::{TimedInstruction, InstructionConsumer};
|
|
||||||
|
|
||||||
mod bvh;
|
mod bvh;
|
||||||
|
mod run;
|
||||||
mod aabb;
|
mod aabb;
|
||||||
mod model;
|
mod model;
|
||||||
mod window;
|
|
||||||
mod worker;
|
mod worker;
|
||||||
mod zeroes;
|
mod zeroes;
|
||||||
mod integer;
|
mod integer;
|
||||||
@ -20,23 +15,6 @@ mod render_thread;
|
|||||||
mod model_graphics;
|
mod model_graphics;
|
||||||
mod graphics_context;
|
mod graphics_context;
|
||||||
|
|
||||||
|
|
||||||
pub struct GlobalState{
|
|
||||||
manual_mouse_lock:bool,
|
|
||||||
mouse:std::sync::Arc<std::sync::Mutex<physics::MouseState>>,
|
|
||||||
user_settings:settings::UserSettings,
|
|
||||||
//Ideally the graphics thread worker description is:
|
|
||||||
/*
|
|
||||||
WorkerDescription{
|
|
||||||
input:Immediate,
|
|
||||||
output:Realtime(PoolOrdering::Ordered(3)),
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//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
|
|
||||||
graphics_thread:worker::INWorker<graphics::GraphicsInstruction>,
|
|
||||||
physics_thread:worker::QNWorker<TimedInstruction<InputInstruction>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_file(path: std::path::PathBuf)->Option<model::IndexedModelInstances>{
|
fn load_file(path: std::path::PathBuf)->Option<model::IndexedModelInstances>{
|
||||||
println!("Loading file: {:?}", &path);
|
println!("Loading file: {:?}", &path);
|
||||||
//oh boy! let's load the map!
|
//oh boy! let's load the map!
|
||||||
@ -138,48 +116,10 @@ fn default_models()->model::IndexedModelInstances{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlobalState {
|
|
||||||
fn init() -> Self {
|
|
||||||
//wee
|
|
||||||
let user_settings=settings::read_user_settings();
|
|
||||||
|
|
||||||
let mut graphics=GraphicsState::new();
|
|
||||||
|
|
||||||
graphics.load_user_settings(&user_settings);
|
|
||||||
|
|
||||||
//how to multithread
|
|
||||||
|
|
||||||
//1. build
|
|
||||||
physics.generate_models(&indexed_model_instances);
|
|
||||||
|
|
||||||
//2. move
|
|
||||||
let physics_thread=physics.into_worker();
|
|
||||||
|
|
||||||
//3. forget
|
|
||||||
|
|
||||||
let mut state=GlobalState{
|
|
||||||
manual_mouse_lock:false,
|
|
||||||
mouse:physics::MouseState::default(),
|
|
||||||
user_settings,
|
|
||||||
graphics,
|
|
||||||
physics_thread,
|
|
||||||
};
|
|
||||||
state.generate_model_graphics(&device,&queue,indexed_model_instances);
|
|
||||||
|
|
||||||
let args:Vec<String>=std::env::args().collect();
|
|
||||||
if args.len()==2{
|
|
||||||
let indexed_model_instances=load_file(std::path::PathBuf::from(&args[1]));
|
|
||||||
state.render_thread=RenderThread::new(user_settings,indexed_model_instances);
|
|
||||||
}
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main(){
|
fn main(){
|
||||||
let title=format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")).as_str();
|
let title=format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")).as_str();
|
||||||
let context=graphics_context::setup(title);
|
let context=graphics_context::setup(title);
|
||||||
let global_state=GlobalState::init();//new
|
let run=run::RunState::init();//new
|
||||||
global_state.replace_models(&context,default_models());
|
run.replace_models(&context,default_models());
|
||||||
context.start(global_state);
|
context.start(run);
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,59 @@
|
|||||||
pub enum WindowInstruction{
|
use crate::physics::PhysicsInstruction;
|
||||||
Resize(),
|
use crate::render_thread::InputInstruction;
|
||||||
}
|
use crate::instruction::{TimedInstruction, InstructionConsumer};
|
||||||
pub struct WindowState{
|
|
||||||
//ok
|
|
||||||
}
|
|
||||||
impl WindowState{
|
|
||||||
fn resize(&mut self);
|
|
||||||
fn render(&self);
|
|
||||||
|
|
||||||
|
pub struct RunState{
|
||||||
|
manual_mouse_lock:bool,
|
||||||
|
mouse:std::sync::Arc<std::sync::Mutex<physics::MouseState>>,
|
||||||
|
user_settings:settings::UserSettings,
|
||||||
|
//Ideally the graphics thread worker description is:
|
||||||
|
/*
|
||||||
|
WorkerDescription{
|
||||||
|
input:Immediate,
|
||||||
|
output:Realtime(PoolOrdering::Ordered(3)),
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
//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
|
||||||
|
graphics_thread:worker::INWorker<graphics::GraphicsInstruction>,
|
||||||
|
physics_thread:worker::QNWorker<TimedInstruction<InputInstruction>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RunState {
|
||||||
|
fn init() -> Self {
|
||||||
|
//wee
|
||||||
|
let user_settings=settings::read_user_settings();
|
||||||
|
|
||||||
|
let mut graphics=GraphicsState::new();
|
||||||
|
|
||||||
|
graphics.load_user_settings(&user_settings);
|
||||||
|
|
||||||
|
//how to multithread
|
||||||
|
|
||||||
|
//1. build
|
||||||
|
physics.generate_models(&indexed_model_instances);
|
||||||
|
|
||||||
|
//2. move
|
||||||
|
let physics_thread=physics.into_worker();
|
||||||
|
|
||||||
|
//3. forget
|
||||||
|
|
||||||
|
let mut state=RunState{
|
||||||
|
manual_mouse_lock:false,
|
||||||
|
mouse:physics::MouseState::default(),
|
||||||
|
user_settings,
|
||||||
|
graphics,
|
||||||
|
physics_thread,
|
||||||
|
};
|
||||||
|
state.generate_model_graphics(&device,&queue,indexed_model_instances);
|
||||||
|
|
||||||
|
let args:Vec<String>=std::env::args().collect();
|
||||||
|
if args.len()==2{
|
||||||
|
let indexed_model_instances=load_file(std::path::PathBuf::from(&args[1]));
|
||||||
|
state.render_thread=RenderThread::new(user_settings,indexed_model_instances);
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
fn window_event(&mut self, window: &winit::window::Window, event: winit::event::WindowEvent) {
|
fn window_event(&mut self, window: &winit::window::Window, event: winit::event::WindowEvent) {
|
||||||
match event {
|
match event {
|
||||||
winit::event::WindowEvent::DroppedFile(path)=>{
|
winit::event::WindowEvent::DroppedFile(path)=>{
|
||||||
@ -138,18 +184,4 @@ impl WindowState{
|
|||||||
_=>(),
|
_=>(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_window(title:&str,event_loop:&winit::event_loop::EventLoop<()>)->Result<winit::window::Window,winit::error::OsError>{
|
|
||||||
let mut builder = winit::window::WindowBuilder::new();
|
|
||||||
builder = builder.with_title(title);
|
|
||||||
#[cfg(windows_OFF)] // TODO
|
|
||||||
{
|
|
||||||
use winit::platform::windows::WindowBuilderExtWindows;
|
|
||||||
builder = builder.with_no_redirection_bitmap(true);
|
|
||||||
}
|
|
||||||
builder.build(event_loop)
|
|
||||||
}
|
|
||||||
pub fn into_thread(window:winit::window::Window){
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user