forked from StrafesNET/strafe-client
next_instruction non-optional time_limit
This commit is contained in:
parent
0fe14749d3
commit
a5aa89064b
11
src/body.rs
11
src/body.rs
@ -1,4 +1,4 @@
|
|||||||
use crate::instruction::TimedInstruction;
|
use crate::instruction::{InstructionEmitter, InstructionConsumer, TimedInstruction};
|
||||||
|
|
||||||
pub enum PhysicsInstruction {
|
pub enum PhysicsInstruction {
|
||||||
CollisionStart(RelativeCollision),
|
CollisionStart(RelativeCollision),
|
||||||
@ -210,10 +210,7 @@ impl PhysicsState {
|
|||||||
//tickless gaming
|
//tickless gaming
|
||||||
pub fn run(&mut self, time: TIME){
|
pub fn run(&mut self, time: TIME){
|
||||||
//prepare is ommitted - everything is done via instructions.
|
//prepare is ommitted - everything is done via instructions.
|
||||||
while let Some(instruction) = self.next_instruction() {//collect
|
while let Some(instruction) = self.next_instruction(time) {//collect
|
||||||
if time<instruction.time {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//advance
|
//advance
|
||||||
//self.advance_time(instruction.time);
|
//self.advance_time(instruction.time);
|
||||||
//process
|
//process
|
||||||
@ -281,9 +278,9 @@ impl PhysicsState {
|
|||||||
|
|
||||||
impl crate::instruction::InstructionEmitter<PhysicsInstruction> for PhysicsState {
|
impl crate::instruction::InstructionEmitter<PhysicsInstruction> for PhysicsState {
|
||||||
//this little next instruction function can cache its return value and invalidate the cached value by watching the State.
|
//this little next instruction function can cache its return value and invalidate the cached value by watching the State.
|
||||||
fn next_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
fn next_instruction(&self,time_limit:TIME) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||||
//JUST POLLING!!! NO MUTATION
|
//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)
|
//autohop (already pressing spacebar; the signal to begin trying to jump is different)
|
||||||
if self.grounded&&self.jump_trying {
|
if self.grounded&&self.jump_trying {
|
||||||
//scroll will be implemented with InputInstruction::Jump(true) but it blocks setting self.jump_trying=true
|
//scroll will be implemented with InputInstruction::Jump(true) but it blocks setting self.jump_trying=true
|
||||||
|
@ -4,7 +4,7 @@ pub struct TimedInstruction<I> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait InstructionEmitter<I> {
|
pub trait InstructionEmitter<I> {
|
||||||
fn next_instruction(&self) -> Option<TimedInstruction<I>>;
|
fn next_instruction(&self, time:crate::body::TIME) -> Option<TimedInstruction<I>>;
|
||||||
}
|
}
|
||||||
pub trait InstructionConsumer<I> {
|
pub trait InstructionConsumer<I> {
|
||||||
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
|
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
|
||||||
@ -12,26 +12,36 @@ pub trait InstructionConsumer<I> {
|
|||||||
|
|
||||||
//PROPER PRIVATE FIELDS!!!
|
//PROPER PRIVATE FIELDS!!!
|
||||||
pub struct InstructionCollector<I> {
|
pub struct InstructionCollector<I> {
|
||||||
instruction: Option<TimedInstruction<I>>,
|
time: crate::body::TIME,
|
||||||
|
instruction: Option<I>,
|
||||||
}
|
}
|
||||||
impl<I> InstructionCollector<I> {
|
impl<I> InstructionCollector<I> {
|
||||||
pub fn new() -> Self {
|
pub fn new(time:crate::body::TIME) -> Self {
|
||||||
Self{instruction:None}
|
Self{
|
||||||
|
time,
|
||||||
|
instruction:None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
|
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
|
||||||
match &instruction {
|
match instruction {
|
||||||
Some(unwrap_instruction) => match &self.instruction {
|
Some(unwrap_instruction) => {
|
||||||
Some(unwrap_best_instruction) => if unwrap_instruction.time<unwrap_best_instruction.time {
|
if unwrap_instruction.time<self.time {
|
||||||
self.instruction=instruction;
|
self.time=unwrap_instruction.time;
|
||||||
},
|
self.instruction=Some(unwrap_instruction.instruction);
|
||||||
None => self.instruction=instruction,
|
}
|
||||||
},
|
},
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn instruction(self) -> Option<TimedInstruction<I>> {
|
pub fn instruction(self) -> Option<TimedInstruction<I>> {
|
||||||
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
|
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
|
||||||
return self.instruction
|
match self.instruction {
|
||||||
|
Some(instruction)=>Some(TimedInstruction{
|
||||||
|
time:self.time,
|
||||||
|
instruction
|
||||||
|
}),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user