This commit is contained in:
Quaternions 2023-10-23 20:22:06 -07:00
parent 9c9d8f8f8f
commit 4655f43f5f
3 changed files with 18 additions and 16 deletions

View File

@ -3,4 +3,11 @@ struct Context{
queue:wgpu::Queue,
}
//??
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
}

View File

@ -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<TimedInstruction<InputInstruction>>{
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});
}
})
}

View File

@ -194,7 +194,8 @@ impl RunState {
pub fn into_worker(self,mut setup_context:crate::setup_context::SetupContext)->crate::worker::QNWorker<TimedInstruction<RunInstruction>>{
//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<RunInstruction>|{
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();
}