2023-09-09 00:34:26 +00:00
|
|
|
pub struct TimedInstruction<I> {
|
2023-09-08 18:33:20 +00:00
|
|
|
pub time: crate::body::TIME,
|
2023-09-09 00:34:26 +00:00
|
|
|
pub instruction: I,
|
2023-09-08 18:33:20 +00:00
|
|
|
}
|
|
|
|
|
2023-09-09 00:34:26 +00:00
|
|
|
pub trait InstructionEmitter<I> {
|
2023-09-09 19:42:51 +00:00
|
|
|
fn next_instruction(&self, time:crate::body::TIME) -> Option<TimedInstruction<I>>;
|
2023-09-08 19:48:11 +00:00
|
|
|
}
|
2023-09-09 00:34:26 +00:00
|
|
|
pub trait InstructionConsumer<I> {
|
|
|
|
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-09 00:34:26 +00:00
|
|
|
pub struct InstructionCollector<I> {
|
2023-09-09 19:42:51 +00:00
|
|
|
time: crate::body::TIME,
|
|
|
|
instruction: Option<I>,
|
2023-09-08 19:48:11 +00:00
|
|
|
}
|
2023-09-09 00:34:26 +00:00
|
|
|
impl<I> InstructionCollector<I> {
|
2023-09-09 19:42:51 +00:00
|
|
|
pub fn new(time:crate::body::TIME) -> Self {
|
|
|
|
Self{
|
|
|
|
time,
|
|
|
|
instruction:None
|
|
|
|
}
|
2023-09-08 19:48:11 +00:00
|
|
|
}
|
|
|
|
|
2023-09-09 00:34:26 +00:00
|
|
|
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
|
2023-09-09 19:42:51 +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
|
|
|
},
|
|
|
|
None => (),
|
|
|
|
}
|
|
|
|
}
|
2023-09-09 00:34:26 +00:00
|
|
|
pub fn instruction(self) -> Option<TimedInstruction<I>> {
|
|
|
|
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
|
2023-09-09 19:42:51 +00:00
|
|
|
match self.instruction {
|
|
|
|
Some(instruction)=>Some(TimedInstruction{
|
|
|
|
time:self.time,
|
|
|
|
instruction
|
|
|
|
}),
|
|
|
|
None => None,
|
|
|
|
}
|
2023-09-08 19:48:11 +00:00
|
|
|
}
|
2023-09-08 18:33:20 +00:00
|
|
|
}
|