rename EventStruct to TimedInstruction
This commit is contained in:
parent
a4ed50fc38
commit
949897a558
48
src/body.rs
48
src/body.rs
@ -1,6 +1,6 @@
|
|||||||
use crate::event::EventStruct;
|
use crate::instruction::TimedInstruction;
|
||||||
|
|
||||||
pub enum PhysicsEvent {
|
pub enum PhysicsInstruction {
|
||||||
CollisionStart(RelativeCollision),
|
CollisionStart(RelativeCollision),
|
||||||
CollisionEnd(RelativeCollision),
|
CollisionEnd(RelativeCollision),
|
||||||
StrafeTick,
|
StrafeTick,
|
||||||
@ -198,7 +198,7 @@ impl PhysicsState {
|
|||||||
if applied_friction*applied_friction<diffv.length_squared() {
|
if applied_friction*applied_friction<diffv.length_squared() {
|
||||||
self.body.velocity+=applied_friction*diffv.normalize();
|
self.body.velocity+=applied_friction*diffv.normalize();
|
||||||
} else {
|
} else {
|
||||||
//EventEnum::WalkTargetReached
|
//PhysicsInstruction::WalkTargetReached
|
||||||
self.body.velocity=targetv;
|
self.body.velocity=targetv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,59 +213,59 @@ impl PhysicsState {
|
|||||||
self.body.position+self.body.velocity*(dt as f32)+self.gravity*((0.5*dt*dt) as f32)
|
self.body.position+self.body.velocity*(dt as f32)+self.gravity*((0.5*dt*dt) as f32)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_strafe_event(&self) -> Option<EventStruct<PhysicsEvent>> {
|
fn next_strafe_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||||
return Some(EventStruct{
|
return Some(TimedInstruction{
|
||||||
time:(self.time*self.strafe_tick_num/self.strafe_tick_den+1)*self.strafe_tick_den/self.strafe_tick_num,
|
time:(self.time*self.strafe_tick_num/self.strafe_tick_den+1)*self.strafe_tick_den/self.strafe_tick_num,
|
||||||
event:PhysicsEvent::StrafeTick
|
instruction:PhysicsInstruction::StrafeTick
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_walk_event(&self) -> Option<EventStruct<PhysicsEvent>> {
|
fn next_walk_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||||
//check if you are accelerating towards a walk target velocity and create an event
|
//check if you are accelerating towards a walk target velocity and create an instruction
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
fn predict_collision_end(&self,model:&Model) -> Option<EventStruct<PhysicsEvent>> {
|
fn predict_collision_end(&self,model:&Model) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn predict_collision_start(&self,model:&Model) -> Option<EventStruct<PhysicsEvent>> {
|
fn predict_collision_start(&self,model:&Model) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::event::EventEmitter<PhysicsEvent> for PhysicsState {
|
impl crate::instruction::InstructionEmitter<PhysicsInstruction> for PhysicsState {
|
||||||
//this little next event 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_event(&self) -> Option<EventStruct<PhysicsEvent>> {
|
fn next_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||||
//JUST POLLING!!! NO MUTATION
|
//JUST POLLING!!! NO MUTATION
|
||||||
let mut best = crate::event::EventCollector::new();
|
let mut best = crate::instruction::InstructionCollector::new();
|
||||||
//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 InputEvent::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
|
||||||
best.collect(Some(EventStruct{
|
best.collect(Some(TimedInstruction{
|
||||||
time:self.time,
|
time:self.time,
|
||||||
event:PhysicsEvent::Jump
|
instruction:PhysicsInstruction::Jump
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
//check for collision stop events with curent contacts
|
//check for collision stop instructions with curent contacts
|
||||||
for collision_data in self.contacts.iter() {
|
for collision_data in self.contacts.iter() {
|
||||||
best.collect(self.predict_collision_end(self.models_cringe_clone.get(collision_data.model as usize).unwrap()));
|
best.collect(self.predict_collision_end(self.models_cringe_clone.get(collision_data.model as usize).unwrap()));
|
||||||
}
|
}
|
||||||
//check for collision start events (against every part in the game with no optimization!!)
|
//check for collision start instructions (against every part in the game with no optimization!!)
|
||||||
for model in &self.models_cringe_clone {
|
for model in &self.models_cringe_clone {
|
||||||
best.collect(self.predict_collision_start(model));
|
best.collect(self.predict_collision_start(model));
|
||||||
}
|
}
|
||||||
if self.grounded {
|
if self.grounded {
|
||||||
//walk maintenance
|
//walk maintenance
|
||||||
best.collect(self.next_walk_event());
|
best.collect(self.next_walk_instruction());
|
||||||
}else{
|
}else{
|
||||||
//check to see when the next strafe tick is
|
//check to see when the next strafe tick is
|
||||||
best.collect(self.next_strafe_event());
|
best.collect(self.next_strafe_instruction());
|
||||||
}
|
}
|
||||||
best.event()
|
best.instruction()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::event::EventConsumer<PhysicsEvent> for PhysicsState {
|
impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsState {
|
||||||
fn process_event(&mut self, event:EventStruct<PhysicsEvent>) {
|
fn process_instruction(&mut self, instruction:TimedInstruction<PhysicsInstruction>) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
38
src/event.rs
38
src/event.rs
@ -1,37 +1,37 @@
|
|||||||
pub struct EventStruct<E> {
|
pub struct TimedInstruction<I> {
|
||||||
pub time: crate::body::TIME,
|
pub time: crate::body::TIME,
|
||||||
pub event: E,
|
pub instruction: I,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait EventEmitter<E> {
|
pub trait InstructionEmitter<I> {
|
||||||
fn next_event(&self) -> Option<EventStruct<E>>;
|
fn next_instruction(&self) -> Option<TimedInstruction<I>>;
|
||||||
}
|
}
|
||||||
pub trait EventConsumer<E> {
|
pub trait InstructionConsumer<I> {
|
||||||
fn process_event(&mut self, event:EventStruct<E>);
|
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//PROPER PRIVATE FIELDS!!!
|
//PROPER PRIVATE FIELDS!!!
|
||||||
pub struct EventCollector<E> {
|
pub struct InstructionCollector<I> {
|
||||||
event: Option<EventStruct<E>>,
|
instruction: Option<TimedInstruction<I>>,
|
||||||
}
|
}
|
||||||
impl<E> EventCollector<E> {
|
impl<I> InstructionCollector<I> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self{event:None}
|
Self{instruction:None}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect(&mut self,test_event:Option<EventStruct<E>>){
|
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
|
||||||
match &test_event {
|
match &instruction {
|
||||||
Some(unwrap_test_event) => match &self.event {
|
Some(unwrap_instruction) => match &self.instruction {
|
||||||
Some(unwrap_best_event) => if unwrap_test_event.time<unwrap_best_event.time {
|
Some(unwrap_best_instruction) => if unwrap_instruction.time<unwrap_best_instruction.time {
|
||||||
self.event=test_event;
|
self.instruction=instruction;
|
||||||
},
|
},
|
||||||
None => self.event=test_event,
|
None => self.instruction=instruction,
|
||||||
},
|
},
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn event(self) -> Option<EventStruct<E>> {
|
pub fn instruction(self) -> Option<TimedInstruction<I>> {
|
||||||
//STEAL EVENT AND DESTROY EVENTCOLLECTOR
|
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
|
||||||
return self.event
|
return self.instruction
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,3 @@
|
|||||||
pub mod framework;
|
pub mod framework;
|
||||||
pub mod body;
|
pub mod body;
|
||||||
pub mod event;
|
pub mod instruction;
|
||||||
|
Loading…
Reference in New Issue
Block a user