-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hide extra functionality from ServerEventQueue
#164
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,7 +203,13 @@ fn queue_system<T: Event>( | |
mut server_events: EventWriter<T>, | ||
mut event_queue: ResMut<ServerEventQueue<T>>, | ||
) { | ||
while let Some(event) = event_queue.pop_next(*replicon_tick) { | ||
while event_queue | ||
.0 | ||
.front() | ||
.filter(|(&tick, _)| tick <= *replicon_tick) | ||
.is_some() | ||
{ | ||
let (_, event) = event_queue.0.pop_front().unwrap(); | ||
server_events.send(event); | ||
} | ||
} | ||
|
@@ -291,7 +297,7 @@ fn local_resending_system<T: Event>( | |
} | ||
|
||
fn reset_system<T: Event>(mut event_queue: ResMut<ServerEventQueue<T>>) { | ||
event_queue.clear(); | ||
event_queue.0.clear(); | ||
} | ||
|
||
/// Sends serialized `message` to clients. | ||
|
@@ -346,27 +352,12 @@ pub enum SendMode { | |
pub struct ServerEventQueue<T>(ListOrderedMultimap<RepliconTick, T>); | ||
|
||
impl<T> ServerEventQueue<T> { | ||
/// Clears the event queue. | ||
pub fn clear(&mut self) { | ||
self.0.clear(); | ||
} | ||
|
||
/// Inserts a new event. | ||
/// | ||
/// The event will be queued until [`Self::pop_next`] is called with a replicon tick >= the tick specified here, | ||
/// or until [`Self::clear`] is called. | ||
/// The event will be queued until [`RepliconTick`] will be bigger or equal to the tick specified here. | ||
pub fn insert(&mut self, tick: RepliconTick, event: T) { | ||
self.0.insert(tick, event); | ||
} | ||
|
||
/// Pops the next event that is at least as old as the specified replicon tick. | ||
pub fn pop_next(&mut self, replicon_tick: RepliconTick) -> Option<T> { | ||
let (tick, _) = self.0.front()?; | ||
if *tick > replicon_tick { | ||
return None; | ||
} | ||
self.0.pop_front().map(|(_, event)| event) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to keep this and just change the visibility, to isolate implementation details from other parts of the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, but I adjusted the name a little bit. |
||
} | ||
|
||
impl<T> Default for ServerEventQueue<T> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.