implement instruction
This commit is contained in:
parent
43a0eef5d1
commit
7309949dd0
@ -1,23 +1,25 @@
|
|||||||
|
use crate::integer::Time;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TimedInstruction<I> {
|
pub struct TimedInstruction<I>{
|
||||||
pub time: crate::physics::TIME,
|
pub time:Time,
|
||||||
pub instruction: I,
|
pub instruction:I,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait InstructionEmitter<I> {
|
pub trait InstructionEmitter<I>{
|
||||||
fn next_instruction(&self, time_limit:crate::physics::TIME) -> Option<TimedInstruction<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>);
|
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//PROPER PRIVATE FIELDS!!!
|
//PROPER PRIVATE FIELDS!!!
|
||||||
pub struct InstructionCollector<I> {
|
pub struct InstructionCollector<I>{
|
||||||
time: crate::physics::TIME,
|
time:Time,
|
||||||
instruction: Option<I>,
|
instruction:Option<I>,
|
||||||
}
|
}
|
||||||
impl<I> InstructionCollector<I> {
|
impl<I> InstructionCollector<I>{
|
||||||
pub fn new(time:crate::physics::TIME) -> Self {
|
pub fn new(time:Time)->Self{
|
||||||
Self{
|
Self{
|
||||||
time,
|
time,
|
||||||
instruction:None
|
instruction:None
|
||||||
@ -25,24 +27,24 @@ impl<I> InstructionCollector<I> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
|
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
|
||||||
match instruction {
|
match instruction{
|
||||||
Some(unwrap_instruction) => {
|
Some(unwrap_instruction)=>{
|
||||||
if unwrap_instruction.time<self.time {
|
if unwrap_instruction.time<self.time {
|
||||||
self.time=unwrap_instruction.time;
|
self.time=unwrap_instruction.time;
|
||||||
self.instruction=Some(unwrap_instruction.instruction);
|
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
|
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
|
||||||
match self.instruction {
|
match self.instruction{
|
||||||
Some(instruction)=>Some(TimedInstruction{
|
Some(instruction)=>Some(TimedInstruction{
|
||||||
time:self.time,
|
time:self.time,
|
||||||
instruction
|
instruction
|
||||||
}),
|
}),
|
||||||
None => None,
|
None=>None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -496,7 +496,7 @@ impl PhysicsState {
|
|||||||
//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 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
|
//push an event to extrapolate no movement from
|
||||||
timeline.push_front(TimedInstruction{
|
timeline.push_front(TimedInstruction{
|
||||||
time:last_mouse_time,
|
time:last_mouse_time,
|
||||||
|
Loading…
Reference in New Issue
Block a user