strafe-client/src/event.rs

34 lines
752 B
Rust
Raw Normal View History

2023-09-09 00:00:50 +00:00
pub struct EventStruct<E> {
2023-09-08 18:33:20 +00:00
pub time: crate::body::TIME,
2023-09-09 00:00:50 +00:00
pub event: E,
2023-09-08 18:33:20 +00:00
}
2023-09-09 00:00:50 +00:00
pub trait EventEmitter<E> {
fn next_event(&self) -> Option<EventStruct<E>>;
2023-09-08 19:48:11 +00:00
}
//PROPER PRIVATE FIELDS!!!
2023-09-09 00:00:50 +00:00
pub struct EventCollector<E> {
event: Option<EventStruct<E>>,
2023-09-08 19:48:11 +00:00
}
2023-09-09 00:00:50 +00:00
impl<E> EventCollector<E> {
2023-09-08 19:48:11 +00:00
pub fn new() -> Self {
Self{event:None}
}
2023-09-09 00:00:50 +00:00
pub fn collect(&mut self,test_event:Option<EventStruct<E>>){
2023-09-08 19:48:11 +00:00
match &test_event {
Some(unwrap_test_event) => match &self.event {
Some(unwrap_best_event) => if unwrap_test_event.time<unwrap_best_event.time {
self.event=test_event;
},
None => self.event=test_event,
},
None => (),
}
}
2023-09-09 00:00:50 +00:00
pub fn event(self) -> Option<EventStruct<E>> {
2023-09-08 19:48:11 +00:00
//STEAL EVENT AND DESTROY EVENTCOLLECTOR
return self.event
}
2023-09-08 18:33:20 +00:00
}