diff --git a/src/body.rs b/src/body.rs index ca3f490e..55cbb303 100644 --- a/src/body.rs +++ b/src/body.rs @@ -1,4 +1,4 @@ -use crate::instruction::TimedInstruction; +use crate::instruction::{InstructionEmitter, InstructionConsumer, TimedInstruction}; pub enum PhysicsInstruction { CollisionStart(RelativeCollision), @@ -210,10 +210,7 @@ impl PhysicsState { //tickless gaming pub fn run(&mut self, time: TIME){ //prepare is ommitted - everything is done via instructions. - while let Some(instruction) = self.next_instruction() {//collect - if time for PhysicsState { //this little next instruction function can cache its return value and invalidate the cached value by watching the State. - fn next_instruction(&self) -> Option> { + fn next_instruction(&self,time_limit:TIME) -> Option> { //JUST POLLING!!! NO MUTATION - let mut collector = crate::instruction::InstructionCollector::new(); + let mut collector = crate::instruction::InstructionCollector::new(time_limit); //autohop (already pressing spacebar; the signal to begin trying to jump is different) if self.grounded&&self.jump_trying { //scroll will be implemented with InputInstruction::Jump(true) but it blocks setting self.jump_trying=true diff --git a/src/instruction.rs b/src/instruction.rs index f45efe96..a56b848f 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -4,7 +4,7 @@ pub struct TimedInstruction { } pub trait InstructionEmitter { - fn next_instruction(&self) -> Option>; + fn next_instruction(&self, time:crate::body::TIME) -> Option>; } pub trait InstructionConsumer { fn process_instruction(&mut self, instruction:TimedInstruction); @@ -12,26 +12,36 @@ pub trait InstructionConsumer { //PROPER PRIVATE FIELDS!!! pub struct InstructionCollector { - instruction: Option>, + time: crate::body::TIME, + instruction: Option, } impl InstructionCollector { - pub fn new() -> Self { - Self{instruction:None} + pub fn new(time:crate::body::TIME) -> Self { + Self{ + time, + instruction:None + } } pub fn collect(&mut self,instruction:Option>){ - match &instruction { - Some(unwrap_instruction) => match &self.instruction { - Some(unwrap_best_instruction) => if unwrap_instruction.time self.instruction=instruction, + match instruction { + Some(unwrap_instruction) => { + if unwrap_instruction.time (), } } pub fn instruction(self) -> Option> { //STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR - return self.instruction + match self.instruction { + Some(instruction)=>Some(TimedInstruction{ + time:self.time, + instruction + }), + None => None, + } } } \ No newline at end of file