Skip to content

Commit

Permalink
Merge pull request #11 from aggyomfg/bevy015
Browse files Browse the repository at this point in the history
bevy015 upgrade
  • Loading branch information
aggyomfg authored Nov 30, 2024
2 parents dc3ba4c + a7cb5e1 commit 0b2b20d
Show file tree
Hide file tree
Showing 12 changed files with 439 additions and 157 deletions.
506 changes: 393 additions & 113 deletions Cargo.lock

Large diffs are not rendered by default.

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.12.0"
version = "0.13.0"
authors = [
"Sliman4 <[email protected]>",
"aggyomfg <[email protected]>"
Expand All @@ -25,7 +25,7 @@ features = [
]

[dependencies]
bevy = { version = "0.14", default-features = false }
bevy = { version = "0.15", default-features = false }
serde = { version = "1", features = ["derive"] }
byteorder = "1"
bincode = { version = "1", optional = true }
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_plugins(ClientPlugin::<Config>::connect("127.0.0.1:3000"))
.observe(connection_establish_system)
.observe(packet_receive_system)
.add_observer(connection_establish_system)
.add_observer(packet_receive_system)
.run()
}

Expand Down Expand Up @@ -119,8 +119,8 @@ fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_plugins(ServerPlugin::<Config>::bind("127.0.0.1:3000").unwrap())
.observe(new_connection_system)
.observe(packet_receive_system)
.add_observer(new_connection_system)
.add_observer(packet_receive_system)
.run()
}

Expand Down Expand Up @@ -165,4 +165,6 @@ Note: you should implement keep-alive and disconnection systems yourself, or loo
| `0.9` | `0.13` |
| `0.10` | `0.13` |
| `0.11` | `0.14` |
| `main` | `0.14` |
| `0.12` | `0.14` |
| `0.13` | `0.15` |
| `main` | `0.15` |
6 changes: 3 additions & 3 deletions examples/hello_world_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn main() {
let server = std::thread::spawn(move || {
App::new()
.add_plugins((MinimalPlugins, ServerPlugin::<Config>::bind(server_addr)))
.observe(server_new_connection_system)
.observe(server_packet_receive_system)
.add_observer(server_new_connection_system)
.add_observer(server_packet_receive_system)
.run();
});
println!("Waiting 1000ms to make sure the server side has started");
Expand All @@ -64,7 +64,7 @@ fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_plugins(ClientPlugin::<Config>::connect(server_addr))
.observe(client_packet_receive_system)
.add_observer(client_packet_receive_system)
.run();
});
server.join().unwrap();
Expand Down
8 changes: 4 additions & 4 deletions examples/hello_world_tcp_encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ fn main() {
let server = std::thread::spawn(move || {
App::new()
.add_plugins((MinimalPlugins, ServerPlugin::<Config>::bind(server_addr)))
.observe(server_new_connection_system)
.observe(server_packet_receive_system)
.add_observer(server_new_connection_system)
.add_observer(server_packet_receive_system)
.run();
});
println!("Waiting 1000ms to make sure the server side has started");
Expand All @@ -68,14 +68,14 @@ fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_plugins(ClientPlugin::<Config>::connect(server_addr))
.observe(client_packet_receive_system)
.add_observer(client_packet_receive_system)
.run();
});
let client2 = std::thread::spawn(move || {
App::new()
.add_plugins(MinimalPlugins)
.add_plugins(ClientPlugin::<Config>::connect(server_addr))
.observe(client2_packet_receive_system)
.add_observer(client2_packet_receive_system)
.run();
});
server.join().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions examples/hello_world_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn main() {
let server = std::thread::spawn(move || {
App::new()
.add_plugins((MinimalPlugins, ServerPlugin::<Config>::bind(server_addr)))
.observe(server_new_connection_system)
.observe(server_packet_receive_system)
.add_observer(server_new_connection_system)
.add_observer(server_packet_receive_system)
.run();
});
println!("Waiting 1000ms to make sure the server side has started");
Expand All @@ -64,7 +64,7 @@ fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_plugins(ClientPlugin::<Config>::connect(server_addr))
.observe(client_packet_receive_system)
.add_observer(client_packet_receive_system)
.run();
});
server.join().unwrap();
Expand Down
28 changes: 14 additions & 14 deletions examples/lobby_and_battle_servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ fn main() {
.add_plugins((LogPlugin::default(), MinimalPlugins))
// Lobby server
.add_plugins(ServerPlugin::<LobbyConfig>::bind(LOBBY_SERVER))
.observe(lobby_server_accept_new_connections)
.observe(lobby_server_packet_handler)
.add_observer(lobby_server_accept_new_connections)
.add_observer(lobby_server_packet_handler)
// Battle server
.add_plugins(ServerPlugin::<BattleConfig>::bind(BATTLE_SERVER))
.observe(battle_server_accept_new_connections)
.observe(battle_server_packet_handler)
.add_observer(battle_server_accept_new_connections)
.add_observer(battle_server_packet_handler)
// Keep-alive packets
.init_resource::<ClientKeepAliveTimeout>()
.init_resource::<ServerKeepAliveMap<LobbyConfig>>()
Expand All @@ -190,19 +190,19 @@ fn main() {
)
// Lobby client
.add_plugins(ClientPlugin::<LobbyConfig>::connect(LOBBY_SERVER))
.observe(lobby_client_connect_handler)
.observe(lobby_client_packet_handler)
.add_observer(lobby_client_connect_handler)
.add_observer(lobby_client_packet_handler)
// Battle client (doesn't connect immediately)
.add_plugins(ClientPlugin::<BattleConfig>::new())
.observe(battle_client_connect_handler)
.observe(battle_client_packet_handler)
.add_observer(battle_client_connect_handler)
.add_observer(battle_client_packet_handler)
// Reconnection handlers
.observe(lobby_client_reconnect_if_error)
.observe(battle_client_reconnect_if_error)
.observe(lobby_client_keepalive_handler)
.observe(battle_client_keepalive_handler)
.observe(lobby_server_keepalive_handler)
.observe(battle_server_keepalive_handler)
.add_observer(lobby_client_reconnect_if_error)
.add_observer(battle_client_reconnect_if_error)
.add_observer(lobby_client_keepalive_handler)
.add_observer(battle_client_keepalive_handler)
.add_observer(lobby_server_keepalive_handler)
.add_observer(battle_server_keepalive_handler)
.run();
}

