strafe-client-jed/src/instruction.rs

37 lines
985 B
Rust
Raw Normal View History

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> {
fn next_instruction(&self) -> 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> {
instruction: Option<TimedInstruction<I>>,
2023-09-08 19:48:11 +00:00
}
2023-09-09 00:34:26 +00:00
impl<I> InstructionCollector<I> {
2023-09-08 19:48:11 +00:00
pub fn new() -> Self {
2023-09-09 00:34:26 +00:00
Self{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>>){
match &instruction {
Some(unwrap_instruction) => match &self.instruction {
Some(unwrap_best_instruction) => if unwrap_instruction.time<unwrap_best_instruction.time {
self.instruction=instruction;
2023-09-08 19:48:11 +00:00
},
2023-09-09 00:34:26 +00:00
None => self.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
return self.instruction
2023-09-08 19:48:11 +00:00
}
2023-09-08 18:33:20 +00:00
}