Files
.cargo
lib
bsp_loader
common
src
aabb.rs
bvh.rs
controls_bitflag.rs
gameplay_attributes.rs
gameplay_modes.rs
gameplay_style.rs
instruction.rs
integer.rs
lib.rs
map.rs
model.rs
mouse.rs
physics.rs
run.rs
timer.rs
updatable.rs
.gitignore
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.md
deferred_loader
fixed_wide
linear_ops
ratio_ops
rbx_loader
roblox_emulator
snf
README.md
strafe-client
tools
.gitignore
Cargo.lock
Cargo.toml
README.md
logo.png
strafe-project/lib/common/src/instruction.rs
2025-01-02 19:28:07 -08:00

54 lines
1.1 KiB
Rust

use crate::integer::Time;
#[derive(Debug)]
pub struct TimedInstruction<I>{
pub time:Time,
pub instruction:I,
}
pub trait InstructionEmitter<I>{
fn next_instruction(&self,time_limit:Time)->Option<TimedInstruction<I>>;
}
pub trait InstructionConsumer<I>{
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
}
//PROPER PRIVATE FIELDS!!!
pub struct InstructionCollector<I>{
time:Time,
instruction:Option<I>,
}
impl<I> InstructionCollector<I>{
pub const fn new(time:Time)->Self{
Self{
time,
instruction:None
}
}
#[inline]
pub const fn time(&self)->Time{
self.time
}
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);
}
},
None=>(),
}
}
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,
}
}
}