common: tidy instruction module

This commit is contained in:
Quaternions 2025-01-15 03:26:43 -08:00
parent c2d6af8bda
commit 7ad76740d4

View File

@ -6,6 +6,7 @@ pub struct TimedInstruction<I,T>{
pub instruction:I, pub instruction:I,
} }
impl<I,T> TimedInstruction<I,T>{ impl<I,T> TimedInstruction<I,T>{
#[inline]
pub fn set_time<TimeInner>(self,new_time:Time<TimeInner>)->TimedInstruction<I,TimeInner>{ pub fn set_time<TimeInner>(self,new_time:Time<TimeInner>)->TimedInstruction<I,TimeInner>{
TimedInstruction{ TimedInstruction{
time:new_time, time:new_time,
@ -29,6 +30,7 @@ pub trait InstructionFeedback<I,T>:InstructionEmitter<I,TimeInner=T>+Instruction
where where
Time<T>:Copy, Time<T>:Copy,
{ {
#[inline]
fn process_exhaustive(&mut self,time_limit:Time<T>){ fn process_exhaustive(&mut self,time_limit:Time<T>){
while let Some(instruction)=self.next_instruction(time_limit){ while let Some(instruction)=self.next_instruction(time_limit){
self.process_instruction(instruction); self.process_instruction(instruction);
@ -49,6 +51,7 @@ pub struct InstructionCollector<I,T>{
impl<I,T> InstructionCollector<I,T> impl<I,T> InstructionCollector<I,T>
where Time<T>:Copy+PartialOrd, where Time<T>:Copy+PartialOrd,
{ {
#[inline]
pub const fn new(time:Time<T>)->Self{ pub const fn new(time:Time<T>)->Self{
Self{ Self{
time, time,
@ -60,24 +63,18 @@ impl<I,T> InstructionCollector<I,T>
self.time self.time
} }
pub fn collect(&mut self,instruction:Option<TimedInstruction<I,T>>){ pub fn collect(&mut self,instruction:Option<TimedInstruction<I,T>>){
match instruction{ if let Some(ins)=instruction{
Some(unwrap_instruction)=>{ if ins.time<self.time{
if unwrap_instruction.time<self.time { self.time=ins.time;
self.time=unwrap_instruction.time; self.instruction=Some(ins.instruction);
self.instruction=Some(unwrap_instruction.instruction);
} }
},
None=>(),
} }
} }
pub fn instruction(self)->Option<TimedInstruction<I,T>>{ pub fn instruction(self)->Option<TimedInstruction<I,T>>{
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR //STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
match self.instruction{ self.instruction.map(|instruction|TimedInstruction{
Some(instruction)=>Some(TimedInstruction{
time:self.time, time:self.time,
instruction instruction
}), })
None=>None,
}
} }
} }