Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 0.14.0-rc
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Jun 16, 2024
2 parents fe995bc + b3f1505 commit 76c3948
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 22 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.26.3] - 2024-06-09

### Added

- Logging for sending and receiving messages.

### Changed

- Do not send empty ack messages from client.

## [0.27.0-rc.1] - 2024-06-07

### Changed
Expand Down Expand Up @@ -516,6 +526,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Initial release after separation from [Project Harmonia](https://github.com/projectharmonia/project_harmonia).

[unreleased]: https://github.com/projectharmonia/bevy_replicon/compare/v0.27.0-rc.1...HEAD
[0.26.3]: https://github.com/projectharmonia/bevy_replicon/compare/v0.26.2...v0.26.3
[0.27.0-rc.1]: https://github.com/projectharmonia/bevy_replicon/compare/v0.26.2...v0.27.0-rc.1
[0.26.2]: https://github.com/projectharmonia/bevy_replicon/compare/v0.26.1...v0.26.2
[0.26.1]: https://github.com/projectharmonia/bevy_replicon/compare/v0.26.0...v0.26.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ See also [What kind of networking should X game use?](https://github.com/bevyeng

Check out the [quick start guide](https://docs.rs/bevy_replicon).

See also [examples](bevy_replicon_renet/examples) with [`bevy_replicon_renet`](bevy_replicon_renet) as a messaging backed.
See also [examples](bevy_replicon_renet/examples) with [`bevy_replicon_renet`](bevy_replicon_renet) as a messaging backend.

Have any questions? Feel free to ask in the dedicated [`bevy_replicon` channel](https://discord.com/channels/691052431525675048/1090432346907492443) in Bevy's Discord server.

Expand Down
7 changes: 3 additions & 4 deletions bevy_replicon_renet/examples/simple_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ impl SimpleBoxPlugin {
});

let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
let public_addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), port);
let socket = UdpSocket::bind(public_addr)?;
let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, port))?;
let server_config = ServerConfig {
current_time,
max_clients: 10,
protocol_id: PROTOCOL_ID,
authentication: ServerAuthentication::Unsecure,
public_addresses: vec![public_addr],
public_addresses: Default::default(),
};
let transport = NetcodeServerTransport::new(server_config, socket)?;

Expand Down Expand Up @@ -130,7 +129,7 @@ impl SimpleBoxPlugin {
let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
let client_id = current_time.as_millis() as u64;
let server_addr = SocketAddr::new(ip, port);
let socket = UdpSocket::bind((ip, 0))?;
let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0))?;
let authentication = ClientAuthentication::Unsecure {
client_id,
protocol_id: PROTOCOL_ID,
Expand Down
7 changes: 3 additions & 4 deletions bevy_replicon_renet/examples/tic_tac_toe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,13 @@ impl TicTacToePlugin {
});

let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
let public_addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), port);
let socket = UdpSocket::bind(public_addr)?;
let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, port))?;
let server_config = ServerConfig {
current_time,
max_clients: 1,
protocol_id: PROTOCOL_ID,
authentication: ServerAuthentication::Unsecure,
public_addresses: vec![public_addr],
public_addresses: Default::default(),
};
let transport = NetcodeServerTransport::new(server_config, socket)?;

Expand All @@ -290,7 +289,7 @@ impl TicTacToePlugin {
let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
let client_id = current_time.as_millis() as u64;
let server_addr = SocketAddr::new(ip, port);
let socket = UdpSocket::bind((ip, 0))?;
let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0))?;
let authentication = ClientAuthentication::Unsecure {
client_id,
protocol_id: PROTOCOL_ID,
Expand Down
12 changes: 7 additions & 5 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ fn apply_replication(
// (unless user requested history via marker).
let init_tick = *world.resource::<ServerInitTick>();
let acks_size = mem::size_of::<u16>() * client.received_count(ReplicationChannel::Update);
let mut acks = Vec::with_capacity(acks_size);
for message in client.receive(ReplicationChannel::Update) {
let update_index = read_update_message(params, buffered_updates, message)?;
bincode::serialize_into(&mut acks, &update_index)?;
if acks_size != 0 {
let mut acks = Vec::with_capacity(acks_size);
for message in client.receive(ReplicationChannel::Update) {
let update_index = read_update_message(params, buffered_updates, message)?;
bincode::serialize_into(&mut acks, &update_index)?;
}
client.send(ReplicationChannel::Init, acks);
}
client.send(ReplicationChannel::Init, acks);

apply_update_messages(world, params, buffered_updates, init_tick)
}
Expand Down
12 changes: 11 additions & 1 deletion src/client/replicon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ impl RepliconClient {
.get_mut(channel_id as usize)
.unwrap_or_else(|| panic!("client should have a receive channel with id {channel_id}"));

trace!(
"received {} message(s) from channel {channel_id}",
channel_messages.len()
);

channel_messages.drain(..)
}

Expand All @@ -73,7 +78,12 @@ impl RepliconClient {
return;
}

self.sent_messages.push((channel_id.into(), message.into()));
let channel_id: u8 = channel_id.into();
let message: Bytes = message.into();

trace!("sending {} bytes over channel {channel_id}", message.len());

self.sent_messages.push((channel_id, message));
}

/// Sets the client connection status.
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn send_events(mut dummy_events: EventWriter<DummyEvent>) {
dummy_events.send_default();
}
/// Receives event on server and single-player.
/// Receives events on server or single-player.
fn receive_events(mut dummy_events: EventReader<FromClient<DummyEvent>>) {
for FromClient { client_id, event } in dummy_events.read() {
info!("received event {event:?} from {client_id:?}");
Expand Down Expand Up @@ -338,7 +338,7 @@ from the send list):
# let mut app = App::new();
# app.add_plugins(RepliconPlugins);
app.add_server_event::<DummyEvent>(ChannelKind::Ordered)
.add_systems(Update, (send_events, receive_events.run_if(has_authority)));
.add_systems(Update, (send_events.run_if(has_authority), receive_events));
/// Sends an event from server or single-player.
fn send_events(mut dummy_events: EventWriter<ToClients<DummyEvent>>) {
Expand All @@ -348,7 +348,7 @@ fn send_events(mut dummy_events: EventWriter<ToClients<DummyEvent>>) {
});
}
/// Receives event on client and single-player.
/// Receives events on client or listen server.
fn receive_events(mut dummy_events: EventReader<DummyEvent>) {
for event in dummy_events.read() {
info!("received event {event:?} from server");
Expand Down
17 changes: 13 additions & 4 deletions src/server/replicon_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@ impl RepliconServer {
}

let channel_id = channel_id.into();
let receive_channel = self
let channel_messages = self
.received_messages
.get_mut(channel_id as usize)
.unwrap_or_else(|| panic!("server should have a receive channel with id {channel_id}"));

receive_channel.drain(..)
trace!(
"received {} message(s) from channel {channel_id}",
channel_messages.len()
);

channel_messages.drain(..)
}

/// Sends a message to a client over a channel.
Expand All @@ -76,8 +81,12 @@ impl RepliconServer {
return;
}

self.sent_messages
.push((client_id, channel_id.into(), message.into()));
let channel_id: u8 = channel_id.into();
let message: Bytes = message.into();

trace!("sending {} bytes over channel {channel_id}", message.len());

self.sent_messages.push((client_id, channel_id, message));
}

/// Marks the server as running or stopped.
Expand Down

0 comments on commit 76c3948

Please sign in to comment.