Skip to content

Commit

Permalink
Upgrade to bevy 0.14 (#464)
Browse files Browse the repository at this point in the history
* fix for bevy 0.14

* only issue is missing deserialize for Entity

* add bevy_ecs to enable serde feature

* 2 tests failing

* fix states

* update leafwing in exampels

* upgrade examples, disable inspector

* taplo

* wip

* add custom serialization

* update rc3

* use observers

* Revert "use observers"

This reverts commit c1a2c41.

* remove sparse set

* add additional settings for input delay

* deduplicate prespawn hash logic

* rebuild ConnectionManager after protocol has been registered

* fix simple_box

* update example

* keep using the last received input when remote inputs are missing

* fix hierarchy replication from client->server, and fix replicating hierarchy with PrePredicted

* add controlled by tests

* handle ControlledBy removal

* put controlled by back in replicate

* fix

* fix tick wrap

* update sync doc

* handle missing inputs correctly on server

* write input messages every FixedUpdate (tick) instead of every frame

* clippy (#516)

* Use observers to handle client disconnect (#518)

* use triggers to handle client disconnect

* lint

* Use observers to react to TickEvent instead of EventReader (#519)

* use observers for TickEvent

* readd relation with ticke vent

* add ActionState and InputBuffer automatically on server-side (#524)

* Use observers for replication (#521)

* wip

* wip

* add observers for server replication, remove replicate cache

* complete server replication commands test

* use observers for interpolation (#526)

* remove more RemovedComponents (#527)

* update to bevy 0.14

* upgrade

* simplify config

* upgrade xpbd to avian

* fix examples

* Cb/0.16 debug (#529)

* fix

* wip

* update run conditions and add run condition for leafwing PrepareMessage

* upgrade

* remove error logs

* 0.16
  • Loading branch information
cBournhonesque authored Jul 8, 2024
1 parent e53e5a9 commit 61809eb
Show file tree
Hide file tree
Showing 141 changed files with 3,479 additions and 2,559 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: cargo clippy -p lightyear --no-deps --tests -- -D warnings -A clippy::module_inception -A clippy::wrong_self_convention -A clippy::assign-op-pattern

- name: Rustdoc
run: cargo rustdoc -p lightyear --features=metrics,webtransport,leafwing,xpbd_2d,websocket,steam,zstd,bevy_xpbd_2d/2d,bevy_xpbd_2d/f32 -- --document-private-items -D warnings --cfg docsrc
run: cargo rustdoc -p lightyear --features=metrics,webtransport,leafwing,avian2d,websocket,steam,zstd,avian2d/2d,avian2d/f32,avian2d/parry-f32 -- --document-private-items -D warnings --cfg docsrc

doctest:
name: Doctest
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ app.add_channel::<Channel1>(ChannelSettings {

## Supported bevy version

| Lightyear | Bevy |
|-----------|------|
| 0.10-0.15 | 0.13 |
| 0.1-0.9 | 0.12 |
| Lightyear | Bevy |
|------------|------|
| 0.16 | 0.14 |
| 0.10-0.15 | 0.13 |
| 0.1-0.9 | 0.12 |
6 changes: 5 additions & 1 deletion benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ pprof = { version = "0.13.0", features = ["flamegraph", "frame-pointer"] }
lightyear = { path = "../lightyear" }
criterion = { version = "0.5", features = ["html_reports"] }
crossbeam-channel = "0.5.10"
bevy = { version = "0.13", features = ["bevy_core_pipeline"] }
bevy = { version = "0.14", default-features = true, features = [
"bevy_core_pipeline",
"multi_threaded",
"bevy_state",
] }
divan = "0.1.14"
serde = { version = "1.0.188", features = ["derive"] }

Expand Down
4 changes: 2 additions & 2 deletions benches/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn send_receive_simple_messages_to_one_client(criterion: &mut Criterion) {
for _ in 0..*n {
let _ = stepper
.server_app
.world
.world()
.resource_mut::<server::ConnectionManager>()
.send_message::<Channel1, _>(client_id, &Message2(1))
.inspect_err(|e| error!("error: {e:?}"));
Expand All @@ -52,7 +52,7 @@ fn send_receive_simple_messages_to_one_client(criterion: &mut Criterion) {
// .client_apps
// .get_mut(&client_id)
// .unwrap()
// .world
// .world_mut()
// .resource_mut::<Events<client::MessageEvent<Message2>>>()
// .drain()
// .map(|e| e.message)
Expand Down
18 changes: 8 additions & 10 deletions benches/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ fn send_float_insert_one_client(criterion: &mut Criterion) {
elapsed += instant.elapsed();
// dbg!(stepper
// .server_app
// .world
// .resource::<ConnectionManager>()
// .world() // .resource::<ConnectionManager>()
// .connection(ClientId::Netcode(0))
// .unwrap()
// .message_manager
Expand All @@ -90,8 +89,7 @@ fn send_float_insert_one_client(criterion: &mut Criterion) {
// .client_apps
// .get(&ClientId::Netcode(0))
// .unwrap()
// .world
// .entities()
// .world() // .entities()
// .len(),
// *n as u32
// );
Expand Down Expand Up @@ -125,7 +123,7 @@ fn send_float_update_one_client(criterion: &mut Criterion) {
// update the entities
for mut component in stepper
.server_app
.world
.world()
.query_filtered::<&mut Component1, With<Replicating>>()
.iter_mut(&mut stepper.server_app.world)
{
Expand All @@ -146,7 +144,7 @@ fn send_float_update_one_client(criterion: &mut Criterion) {
.client_apps
.get(&ClientId::Netcode(0))
.unwrap()
.world
.world()
.entities()
.len(),
*n as u32
Expand Down Expand Up @@ -201,7 +199,7 @@ fn receive_float_insert(criterion: &mut Criterion) {
.client_apps
.get(&ClientId::Netcode(0))
.unwrap()
.world
.world()
.entities()
.len(),
*n as u32
Expand Down Expand Up @@ -236,7 +234,7 @@ fn receive_float_update(criterion: &mut Criterion) {
// update the entities
for mut component in stepper
.server_app
.world
.world()
.query_filtered::<&mut Component1, With<Replicating>>()
.iter_mut(&mut stepper.server_app.world)
{
Expand All @@ -256,7 +254,7 @@ fn receive_float_update(criterion: &mut Criterion) {
.client_apps
.get(&ClientId::Netcode(0))
.unwrap()
.world
.world()
.entities()
.len(),
*n as u32
Expand Down Expand Up @@ -306,7 +304,7 @@ fn send_float_insert_n_clients(criterion: &mut Criterion) {
.client_apps
.get(&ClientId::Netcode(i as u64))
.unwrap()
.world
.world()
.entities()
.len(),
FIXED_NUM_ENTITIES as u32
Expand Down
27 changes: 16 additions & 11 deletions benches/src/local_stepper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use bevy::prelude::{
default, App, Commands, Mut, Plugin, PluginGroup, Real, Resource, TaskPoolOptions,
TaskPoolPlugin, Time,
};
use bevy::state::app::StatesPlugin;
use bevy::tasks::available_parallelism;
use bevy::time::TimeUpdateStrategy;
use bevy::utils::HashMap;
Expand Down Expand Up @@ -118,6 +119,7 @@ impl LocalBevyStepper {
let mut client_app = App::new();
client_app.add_plugins((
MinimalPlugins,
StatesPlugin,
#[cfg(feature = "bevy/trace_tracy")]
LogPlugin::default(),
));
Expand All @@ -142,7 +144,7 @@ impl LocalBevyStepper {
client_app.add_plugins((ClientPlugins::new(config), ProtocolPlugin));
// Initialize Real time (needed only for the first TimeSystem run)
client_app
.world
.world_mut()
.get_resource_mut::<Time<Real>>()
.unwrap()
.update_with_instant(now);
Expand All @@ -157,6 +159,7 @@ impl LocalBevyStepper {
let mut server_app = App::new();
server_app.add_plugins((
MinimalPlugins,
StatesPlugin,
#[cfg(feature = "bevy/trace_tracy")]
LogPlugin::default(),
));
Expand All @@ -174,7 +177,7 @@ impl LocalBevyStepper {

// Initialize Real time (needed only for the first TimeSystem run)
server_app
.world
.world_mut()
.get_resource_mut::<Time<Real>>()
.unwrap()
.update_with_instant(now);
Expand Down Expand Up @@ -210,37 +213,39 @@ impl LocalBevyStepper {
self.client_apps
.get(&client_id)
.unwrap()
.world
.world()
.resource::<R>()
}

pub fn client_resource_mut<R: Resource>(&mut self, client_id: ClientId) -> Mut<R> {
self.client_apps
.get_mut(&client_id)
.unwrap()
.world
.world_mut()
.resource_mut::<R>()
}

pub fn init(&mut self) {
self.server_app.finish();
self.server_app.cleanup();
self.server_app
.world
.world_mut()
.run_system_once(|mut commands: Commands| commands.start_server());
self.client_apps.values_mut().for_each(|client_app| {
client_app.finish();
client_app.cleanup();
let _ = client_app
.world
.world_mut()
.run_system_once(|mut commands: Commands| commands.connect_client());
});

// Advance the world to let the connection process complete
for _ in 0..100 {
if self
.client_apps
.values()
.all(|c| c.world.resource::<client::ConnectionManager>().is_synced())
{
if self.client_apps.values().all(|c| {
c.world()
.resource::<client::ConnectionManager>()
.is_synced()
}) {
return;
}
self.frame_step();
Expand Down
4 changes: 2 additions & 2 deletions benches/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pub(crate) struct ProtocolPlugin;
impl Plugin for ProtocolPlugin {
fn build(&self, app: &mut App) {
// messages
app.add_message::<Message1>(ChannelDirection::Bidirectional);
app.add_message::<Message2>(ChannelDirection::Bidirectional);
app.register_message::<Message1>(ChannelDirection::Bidirectional);
app.register_message::<Message2>(ChannelDirection::Bidirectional);
// inputs
app.add_plugins(InputPlugin::<MyInput>::default());
// components
Expand Down
13 changes: 8 additions & 5 deletions examples/auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ serde = { version = "1.0.188", features = ["derive"] }
anyhow = { version = "1.0.75", features = [] }
tracing = "0.1"
tracing-subscriber = "0.3.17"
bevy = { version = "0.13", features = ["bevy_core_pipeline"] }
bevy_mod_picking = { version = "0.19.1", features = ["backend_bevy_ui"] }
derive_more = { version = "0.99", features = ["add", "mul"] }
bevy = { version = "0.14", features = [
"multi_threaded",
"bevy_state",
"serialize",
] }
bevy_mod_picking = { version = "0.20", features = ["backend_bevy_ui"] }
rand = "0.8.1"
metrics-exporter-prometheus = { version = "0.13.0", optional = true }
bevy-inspector-egui = "0.24"
metrics-exporter-prometheus = { version = "0.15.1", optional = true }
bevy-inspector-egui = "0.25"
tokio = "1.37.0"
4 changes: 2 additions & 2 deletions examples/auth/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub(crate) fn spawn_connect_button(mut commands: Commands) {
..default()
},
border_color: BorderColor(Color::BLACK),
background_color: Color::rgb(0.15, 0.15, 0.15).into(),
background_color: Color::srgb(0.15, 0.15, 0.15).into(),
..default()
},
On::<Pointer<Click>>::run(|| {}),
Expand All @@ -171,7 +171,7 @@ pub(crate) fn spawn_connect_button(mut commands: Commands) {
"Connect",
TextStyle {
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
color: Color::srgb(0.9, 0.9, 0.9),
..default()
},
),
Expand Down
1 change: 0 additions & 1 deletion examples/auth/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use bevy::prelude::{
default, Bundle, Color, Component, Deref, DerefMut, Entity, EntityMapper, Vec2,
};
use bevy::prelude::{App, Plugin};
use derive_more::Add;
use serde::{Deserialize, Serialize};

use lightyear::client::components::ComponentSyncMode;
Expand Down
33 changes: 19 additions & 14 deletions examples/auth/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ impl Plugin for ExampleServerPlugin {
let client_ids = Arc::new(RwLock::new(HashSet::default()));
app.add_systems(Startup, (init, start_server));

app.observe(handle_disconnect_event);
app.observe(handle_connect_event);

start_netcode_authentication_task(
self.game_server_addr,
self.auth_backend_addr,
Expand Down Expand Up @@ -75,21 +78,23 @@ fn init(mut commands: Commands) {
#[derive(Resource)]
struct ClientIds(Arc<RwLock<HashSet<u64>>>);

/// Update the list of connected client ids when a client connects or disconnects
fn handle_connect_events(
client_ids: Res<ClientIds>,
mut connect_events: EventReader<ConnectEvent>,
mut disconnect_events: EventReader<DisconnectEvent>,
) {
for event in connect_events.read() {
if let Netcode(client_id) = event.client_id {
client_ids.0.write().unwrap().insert(client_id);
}
/// Update the list of connected client ids when a client disconnects
///
/// We use an Observer to handle disconnect events to avoid the perf cost of running
/// the system every frame. We want to run the system only when we have a disconnection.
fn handle_disconnect_event(trigger: Trigger<DisconnectEvent>, client_ids: Res<ClientIds>) {
if let Netcode(client_id) = trigger.event().client_id {
client_ids.0.write().unwrap().remove(&client_id);
}
for event in disconnect_events.read() {
if let Netcode(client_id) = event.client_id {
client_ids.0.write().unwrap().remove(&client_id);
}
}

/// Update the list of connected client ids when a client connects
///
/// We use an Observer to handle disconnect events to avoid the perf cost of running
/// the system every frame. We want to run the system only when we have a connection.
fn handle_connect_event(trigger: Trigger<ConnectEvent>, client_ids: Res<ClientIds>) {
if let Netcode(client_id) = trigger.event().client_id {
client_ids.0.write().unwrap().insert(client_id);
}
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "leafwing_inputs"
name = "avian_physics"
version = "0.0.0"
authors = ["Charles Bournhonesque <[email protected]>"]
edition = "2021"
Expand All @@ -11,21 +11,25 @@ metrics = ["lightyear/metrics", "dep:metrics-exporter-prometheus"]

[dependencies]
lightyear_examples_common = { path = "../common" }
bevy_screen_diagnostics = "0.5.0"
leafwing-input-manager = "0.13"
bevy_xpbd_2d = { version = "0.4", features = ["serialize"] }
bevy_screen_diagnostics = "0.6"
leafwing-input-manager = "0.14"
avian2d = { version = "0.1", features = ["serialize"] }
lightyear = { path = "../../lightyear", features = [
"webtransport",
"websocket",
"leafwing",
"xpbd_2d",
"avian2d",
"steam",
] }
serde = { version = "1.0.188", features = ["derive"] }
anyhow = { version = "1.0.75", features = [] }
tracing = "0.1"
tracing-subscriber = "0.3.17"
bevy = { version = "0.13", features = ["bevy_core_pipeline"] }
derive_more = { version = "0.99", features = ["add", "mul"] }
bevy = { version = "0.14", features = [
"multi_threaded",
"bevy_state",
"serialize",
] }

rand = "0.8.1"
metrics-exporter-prometheus = { version = "0.13.0", optional = true }
metrics-exporter-prometheus = { version = "0.15.1", optional = true }
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 61809eb

Please sign in to comment.