forked from StrafesNET/strafe-project
InstructionCache
This commit is contained in:
parent
13cae4c7c5
commit
9ae740fb49
@ -33,6 +33,42 @@ impl<I,T,X> InstructionFeedback<I,T> for X
|
|||||||
X:InstructionEmitter<I,TimeInner=T>+InstructionConsumer<I,TimeInner=T>,
|
X:InstructionEmitter<I,TimeInner=T>+InstructionConsumer<I,TimeInner=T>,
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
pub struct InstructionCache<S,I,T>{
|
||||||
|
instruction_machine:S,
|
||||||
|
cached_instruction:Option<TimedInstruction<I,T>>,
|
||||||
|
time_limit:Time<T>,
|
||||||
|
}
|
||||||
|
impl<S,I,T> InstructionCache<S,I,T>
|
||||||
|
where
|
||||||
|
Time<T>:Copy+Ord,
|
||||||
|
Option<TimedInstruction<I,T>>:Clone,
|
||||||
|
S:InstructionEmitter<I,TimeInner=T>+InstructionConsumer<I,TimeInner=T>
|
||||||
|
{
|
||||||
|
pub fn new(
|
||||||
|
instruction_machine:S,
|
||||||
|
)->Self{
|
||||||
|
Self{
|
||||||
|
instruction_machine,
|
||||||
|
cached_instruction:None,
|
||||||
|
time_limit:Time::MIN,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn next_instruction_cached(&mut self,time_limit:Time<T>)->Option<TimedInstruction<I,T>>{
|
||||||
|
if time_limit<self.time_limit{
|
||||||
|
return self.cached_instruction.clone();
|
||||||
|
}
|
||||||
|
let next_instruction=self.instruction_machine.next_instruction(time_limit);
|
||||||
|
self.cached_instruction=next_instruction.clone();
|
||||||
|
self.time_limit=time_limit;
|
||||||
|
next_instruction
|
||||||
|
}
|
||||||
|
pub fn process_instruction(&mut self,instruction:TimedInstruction<I,T>){
|
||||||
|
// invalidate cache
|
||||||
|
self.time_limit=Time::MIN;
|
||||||
|
self.instruction_machine.process_instruction(instruction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//PROPER PRIVATE FIELDS!!!
|
//PROPER PRIVATE FIELDS!!!
|
||||||
pub struct InstructionCollector<I,T>{
|
pub struct InstructionCollector<I,T>{
|
||||||
time:Time<T>,
|
time:Time<T>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user