forked from StrafesNET/strafe-client
real threads + GraphicsInstruction + thread accessible mouse
This commit is contained in:
parent
7130eafc06
commit
124139274f
@ -1,3 +1,18 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
|
use wgpu::{util::DeviceExt,AstcBlock,AstcChannel};
|
||||||
|
use crate::model_graphics::{GraphicsVertex,ModelGraphicsInstance};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ModelUpdate{
|
||||||
|
transform:Option<glam::Mat4>,
|
||||||
|
color:Option<glam::Vec4>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum GraphicsInstruction{
|
||||||
|
UpdateModel(ModelUpdate),
|
||||||
|
Render,
|
||||||
|
}
|
||||||
|
|
||||||
struct Entity {
|
struct Entity {
|
||||||
index_count: u32,
|
index_count: u32,
|
||||||
|
18
src/main.rs
18
src/main.rs
@ -1,6 +1,4 @@
|
|||||||
use std::{borrow::Cow, time::Instant};
|
use std::time::Instant;
|
||||||
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
|
|
||||||
use model_graphics::{GraphicsVertex,ModelGraphicsInstance};
|
|
||||||
use physics::{InputInstruction, PhysicsInstruction};
|
use physics::{InputInstruction, PhysicsInstruction};
|
||||||
use instruction::{TimedInstruction, InstructionConsumer};
|
use instruction::{TimedInstruction, InstructionConsumer};
|
||||||
|
|
||||||
@ -23,10 +21,18 @@ mod load_roblox;
|
|||||||
pub struct GlobalState{
|
pub struct GlobalState{
|
||||||
start_time: std::time::Instant,
|
start_time: std::time::Instant,
|
||||||
manual_mouse_lock:bool,
|
manual_mouse_lock:bool,
|
||||||
mouse:physics::MouseState,
|
mouse:std::sync::Arc<std::sync::Mutex<physics::MouseState>>,
|
||||||
user_settings:settings::UserSettings,
|
user_settings:settings::UserSettings,
|
||||||
graphics:graphics::GraphicsState,
|
//Ideally the graphics thread worker description is:
|
||||||
physics_thread:worker::CompatWorker<TimedInstruction<InputInstruction>,physics::PhysicsOutputState,Box<dyn FnMut(TimedInstruction<InputInstruction>)->physics::PhysicsOutputState>>,
|
/*
|
||||||
|
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 framework::Example for GlobalState {
|
impl framework::Example for GlobalState {
|
||||||
|
@ -736,11 +736,11 @@ impl PhysicsState {
|
|||||||
self.touching.clear();
|
self.touching.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_worker(mut self)->crate::worker::CompatWorker<TimedInstruction<InputInstruction>,PhysicsOutputState,Box<dyn FnMut(TimedInstruction<InputInstruction>)->PhysicsOutputState>>{
|
pub fn into_worker(mut self)->crate::worker::CNWorker<TimedInstruction<InputInstruction>>{
|
||||||
let mut mouse_blocking=true;
|
let mut mouse_blocking=true;
|
||||||
let mut last_mouse_time=self.next_mouse.time;
|
let mut last_mouse_time=self.next_mouse.time;
|
||||||
let mut timeline=std::collections::VecDeque::new();
|
let mut timeline=std::collections::VecDeque::new();
|
||||||
crate::worker::CompatWorker::new(self.output(),Box::new(move |ins:TimedInstruction<InputInstruction>|{
|
crate::worker::CNWorker::new(move |ins:TimedInstruction<InputInstruction>|{
|
||||||
if if let Some(phys_input)=match ins.instruction{
|
if if let Some(phys_input)=match ins.instruction{
|
||||||
InputInstruction::MoveMouse(m)=>{
|
InputInstruction::MoveMouse(m)=>{
|
||||||
if mouse_blocking{
|
if mouse_blocking{
|
||||||
@ -819,8 +819,7 @@ impl PhysicsState {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.output()
|
})
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn output(&self)->PhysicsOutputState{
|
pub fn output(&self)->PhysicsOutputState{
|
||||||
|
Loading…
Reference in New Issue
Block a user