Expand Down
6 changes: 3 additions & 3 deletions examples/multiple_connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ fn main() {
MinimalPlugins,
ServerPlugin::<Config>::bind("127.0.0.1:3000"),
))
.observe(server_new_connection_system)
.observe(server_packet_receive_system)
.add_observer(server_new_connection_system)
.add_observer(server_packet_receive_system)
.run();
});
println!("Waiting 1000ms to make sure the server has started");
Expand All @@ -74,7 +74,7 @@ fn main() {
ClientPlugin::<Config>::connect("127.0.0.1:3000"),
))
.insert_resource(ClientId(id))
.observe(client_packet_receive_system)
.add_observer(client_packet_receive_system)
.run();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn setup_system<Config: ClientConfig>(mut commands: Commands) {
commands.insert_resource(ConnectionReceiver::<Config>(conn_rx));
commands.insert_resource(DisconnectionReceiver::<Config>(disc_rx, PhantomData));
commands.insert_resource(PacketReceiver::<Config>(pack_rx));
commands.spawn(Observer::new(connection_request_system::<Config>));
commands.add_observer(connection_request_system::<Config>);

// Connection
let disc_tx2 = disc_tx.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<Config: ServerConfig> Plugin for ServerPlugin<Config> {
PostUpdate,
(remove_connections::<Config>.in_set(SystemSets::ServerRemoveConnections),),
)
.observe(connection_add_system::<Config>);
.add_observer(connection_add_system::<Config>);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ fn tcp_packets() {
app_server.insert_resource(ReceivedPackets::<Packet>::default());
app_server.insert_resource(ServerToClientPacketResource(server_to_client_packet));

app_server.observe(server_new_connection_system);
app_server.observe(server_packet_receive_system);
app_server.add_observer(server_new_connection_system);
app_server.add_observer(server_packet_receive_system);

let mut app_client = App::new();
app_client.add_plugins(ClientPlugin::<TcpConfig>::connect(server_addr));
app_client.insert_resource(ReceivedPackets::<Packet>::default());
app_client.insert_resource(ClientToServerPacketResource(client_to_server_packet));

app_client.observe(client_connection_establish_system);
app_client.observe(client_packet_receive_system);
app_client.add_observer(client_connection_establish_system);
app_client.add_observer(client_packet_receive_system);

app_server.update(); // bind
app_client.update(); // connect
Expand Down
8 changes: 4 additions & 4 deletions src/tests_mut_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ fn tcp_encrypted_packets() {
server_to_client_packet.clone(),
));

app_server.observe(server_new_connection_system);
app_server.observe(server_packet_receive_system);
app_server.add_observer(server_new_connection_system);
app_server.add_observer(server_packet_receive_system);

let mut app_client = App::new();
app_client.add_plugins(ClientPlugin::<TcpConfig>::connect(server_addr));
Expand All @@ -123,8 +123,8 @@ fn tcp_encrypted_packets() {
client_to_server_packet.clone(),
));

app_client.observe(client_connection_establish_system);
app_client.observe(client_packet_receive_system);
app_client.add_observer(client_connection_establish_system);
app_client.add_observer(client_packet_receive_system);

app_server.update(); // bind
app_client.update(); // connect
Expand Down

0 comments on commit 0b2b20d

Please sign in to comment.