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 1 commit
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
27 changes: 9 additions & 18 deletions src/network_event/server_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The event will be queued until [`RepliconTick`] will be bigger or equal to the tick specified here.
/// 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> {
let (tick, _) = self.0.front()?;
if *tick > replicon_tick {
return None;
}
self.0.pop_front().map(|(_, event)| event)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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> {
Expand Down