implement instruction

This commit is contained in:
Quaternions 2023-10-11 22:16:06 -07:00
parent 43a0eef5d1
commit 7309949dd0
2 changed files with 20 additions and 18 deletions

View File

@ -1,23 +1,25 @@
use crate::integer::Time;
#[derive(Debug)]
pub struct TimedInstruction<I> {
pub time: crate::physics::TIME,
pub instruction: I,
pub struct TimedInstruction<I>{
pub time:Time,
pub instruction:I,
}
pub trait InstructionEmitter<I> {
fn next_instruction(&self, time_limit:crate::physics::TIME) -> Option<TimedInstruction<I>>;
pub trait InstructionEmitter<I>{
fn next_instruction(&self,time_limit:Time)->Option<TimedInstruction<I>>;
}
pub trait InstructionConsumer<I> {
pub trait InstructionConsumer<I>{
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
}
//PROPER PRIVATE FIELDS!!!
pub struct InstructionCollector<I> {
time: crate::physics::TIME,
instruction: Option<I>,
pub struct InstructionCollector<I>{
time:Time,
instruction:Option<I>,
}
impl<I> InstructionCollector<I> {
pub fn new(time:crate::physics::TIME) -> Self {
impl<I> InstructionCollector<I>{
pub fn new(time:Time)->Self{
Self{
time,
instruction:None
@ -25,24 +27,24 @@ impl<I> InstructionCollector<I> {
}
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
match instruction {
Some(unwrap_instruction) => {
match instruction{
Some(unwrap_instruction)=>{
if unwrap_instruction.time<self.time {
self.time=unwrap_instruction.time;
self.instruction=Some(unwrap_instruction.instruction);
}
},
None => (),
None=>(),
}
}
pub fn instruction(self) -> Option<TimedInstruction<I>> {
pub fn instruction(self)->Option<TimedInstruction<I>>{
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
match self.instruction {
match self.instruction{
Some(instruction)=>Some(TimedInstruction{
time:self.time,
instruction
}),
None => None,
None=>None,
}
}
}

View File

@ -496,7 +496,7 @@ impl PhysicsState {
//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,
//so mouse events are probably not handled separately from drawing and fire right before it :(
if 10_000_000<ins.time-self.next_mouse.time{
if Time::from_millis(10)<ins.time-self.next_mouse.time{
//push an event to extrapolate no movement from
timeline.push_front(TimedInstruction{
time:last_mouse_time,