strafe-client-jed/src/instruction.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2023-09-19 01:34:48 +00:00
#[derive(Debug)]
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-19 01:06:03 +00:00
fn next_instruction(&self, time_limit: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> {
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> {
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>>){
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
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
}