be pedantic about public private

This commit is contained in:
Quaternions 2024-02-21 04:11:31 -08:00
parent aadcca91ea
commit 623a2d2a4f
3 changed files with 47 additions and 35 deletions

View File

@ -27,6 +27,7 @@ pub enum PhysicsInstruction {
// ) // )
//InputInstructions conditionally activate RefreshWalkTarget (by doing what SetWalkTargetVelocity used to do and then flagging it) //InputInstructions conditionally activate RefreshWalkTarget (by doing what SetWalkTargetVelocity used to do and then flagging it)
Input(PhysicsInputInstruction), Input(PhysicsInputInstruction),
SetSensitivity(Ratio64Vec2),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum PhysicsInputInstruction { pub enum PhysicsInputInstruction {
@ -937,27 +938,13 @@ impl Default for PhysicsData{
} }
impl PhysicsState { impl PhysicsState {
pub fn clear(&mut self){ fn clear(&mut self){
self.touching.clear(); self.touching.clear();
} }
pub const fn output(&self)->PhysicsOutputState{ fn advance_time(&mut self, time: Time){
PhysicsOutputState{
body:self.body,
camera:self.camera,
camera_offset:self.style.camera_offset,
mouse_pos:self.input_state.mouse.pos,
}
}
pub fn load_user_settings(&mut self,user_settings:&crate::settings::UserSettings){
self.camera.sensitivity=user_settings.calculate_sensitivity();
}
pub fn advance_time(&mut self, time: Time){
self.body.advance_time(time); self.body.advance_time(time);
self.time=time; self.time=time;
} }
pub const fn get_next_mouse(&self)->&MouseState{
self.input_state.get_next_mouse()
}
fn next_move_instruction(&self)->Option<TimedInstruction<PhysicsInstruction>>{ fn next_move_instruction(&self)->Option<TimedInstruction<PhysicsInstruction>>{
self.move_state.next_move_instruction(&self.style.strafe,self.time) self.move_state.next_move_instruction(&self.style.strafe,self.time)
} }
@ -996,7 +983,7 @@ impl PhysicsState {
#[derive(Default)] #[derive(Default)]
pub struct PhysicsContext{ pub struct PhysicsContext{
pub state:PhysicsState,//this captures the entire state of the physics. state:PhysicsState,//this captures the entire state of the physics.
data:PhysicsData,//data currently loaded into memory which is needded for physics to run, but is not part of the state. data:PhysicsData,//data currently loaded into memory which is needded for physics to run, but is not part of the state.
} }
impl instruction::InstructionConsumer<PhysicsInstruction> for PhysicsContext{ impl instruction::InstructionConsumer<PhysicsInstruction> for PhysicsContext{
@ -1011,13 +998,32 @@ impl instruction::InstructionEmitter<PhysicsInstruction> for PhysicsContext{
} }
} }
impl PhysicsContext{ impl PhysicsContext{
pub fn clear(&mut self){
self.state.clear();
}
pub fn load_user_settings(&mut self,user_settings:&crate::settings::UserSettings){
self.process_instruction(TimedInstruction{
time:self.state.time,
instruction:PhysicsInstruction::SetSensitivity(user_settings.calculate_sensitivity()),
});
}
pub fn spawn(&mut self){ pub fn spawn(&mut self){
self.process_instruction(instruction::TimedInstruction{ self.process_instruction(TimedInstruction{
time:self.state.time, time:self.state.time,
instruction:PhysicsInstruction::Input(PhysicsInputInstruction::Reset), instruction:PhysicsInstruction::Input(PhysicsInputInstruction::Reset),
}); });
} }
pub const fn output(&self)->PhysicsOutputState{
PhysicsOutputState{
body:self.state.body,
camera:self.state.camera,
camera_offset:self.state.style.camera_offset,
mouse_pos:self.state.input_state.mouse.pos,
}
}
pub const fn get_next_mouse(&self)->&MouseState{
self.state.input_state.get_next_mouse()
}
pub fn generate_models(&mut self,map:&map::CompleteMap){ pub fn generate_models(&mut self,map:&map::CompleteMap){
self.data.modes=map.modes.clone(); self.data.modes=map.modes.clone();
let mut used_attributes=Vec::new(); let mut used_attributes=Vec::new();
@ -1087,7 +1093,7 @@ impl PhysicsContext{
} }
//tickless gaming //tickless gaming
pub fn run(&mut self,time_limit:Time){ fn run(&mut self,time_limit:Time){
//prepare is ommitted - everything is done via instructions. //prepare is ommitted - everything is done via instructions.
while let Some(instruction)=self.next_instruction(time_limit){//collect while let Some(instruction)=self.next_instruction(time_limit){//collect
//process //process
@ -1095,6 +1101,13 @@ impl PhysicsContext{
//write hash lol //write hash lol
} }
} }
pub fn run_input_instruction(&mut self,instruction:TimedInstruction<PhysicsInputInstruction>){
self.run(instruction.time);
self.process_instruction(TimedInstruction{
time:instruction.time,
instruction:PhysicsInstruction::Input(instruction.instruction),
});
}
} }
fn literally_next_instruction_but_with_context(state:&PhysicsState,data:&PhysicsData,time_limit:Time)->Option<TimedInstruction<PhysicsInstruction>>{ fn literally_next_instruction_but_with_context(state:&PhysicsState,data:&PhysicsData,time_limit:Time)->Option<TimedInstruction<PhysicsInstruction>>{
@ -1270,7 +1283,9 @@ fn run_teleport_behaviour(wormhole:&Option<gameplay_attributes::Wormhole>,models
|PhysicsInstruction::ReachWalkTargetVelocity |PhysicsInstruction::ReachWalkTargetVelocity
|PhysicsInstruction::CollisionStart(_) |PhysicsInstruction::CollisionStart(_)
|PhysicsInstruction::CollisionEnd(_) |PhysicsInstruction::CollisionEnd(_)
|PhysicsInstruction::StrafeTick=>state.advance_time(ins.time), |PhysicsInstruction::StrafeTick
|PhysicsInstruction::SetSensitivity(_)
=>state.advance_time(ins.time),
} }
match ins.instruction{ match ins.instruction{
PhysicsInstruction::CollisionStart(c)=>{ PhysicsInstruction::CollisionStart(c)=>{
@ -1419,6 +1434,7 @@ fn run_teleport_behaviour(wormhole:&Option<gameplay_attributes::Wormhole>,models
} }
} }
}, },
PhysicsInstruction::SetSensitivity(sensitivity)=>state.camera.sensitivity=sensitivity,
PhysicsInstruction::Input(input_instruction)=>{ PhysicsInstruction::Input(input_instruction)=>{
let mut b_refresh_walk_target=true; let mut b_refresh_walk_target=true;
match input_instruction{ match input_instruction{

View File

@ -25,7 +25,7 @@ pub enum Instruction{
pub fn new(mut physics:crate::physics::PhysicsContext,mut graphics_worker:crate::compat_worker::INWorker<crate::graphics_worker::Instruction>)->crate::compat_worker::QNWorker<TimedInstruction<Instruction>>{ pub fn new(mut physics:crate::physics::PhysicsContext,mut graphics_worker:crate::compat_worker::INWorker<crate::graphics_worker::Instruction>)->crate::compat_worker::QNWorker<TimedInstruction<Instruction>>{
let mut mouse_blocking=true; let mut mouse_blocking=true;
let mut last_mouse_time=physics.state.get_next_mouse().time; let mut last_mouse_time=physics.get_next_mouse().time;
let mut timeline=std::collections::VecDeque::new(); let mut timeline=std::collections::VecDeque::new();
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{ crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
if if let Some(phys_input)=match &ins.instruction{ if if let Some(phys_input)=match &ins.instruction{
@ -43,7 +43,7 @@ pub enum Instruction{
timeline.push_front(TimedInstruction{ timeline.push_front(TimedInstruction{
time:last_mouse_time, time:last_mouse_time,
instruction:PhysicsInputInstruction::ReplaceMouse( instruction:PhysicsInputInstruction::ReplaceMouse(
MouseState{time:last_mouse_time,pos:physics.state.get_next_mouse().pos}, MouseState{time:last_mouse_time,pos:physics.get_next_mouse().pos},
MouseState{time:ins.time,pos:m} MouseState{time:ins.time,pos:m}
), ),
}); });
@ -79,11 +79,11 @@ pub enum Instruction{
//shitty mice are 125Hz which is 8ms so this should cover that. //shitty mice are 125Hz which is 8ms so this should cover that.
//setting this to 100us still doesn't print even though it's 10x lower than the polling rate, //setting this to 100us still doesn't print even though it's 10x lower than the polling rate,
//so mouse events are probably not handled separately from drawing and fire right before it :( //so mouse events are probably not handled separately from drawing and fire right before it :(
if Time::from_millis(10)<ins.time-physics.state.get_next_mouse().time{ if Time::from_millis(10)<ins.time-physics.get_next_mouse().time{
//push an event to extrapolate no movement from //push an event to extrapolate no movement from
timeline.push_front(TimedInstruction{ timeline.push_front(TimedInstruction{
time:last_mouse_time, time:last_mouse_time,
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:physics.state.get_next_mouse().pos}), instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:physics.get_next_mouse().pos}),
}); });
last_mouse_time=ins.time; last_mouse_time=ins.time;
//stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets. //stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets.
@ -104,16 +104,12 @@ pub enum Instruction{
}{ }{
//empty queue //empty queue
while let Some(instruction)=timeline.pop_front(){ while let Some(instruction)=timeline.pop_front(){
physics.run(instruction.time); physics.run_input_instruction(instruction);
physics.process_instruction(TimedInstruction{
time:instruction.time,
instruction:crate::physics::PhysicsInstruction::Input(instruction.instruction),
});
} }
} }
match ins.instruction{ match ins.instruction{
Instruction::Render=>{ Instruction::Render=>{
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.state.output(),ins.time,physics.state.get_next_mouse().pos)).unwrap(); graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.get_next_mouse().pos)).unwrap();
}, },
Instruction::Resize(size,user_settings)=>{ Instruction::Resize(size,user_settings)=>{
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap(); graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
@ -124,7 +120,7 @@ pub enum Instruction{
graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(map)).unwrap(); graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(map)).unwrap();
}, },
Instruction::ClearModels=>{ Instruction::ClearModels=>{
physics.state.clear(); physics.clear();
graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap(); graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap();
}, },
_=>(), _=>(),

View File

@ -173,7 +173,7 @@ impl<'a> WindowContextSetup<'a>{
let user_settings=crate::settings::read_user_settings(); let user_settings=crate::settings::read_user_settings();
let mut physics=crate::physics::PhysicsContext::default(); let mut physics=crate::physics::PhysicsContext::default();
physics.state.load_user_settings(&user_settings); physics.load_user_settings(&user_settings);
let mut graphics=crate::graphics::GraphicsState::new(&context.device,&context.queue,&context.config); let mut graphics=crate::graphics::GraphicsState::new(&context.device,&context.queue,&context.config);
graphics.load_user_settings(&user_settings); graphics.load_user_settings(&user_settings);