Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Update for Bevy v0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
billyb2 authored and smokku committed Jan 14, 2022
1 parent 291967e commit 33ef527
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_networking_turbulence"
version = "0.3.3"
edition = "2018"
edition = "2021"
authors = ["Tomasz Sterna <[email protected]>"]
description = "Networking plugin for Bevy engine running on naia-socket and turbulence libraries"
readme = "README.md"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
27 changes: 15 additions & 12 deletions examples/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,27 @@ 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,
}

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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -309,7 +312,6 @@ fn handle_messages_client(
mut commands: Commands,
mut net: ResMut<NetworkResource>,
mut server_ids: ResMut<ServerIds>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut balls: Query<(Entity, &mut Ball, &mut Transform)>,
) {
for (handle, connection) in net.connections.iter_mut() {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions examples/idle_timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion examples/message_coalescing.readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ fn flush_channels(mut net: ResMut<NetworkResource>) {
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.
you may benefit from manually flushing per tick.
5 changes: 3 additions & 2 deletions examples/message_coalescing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::{
app::{AppBuilder, Events, Plugin, CoreStage},
app::{App, Events, Plugin, CoreStage},
ecs::prelude::*,
tasks::{IoTaskPool, TaskPool, Task},
core::FixedTimestep,
Expand Down Expand Up @@ -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::<IoTaskPool>()
.expect("`IoTaskPool` resource not found.")
.0
Expand Down

0 comments on commit 33ef527

Please sign in to comment.