Skip to content

Commit

Permalink
upgrade to bevy 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
aggyomfg committed Feb 29, 2024
1 parent 114c990 commit 156e26d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/target
/Cargo.lock
/.idea
/.vscode
/.cargo/config
/.cargo/config.toml
/*.iml
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.cargo.features": ["serializer_bincode", "protocol_tcp", "protocol_udp", "client", "server"]
}
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_slinet"
version = "0.8.0"
version = "0.9.0"
authors = ["Sliman4 <[email protected]>"]
edition = "2021"
license = "Apache-2.0 OR MIT"
Expand All @@ -22,7 +22,7 @@ features = [
]

[dependencies]
bevy = { version = "0.12.*", default-features = false }
bevy = { version = "0.13", default-features = false }
serde = "1"
byteorder = "1"
bincode = { version = "1", optional = true }
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# bevy_slinet

A simple networking plugin for bevy.

[![docs.rs](https://img.shields.io/docsrs/bevy_slinet)](https://docs.rs/bevy_slinet)
[![Crates.io](https://img.shields.io/crates/v/bevy_slinet)](https://crates.io/crates/bevy_slinet)
[![Crates.io](https://img.shields.io/crates/l/bevy_slinet)](https://github.com/Sliman4/bevy_slinet/tree/main/LICENSE)

## Features

- You can choose TCP or UDP protocol. Adding your own protocols is as easy as implementing a few traits.
- Multiple clients/servers with different configs (specifies a protocol, packet types, serializer, etc.)
- De/serialization. You choose a serialization format, packet type (you probably want it to be `enum`), and receive events with deserialized packets.

> Note: Everything in bevy_slinet is feature-gated. Make sure to enable features you need (`client`, `server`, `protocol_tcp`, `protocol_udp`, `serializer_bincode`).
## Client example

```rust
use bevy::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -132,9 +135,11 @@ fn packet_receive_system(mut events: EventReader<PacketReceiveEvent<Config>>) {
Note: you should implement keep-alive and disconnection systems yourself, or look at [lobby_and_battle_servers example](examples/lobby_and_battle_servers.rs)

## More examples

[Here](https://github.com/Sliman4/bevy_slinet/tree/main/examples).

### Compatibility table

| Plugin Version | Bevy Version |
|----------------|--------------|
| `0.1` | `0.6` |
Expand All @@ -145,4 +150,5 @@ Note: you should implement keep-alive and disconnection systems yourself, or loo
| `0.6` | `0.10.1` |
| `0.7` | `0.11` |
| `0.8` | `0.12` |
| `main` | `0.12` |
| `0.9` | `0.13` |
| `main` | `0.13` |
10 changes: 5 additions & 5 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ fn packet_receive_system<Config: ClientConfig>(
mut event_writer: EventWriter<PacketReceiveEvent<Config>>,
) {
while let Ok((connection, packet)) = packets.0.try_recv() {
event_writer.send(PacketReceiveEvent { connection, packet })
let _id = event_writer.send(PacketReceiveEvent { connection, packet });
}
}

Expand All @@ -359,10 +359,10 @@ fn connection_establish_system<Config: ClientConfig>(
while let Ok((address, connection)) = new_connections.0.try_recv() {
commands.insert_resource(connection.clone());
connections.push(connection.clone());
event_writer.send(ConnectionEstablishEvent {
let _id = event_writer.send(ConnectionEstablishEvent {
address,
connection,
})
});
}
}

Expand All @@ -378,11 +378,11 @@ fn connection_remove_system<Config: ClientConfig>(
if let Some(connection) = connections.last() {
commands.insert_resource(connection.clone());
}
event_writer.send(DisconnectionEvent {
let _id = event_writer.send(DisconnectionEvent {
error,
address,
_marker: PhantomData,
})
});
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ fn accept_new_connections<Config: ServerConfig>(
mut event_writer: EventWriter<NewConnectionEvent<Config>>,
) {
while let Ok((address, connection)) = receiver.0.try_recv() {
event_writer.send(NewConnectionEvent {
let _id = event_writer.send(NewConnectionEvent {
connection,
address,
})
});
}
}

Expand All @@ -330,7 +330,7 @@ fn accept_new_packets<Config: ServerConfig>(
mut event_writer: EventWriter<PacketReceiveEvent<Config>>,
) {
while let Ok((connection, packet)) = receiver.0.try_recv() {
event_writer.send(PacketReceiveEvent { connection, packet })
let _id = event_writer.send(PacketReceiveEvent { connection, packet });
}
}

Expand Down

0 comments on commit 156e26d

Please sign in to comment.