Skip to content

Commit

Permalink
upgrade to bevy 0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaeleragni committed Jul 9, 2024
1 parent e374b00 commit 38bd511
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 126 deletions.
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ include = ["/src", "/LICENSE-MIT", "/LICENSE-APACHE"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.13" }
wgpu-types = { version = "0.19", features = ["serde", "replay", "trace"] }
bevy_renet = "0.0.11"
bevy = { version = "0.14" }
wgpu-types = { version = "0.20", features = ["serde"] }
bevy_renet = { git = "https://github.com/raffaeleragni/renet" }
#bevy_renet = "0.0.12"
bincode = "1.3"
serde = { version = "1.0", features = ["derive"] }
uuid = "1.8"
uuid = "1.10"

threadpool = "1.8"
tiny_http = { version = "0", default-features = false }
ureq = { version = "2.9", default-features = false }
ureq = { version = "2.10", default-features = false }
portpicker = "0.1"
ascii = "1.1"
lz4-compress = "0.1"

[dev-dependencies]
serial_test = "3.0"
serial_test = "3.1"
bevy_editor_pls = "0.8"
9 changes: 4 additions & 5 deletions src/binreflect.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use bevy::reflect::{
serde::{ReflectSerializer, UntypedReflectDeserializer},
serde::{ReflectDeserializer, ReflectSerializer},
DynamicStruct, Reflect, ReflectFromReflect, TypeRegistry,
};

use bincode::{DefaultOptions, ErrorKind, Options};
use serde::de::DeserializeSeed;

Expand All @@ -18,7 +17,7 @@ pub(crate) fn reflect_to_bin(
}

pub(crate) fn bin_to_reflect(data: &[u8], registry: &TypeRegistry) -> Box<dyn Reflect> {
let reflect_deserializer = UntypedReflectDeserializer::new(registry);
let reflect_deserializer = ReflectDeserializer::new(registry);
let binoptions = DefaultOptions::new()
.with_fixint_encoding()
.allow_trailing_bytes();
Expand Down Expand Up @@ -98,7 +97,7 @@ mod test {
#[test]
fn material_serde() {
let material_orig = StandardMaterial {
base_color: Color::RED,
base_color: Color::srgb(1.0, 0.0, 0.0),
..StandardMaterial::default()
};

Expand All @@ -124,7 +123,7 @@ mod test {
#[test]
fn reflect_material_no_dependencies() {
let compo = StandardMaterial {
base_color: Color::RED,
base_color: Color::srgb(1.0, 0.0, 0.0),
..StandardMaterial::default()
};

Expand Down
10 changes: 5 additions & 5 deletions src/lib_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ impl SyncComponent for App {
) -> &mut Self {
self.register_type::<T>();
self.register_type_data::<T, ReflectFromReflect>();
let c_id = self.world.init_component::<T>();
let c_exclude_id = self.world.init_component::<SyncExclude<T>>();
let mut track = self.world.resource_mut::<SyncTrackerRes>();
let c_id = self.world_mut().init_component::<T>();
let c_exclude_id = self.world_mut().init_component::<SyncExclude<T>>();
let mut track = self.world_mut().resource_mut::<SyncTrackerRes>();
track.registered_componets_for_sync.insert(c_id);
track
.sync_exclude_cid_of_component_cid
Expand All @@ -209,12 +209,12 @@ impl SyncComponent for App {
}

fn sync_materials(&mut self, enable: bool) {
let mut tracker = self.world.resource_mut::<SyncTrackerRes>();
let mut tracker = self.world_mut().resource_mut::<SyncTrackerRes>();
tracker.sync_materials = enable;
}

fn sync_meshes(&mut self, enable: bool) {
let mut tracker = self.world.resource_mut::<SyncTrackerRes>();
let mut tracker = self.world_mut().resource_mut::<SyncTrackerRes>();
tracker.sync_meshes = enable;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/networking/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use crate::{
lib_priv::SyncTrackerRes, networking::assets::image_serde::image_to_bin, proto::SyncAssetType,
};
use ascii::AsciiString;
use bevy::utils::Uuid;
use bevy::{prelude::*, utils::HashMap};
use mesh_serde::{bin_to_mesh, mesh_to_bin};
use std::io::Read;
use threadpool::ThreadPool;
use tiny_http::{Header, Request, Response, Server};
use uuid::Uuid;

use self::image_serde::bin_to_image;

Expand Down
3 changes: 2 additions & 1 deletion src/proto.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::net::IpAddr;

use bevy::{ecs::event::Event, utils::Uuid};
use bevy::ecs::event::Event;
use bevy_renet::renet::ClientId;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

pub type EntityId = Uuid;
pub type AssId = Uuid;
Expand Down
2 changes: 1 addition & 1 deletion src/server/initial_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::{
binreflect::reflect_to_bin, lib_priv::SyncTrackerRes, networking::assets::SyncAssetTransfer,
proto::Message, SyncEntity,
};
use bevy::utils::Uuid;
use bevy::{prelude::*, utils::HashSet};
use bevy_renet::renet::{ClientId, DefaultChannel, RenetServer};
use uuid::Uuid;

pub(crate) fn send_initial_sync(client_id: ClientId, world: &mut World) {
info!("Sending initial sync to client id {}", client_id);
Expand Down
40 changes: 24 additions & 16 deletions tests/assert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use crate::setup::{sample_image, sample_mesh, MySynched, TestEnv};
pub(crate) fn entities_in_sync<T>(env: &mut TestEnv, _: T, entity_count: u32) {
for c in &mut env.clients {
let mut count_check = 0;
for e in c.world.query::<&SyncEntity>().iter(&c.world) {
for e in c.world_mut().query::<&SyncEntity>().iter(c.world()) {
for se in env
.server
.world
.world_mut()
.query::<&SyncEntity>()
.iter(&env.server.world)
.iter(env.server.world())
{
if se.uuid == e.uuid {
count_check += 1;
Expand All @@ -27,7 +27,7 @@ pub(crate) fn entities_in_sync<T>(env: &mut TestEnv, _: T, entity_count: u32) {

#[allow(dead_code)]
pub(crate) fn no_messages_left_for_server(s: &mut App) {
let mut server = s.world.resource_mut::<RenetServer>();
let mut server = s.world_mut().resource_mut::<RenetServer>();
for client_id in server.clients_id().into_iter() {
assert!(server
.receive_message(client_id, DefaultChannel::ReliableOrdered)
Expand All @@ -44,7 +44,7 @@ pub(crate) fn no_messages_left_for_clients(cs: &mut Vec<App>) {

#[allow(dead_code)]
pub(crate) fn no_messages_left_for_client(c: &mut App) {
let mut client = c.world.resource_mut::<RenetClient>();
let mut client = c.world_mut().resource_mut::<RenetClient>();
assert!(client
.receive_message(DefaultChannel::ReliableOrdered)
.is_none());
Expand All @@ -53,8 +53,12 @@ pub(crate) fn no_messages_left_for_client(c: &mut App) {
#[allow(dead_code)]
pub(crate) fn initial_sync_for_client_happened(s: &mut App, c: &mut App, entity_count: u32) {
let mut count_check = 0;
for (e, c) in c.world.query::<(&SyncEntity, &MySynched)>().iter(&c.world) {
for se in s.world.query::<&SyncEntity>().iter(&s.world) {
for (e, c) in c
.world_mut()
.query::<(&SyncEntity, &MySynched)>()
.iter(c.world())
{
for se in s.world_mut().query::<&SyncEntity>().iter(s.world()) {
if se.uuid == e.uuid {
count_check += 1;
assert_eq!(c.value, 7);
Expand All @@ -68,9 +72,9 @@ pub(crate) fn initial_sync_for_client_happened(s: &mut App, c: &mut App, entity_
pub(crate) fn count_entities_with_component<T: Component>(app: &mut App) -> u32 {
let mut count = 0;
for _ in app
.world
.world_mut()
.query_filtered::<Entity, With<T>>()
.iter(&app.world)
.iter(app.world())
{
count += 1;
}
Expand All @@ -81,9 +85,9 @@ pub(crate) fn count_entities_with_component<T: Component>(app: &mut App) -> u32
pub(crate) fn count_entities_without_component<T: Component>(app: &mut App) -> u32 {
let mut count = 0;
for _ in app
.world
.world_mut()
.query_filtered::<Entity, Without<T>>()
.iter(&app.world)
.iter(app.world())
{
count += 1;
}
Expand All @@ -92,19 +96,19 @@ pub(crate) fn count_entities_without_component<T: Component>(app: &mut App) -> u

#[allow(dead_code)]
pub(crate) fn get_first_entity_component<T: Component>(app: &mut App) -> Option<&T> {
app.world.query::<&T>().iter(&app.world).next()
app.world_mut().query::<&T>().iter(app.world()).next()
}

#[allow(dead_code)]
pub(crate) fn material_has_color(app: &mut App, id: AssetId<StandardMaterial>, color: Color) {
let materials = app.world.resource_mut::<Assets<StandardMaterial>>();
let materials = app.world_mut().resource_mut::<Assets<StandardMaterial>>();
let material = materials.get(id).unwrap();
assert_eq!(material.base_color, color);
}

#[allow(dead_code)]
pub(crate) fn assets_has_sample_mesh(app: &mut App, id: AssetId<Mesh>) {
let meshes = app.world.resource_mut::<Assets<Mesh>>();
let meshes = app.world_mut().resource_mut::<Assets<Mesh>>();
let mesh = meshes.get(id).unwrap();
let sample = sample_mesh();
assert_eq!(
Expand All @@ -120,15 +124,19 @@ pub(crate) fn assets_has_sample_mesh(app: &mut App, id: AssetId<Mesh>) {

#[allow(dead_code)]
pub(crate) fn assets_has_sample_image(app: &mut App, id: AssetId<Image>) {
let images = app.world.resource_mut::<Assets<Image>>();
let images = app.world_mut().resource_mut::<Assets<Image>>();
let image = images.get(id).unwrap();
let sample = sample_image();
assert_eq!(image.data, sample.data);
}

#[allow(dead_code)]
pub(crate) fn find_entity_with_server_id(app: &mut App, server_entity_id: Uuid) -> Option<Entity> {
for (entity, sup) in app.world.query::<(Entity, &SyncEntity)>().iter(&app.world) {
for (entity, sup) in app
.world_mut()
.query::<(Entity, &SyncEntity)>()
.iter(app.world())
{
if sup.uuid == server_entity_id {
return Some(entity);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/asset_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn sync_material_from_server() {
spawn_new_material(app)
},
|env, _, id| {
material_has_color(&mut env.clients[0], id, Color::RED);
material_has_color(&mut env.clients[0], id, Color::srgb(1.0, 0.0, 0.0));
},
);
}
Expand All @@ -41,7 +41,7 @@ fn sync_material_from_client() {
spawn_new_material(app)
},
|env, _, id| {
material_has_color(&mut env.clients[0], id, Color::RED);
material_has_color(&mut env.clients[0], id, Color::srgb(1.0, 0.0, 0.0));
},
);
}
Expand All @@ -61,7 +61,7 @@ fn sync_material_from_client_to_client_across_server() {
spawn_new_material(app)
},
|env, _, id| {
material_has_color(&mut env.clients[0], id, Color::RED);
material_has_color(&mut env.clients[0], id, Color::srgb(1.0, 0.0, 0.0));
},
);
}
Expand Down
Loading

0 comments on commit 38bd511

Please sign in to comment.