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

Update NetworkChannels API #167

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Refactor `ServerEventQueue` to have an explicit interface.
- Moved server event reset system to new set `ClientSet::ResetEvents` in `PreUpdate`.
- Make `NetworkChannels` channel-creation methods public (`create_client_channel()` and `create_server_channel()`).

## [0.19.0] - 2024-01-07

Expand Down
20 changes: 11 additions & 9 deletions src/replicon_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ impl From<ReplicationChannel> for u8 {
}
}

/// A resource to configure and setup channels for [`ConnectionConfig`](bevy_renet::renet::ConnectionConfig)
/// A resource to configure and setup channels for [`ConnectionConfig`](bevy_renet::renet::ConnectionConfig).
#[derive(Clone, Resource)]
pub struct NetworkChannels {
/// Stores delivery guarantee and maximum usage bytes (if set) for each server channel.
/// Stores the delivery guarantee and maximum usage bytes (if set) for each server channel.
server: Vec<(SendType, Option<usize>)>,

/// Same as [`Self::server`], but for client.
client: Vec<(SendType, Option<usize>)>,

/// Stores default max memory usage bytes for all channels.
/// Stores the default max memory usage bytes for all channels.
///
/// This value will be used instead of `None`.
default_max_bytes: usize,
}

/// Stores only replication channel by default.
/// Only stores the replication channel by default.
impl Default for NetworkChannels {
fn default() -> Self {
let replication_channels = vec![
Expand Down Expand Up @@ -85,7 +85,7 @@ impl NetworkChannels {
self.get_configs(&self.client)
}

/// Sets maximum usage bytes for specific client channel.
/// Sets the maximum usage bytes for a specific server channel.
///
/// [`ReplicationChannel`] or [`ServerEventChannel<T>`](crate::network_event::ServerEventChannel) can be passed as `id`.
/// Without calling this function, the default value will be used.
Expand All @@ -100,7 +100,7 @@ impl NetworkChannels {
*bytes = Some(max_bytes);
}

/// Same as [`Self::set_server_max_bytes`], but for client.
/// Same as [`Self::set_server_max_bytes`], but for a client channel.
pub fn set_client_max_bytes(&mut self, id: impl Into<u8>, max_bytes: usize) {
let id = id.into();
let (_, bytes) = self
Expand All @@ -111,12 +111,13 @@ impl NetworkChannels {
*bytes = Some(max_bytes);
}

/// Sets maximum usage bytes that will be used by default for all channels if not set.
/// Sets the maximum usage bytes that will be used by default for all channels if not set.
pub fn set_default_max_bytes(&mut self, max_bytes: usize) {
self.default_max_bytes = max_bytes;
}

pub(super) fn create_client_channel(&mut self, send_type: SendType) -> u8 {
/// Creates a new client channel with the specified send type.
pub fn create_client_channel(&mut self, send_type: SendType) -> u8 {
if self.client.len() == u8::MAX as usize {
panic!("number of client channels shouldn't exceed u8::MAX");
}
Expand All @@ -125,7 +126,8 @@ impl NetworkChannels {
self.client.len() as u8 - 1
}

pub(super) fn create_server_channel(&mut self, send_type: SendType) -> u8 {
/// Creates a new server channel with the specified send type.
pub fn create_server_channel(&mut self, send_type: SendType) -> u8 {
if self.server.len() == u8::MAX as usize {
panic!("number of server channels shouldn't exceed u8::MAX");
}
Expand Down