From 33ef527b2ba7106491749eacfabb4caa2882b41a Mon Sep 17 00:00:00 2001 From: William Batista Date: Wed, 28 Jul 2021 21:24:50 -0400 Subject: [PATCH] Update for Bevy v0.6 --- Cargo.toml | 16 ++++++++-------- examples/channels.rs | 27 +++++++++++++++------------ examples/idle_timeout.rs | 5 +++-- examples/message_coalescing.readme.md | 2 +- examples/message_coalescing.rs | 5 +++-- examples/simple.rs | 5 +++-- src/lib.rs | 6 +++--- 7 files changed, 36 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 58972f5..42fad9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_networking_turbulence" version = "0.3.3" -edition = "2018" +edition = "2021" authors = ["Tomasz Sterna "] description = "Networking plugin for Bevy engine running on naia-socket and turbulence libraries" readme = "README.md" @@ -27,12 +27,12 @@ use-webrtc = [ ] [dependencies] -bevy = {version = "0.5", default-features = false} +bevy = { version = "0.6", default-features = false} turbulence = "0.3" naia-client-socket = { version = "0.6", features = ["multithread"] } -bytes = "1.0" +bytes = "1.1" log = "0.4" -futures-lite = "1.11" +futures-lite = "1.12" crossbeam-channel = "0.5" cfg-if = "1.0" instant = "0.1" @@ -43,14 +43,14 @@ futures-timer = "3.0" naia-server-socket = "0.5" [dev-dependencies] -clap = "2.33.3" -bevy = { version = "0.5", default-features = false } +clap = "2.34.0" +bevy = { version = "0.6", default-features = false } serde = { version = "1.0", features = ["derive"] } simple_logger = "1" -rand = { version = "0.7.3", features = ["wasm-bindgen"] } +rand = { version = "0.8" } console_error_panic_hook = "0.1" console_log = "0.2" -wasm-bindgen = "=0.2.69" # pin to Bevy's dependency +wasm-bindgen = "=0.2.78" # pin to Bevy's dependency [[example]] name = "channels" diff --git a/examples/channels.rs b/examples/channels.rs index 771fed9..5a0548f 100644 --- a/examples/channels.rs +++ b/examples/channels.rs @@ -26,16 +26,19 @@ const BOARD_WIDTH: u32 = 1000; const BOARD_HEIGHT: u32 = 1000; fn main() { - simple_logger::SimpleLogger::from_env() + simple_logger::SimpleLogger::new() + .env() .init() .expect("A logger was already initialized"); - App::build().add_plugin(BallsExample).run(); + App::new().add_plugin(BallsExample).run(); } +#[derive(Component)] struct Pawn { controller: u32, } +#[derive(Component)] struct Ball { velocity: Vec3, } @@ -43,7 +46,7 @@ struct Ball { struct BallsExample; impl Plugin for BallsExample { - fn build(&self, app: &mut AppBuilder) { + fn build(&self, app: &mut App) { let args = parse_simple_args(); if args.is_server { // Server @@ -227,10 +230,10 @@ fn handle_packets( // New client connected - spawn a ball let mut rng = rand::thread_rng(); - let vel_x = rng.gen_range(-0.5, 0.5); - let vel_y = rng.gen_range(-0.5, 0.5); - let pos_x = rng.gen_range(0, BOARD_WIDTH) as f32; - let pos_y = rng.gen_range(0, BOARD_HEIGHT) as f32; + let vel_x = rng.gen_range(-0.5..0.5); + let vel_y = rng.gen_range(-0.5..0.5); + let pos_x = rng.gen_range(0..BOARD_WIDTH) as f32; + let pos_y = rng.gen_range(0..BOARD_HEIGHT) as f32; log::info!("Spawning {}x{} {}/{}", pos_x, pos_y, vel_x, vel_y); commands.spawn_bundle(( Ball { @@ -309,7 +312,6 @@ fn handle_messages_client( mut commands: Commands, mut net: ResMut, mut server_ids: ResMut, - mut materials: ResMut>, mut balls: Query<(Entity, &mut Ball, &mut Transform)>, ) { for (handle, connection) in net.connections.iter_mut() { @@ -367,11 +369,12 @@ fn handle_messages_client( log::info!("Spawning {} @{}", id, frame); let entity = commands .spawn_bundle(SpriteBundle { - material: materials.add( - Color::rgb(0.8 - (*id as f32 / 5.0), 0.2, 0.2 + (*id as f32 / 5.0)).into(), - ), transform: Transform::from_translation(*translation), - sprite: Sprite::new(Vec2::new(30.0, 30.0)), + sprite: Sprite { + color:Color::rgb(0.8 - (*id as f32 / 5.0), 0.2, 0.2 + (*id as f32 / 5.0)), + custom_size: Some(Vec2::new(30.0, 30.0)), + ..Default::default() + }, ..Default::default() }) .insert(Ball { diff --git a/examples/idle_timeout.rs b/examples/idle_timeout.rs index 4581fc5..da6c6c4 100644 --- a/examples/idle_timeout.rs +++ b/examples/idle_timeout.rs @@ -27,7 +27,8 @@ fn main() { console_log::init_with_level(log::Level::Debug).expect("cannot initialize console_log"); } else { - simple_logger::SimpleLogger::from_env() + simple_logger::SimpleLogger::new() + .env() .init() .expect("A logger was already initialized"); } @@ -44,7 +45,7 @@ fn main() { pong_reservoir: args.pongs, }; - let mut app = App::build(); + let mut app = App::new(); app // minimal plugins necessary for timers + headless loop .insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64( diff --git a/examples/message_coalescing.readme.md b/examples/message_coalescing.readme.md index 0c27b48..a9721bb 100644 --- a/examples/message_coalescing.readme.md +++ b/examples/message_coalescing.readme.md @@ -76,4 +76,4 @@ fn flush_channels(mut net: ResMut) { Note how when manually flushing per tick the client only sends 10 packets - one per tick. In a game server where you might have a few different systems enqueueing messages to be sent to clients, -you may benefit from manually flushing per tick. \ No newline at end of file +you may benefit from manually flushing per tick. diff --git a/examples/message_coalescing.rs b/examples/message_coalescing.rs index eaf200c..d9e5c32 100644 --- a/examples/message_coalescing.rs +++ b/examples/message_coalescing.rs @@ -39,7 +39,8 @@ fn main() { console_log::init_with_level(log::Level::Debug).expect("cannot initialize console_log"); } else { - simple_logger::SimpleLogger::from_env() + simple_logger::SimpleLogger::new() + .env() .init() .expect("A logger was already initialized"); } @@ -51,7 +52,7 @@ fn main() { net_plugin.message_flushing_strategy = MessageFlushingStrategy::Never; } - let mut app = App::build(); + let mut app = App::new(); app // minimal plugins necessary for timers + headless loop .insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64( diff --git a/examples/simple.rs b/examples/simple.rs index d1acc43..ba5d598 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -20,13 +20,14 @@ fn main() { console_log::init_with_level(log::Level::Debug).expect("cannot initialize console_log"); } else { - simple_logger::SimpleLogger::from_env() + simple_logger::SimpleLogger::new() + .env() .init() .expect("A logger was already initialized"); } } - App::build() + App::new() // minimal plugins necessary for timers + headless loop .insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64( 1.0 / 60.0, diff --git a/src/lib.rs b/src/lib.rs index 697d5bb..f1d9f76 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ use bevy::{ - app::{AppBuilder, Events, Plugin, CoreStage}, + app::{App, Events, Plugin, CoreStage}, ecs::prelude::*, tasks::{IoTaskPool, TaskPool, Task}, core::FixedTimestep, @@ -69,9 +69,9 @@ pub struct NetworkingPlugin { } impl Plugin for NetworkingPlugin { - fn build(&self, app: &mut AppBuilder) { + fn build(&self, app: &mut App) { let task_pool = app - .world() + .world .get_resource::() .expect("`IoTaskPool` resource not found.") .0