Skip to content
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

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Refactor `ServerEventQueue` to have an explicit interface.
- Hide extra functionality from `ServerEventQueue`.
- Moved server event reset system to new set `ClientSet::ResetEvents` in `PreUpdate`.

## [0.19.0] - 2024-01-07
Expand Down
14 changes: 4 additions & 10 deletions src/network_event/server_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ 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 let Some(event) = event_queue.try_pop(*replicon_tick) {
server_events.send(event);
}
}
Expand Down Expand Up @@ -291,7 +291,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.
Expand Down Expand Up @@ -346,21 +346,15 @@ 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`] is 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> {
pub fn try_pop(&mut self, replicon_tick: RepliconTick) -> Option<T> {
let (tick, _) = self.0.front()?;
if *tick > replicon_tick {
return None;
Expand Down