strafe-client/src/instruction.rs

53 lines
1.1 KiB
Rust
Raw Normal View History

2023-09-27 09:12:20 +00:00
use crate::integer::Time;
2023-09-19 01:34:48 +00:00
#[derive(Debug)]
2023-09-27 09:12:20 +00:00
pub struct TimedInstruction<I>{
pub time:Time,
pub instruction:I,
2023-09-08 18:33:20 +00:00
}
2023-09-27 09:12:20 +00:00
pub trait InstructionEmitter<I>{
fn next_instruction(&self,time_limit:Time)->Option<TimedInstruction<I>>;
2023-09-08 19:48:11 +00:00
}
2023-09-27 09:12:20 +00:00
pub trait InstructionConsumer<I>{
2023-09-09 00:34:26 +00:00
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
2023-09-09 00:15:49 +00:00
}
2023-09-08 19:48:11 +00:00
//PROPER PRIVATE FIELDS!!!
2023-09-27 09:12:20 +00:00
pub struct InstructionCollector<I>{
time:Time,
instruction:Option<I>,
2023-09-08 19:48:11 +00:00
}
2023-09-27 09:12:20 +00:00
impl<I> InstructionCollector<I>{
pub fn new(time:Time)->Self{
Self{
time,
instruction:None
}
2023-09-08 19:48:11 +00:00
}
2023-11-30 05:20:52 +00:00
#[inline]
pub fn time(&self)->Time{
self.time
}
2023-09-09 00:34:26 +00:00
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
2023-09-27 09:12:20 +00:00
match instruction{
Some(unwrap_instruction)=>{
if unwrap_instruction.time<self.time {
self.time=unwrap_instruction.time;
self.instruction=Some(unwrap_instruction.instruction);
}
2023-09-08 19:48:11 +00:00
},
2023-09-27 09:12:20 +00:00
None=>(),
2023-09-08 19:48:11 +00:00
}
}
2023-09-27 09:12:20 +00:00
pub fn instruction(self)->Option<TimedInstruction<I>>{
2023-09-09 00:34:26 +00:00
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
2023-09-27 09:12:20 +00:00
match self.instruction{
Some(instruction)=>Some(TimedInstruction{
time:self.time,
instruction
}),
2023-09-27 09:12:20 +00:00
None=>None,
}
2023-09-08 19:48:11 +00:00
}
2023-09-08 18:33:20 +00:00
}