Skip to content

Commit

Permalink
fix breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaeleragni committed Dec 20, 2023
1 parent 948abd3 commit 2c1a01b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 21 deletions.
3 changes: 2 additions & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ fn main() {

let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let port = 4000;
let web_port = 4001;

let mut client = App::new();
client.add_plugins(DefaultPlugins);
client.add_plugins(bevy_editor_pls::EditorPlugin::default());
client.add_plugins(SyncPlugin);
client.add_plugins(ClientPlugin { ip, port });
client.add_plugins(ClientPlugin { ip, port, web_port });

client.sync_component::<Name>();
client.sync_component::<Aabb>();
Expand Down
18 changes: 9 additions & 9 deletions src/client/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) fn entity_parented_on_client(
) {
for (p, sup) in query.iter() {
let Ok(parent) = query_parent.get_component::<SyncUp>(p.get()) else {
return;
continue;
};
client.send_message(
DefaultChannel::ReliableOrdered,
Expand Down Expand Up @@ -81,7 +81,7 @@ pub(crate) fn react_on_changed_components(
let registry = registry.read();
while let Some(change) = track.changed_components_to_send.pop_front() {
let Ok(bin) = compo_to_bin(change.data.as_reflect(), &registry) else {
break;
continue;
};
client.send_message(
DefaultChannel::ReliableOrdered,
Expand All @@ -107,16 +107,16 @@ pub(crate) fn react_on_changed_materials(
match event {
AssetEvent::Added { id } | AssetEvent::Modified { id } => {
let Some(material) = materials.get(*id) else {
break;
continue;
};
let AssetId::Uuid { uuid: id } = id else {
break;
continue;
};
if track.skip_network_handle_change(*id) {
break;
continue;
}
let Ok(bin) = compo_to_bin(material.as_reflect(), &registry) else {
break;
continue;
};
client.send_message(
DefaultChannel::ReliableOrdered,
Expand All @@ -143,13 +143,13 @@ pub(crate) fn react_on_changed_meshes(
match event {
AssetEvent::Added { id } | AssetEvent::Modified { id } => {
let Some(mesh) = assets.get(*id) else {
return;
continue;
};
let AssetId::Uuid { uuid: id } = id else {
return;
continue;
};
if track.skip_network_handle_change(*id) {
return;
continue;
}
client.send_message(
DefaultChannel::ReliableOrdered,
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ pub struct SyncPlugin;
pub struct ServerPlugin {
pub ip: IpAddr,
pub port: u16,
pub web_port: u16
pub web_port: u16,
}

pub struct ClientPlugin {
pub ip: IpAddr,
pub port: u16,
pub web_port: u16,
}

pub trait SyncComponent {
Expand Down
2 changes: 2 additions & 0 deletions src/lib_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,15 @@ impl Plugin for SyncPlugin {
impl Plugin for ServerPlugin {
fn build(&self, app: &mut App) {
crate::networking::setup_server(app, self.ip, self.port);
crate::networking::assets::setup_server(app, self.ip, self.web_port);
app.add_plugins(ServerSyncPlugin);
}
}

impl Plugin for ClientPlugin {
fn build(&self, app: &mut App) {
crate::networking::setup_client(app, self.ip, self.port);
crate::networking::assets::setup_client(app, self.ip, self.web_port);
app.add_plugins(ClientSyncPlugin);
}
}
7 changes: 7 additions & 0 deletions src/networking/assets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use bevy::prelude::*;

pub(crate) fn setup_client(app: &mut App, ip: std::net::IpAddr, web_port: u16) {
}

pub(crate) fn setup_server(app: &mut App, ip: std::net::IpAddr, web_port: u16) {
}
2 changes: 2 additions & 0 deletions src/networking.rs → src/networking/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod assets;

use std::{
net::{IpAddr, SocketAddr, UdpSocket},
time::SystemTime,
Expand Down
4 changes: 2 additions & 2 deletions src/server/initial_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn check_entity_components(world: &World, result: &mut Vec<Message>) -> Result<(
let entity = world.entity(arch_entity.entity());
let e_id = entity.id();
let component = reflect_component.reflect(entity).ok_or("not registered")?;
let Ok(compo_bin) = compo_to_bin(component.as_reflect(), &registry) else {break};
let Ok(compo_bin) = compo_to_bin(component.as_reflect(), &registry) else {continue};
result.push(Message::ComponentUpdated {
id: e_id,
name: type_name.into(),
Expand Down Expand Up @@ -145,7 +145,7 @@ fn check_materials(world: &World, result: &mut Vec<Message>) -> Result<(), Box<d
continue;
};
let Ok(bin) = compo_to_bin(material.as_reflect(), &registry) else {
break;
continue;
};
result.push(Message::StandardMaterialUpdated { id, material: bin });
}
Expand Down
16 changes: 8 additions & 8 deletions src/server/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub(crate) fn react_on_changed_components(
let registry = registry.read();
while let Some(change) = track.changed_components_to_send.pop_front() {
let Ok(bin) = compo_to_bin(change.data.as_reflect(), &registry) else {
break;
continue;
};
let msg = &Message::ComponentUpdated {
id: change.change_id.id,
Expand Down Expand Up @@ -148,16 +148,16 @@ pub(crate) fn react_on_changed_materials(
match event {
AssetEvent::Added { id } | AssetEvent::Modified { id } => {
let Some(material) = materials.get(*id) else {
return;
continue;
};
let AssetId::Uuid { uuid: id } = id else {
return;
continue;
};
if track.skip_network_handle_change(*id) {
return;
continue;
}
let Ok(bin) = compo_to_bin(material.as_reflect(), &registry) else {
break;
continue;
};
let msg = &Message::StandardMaterialUpdated {
id: *id,
Expand Down Expand Up @@ -187,13 +187,13 @@ pub(crate) fn react_on_changed_meshes(
match event {
AssetEvent::Added { id } | AssetEvent::Modified { id } => {
let Some(mesh) = assets.get(*id) else {
return;
continue;
};
let AssetId::Uuid { uuid: id } = id else {
return;
continue;
};
if track.skip_network_handle_change(*id) {
return;
continue;
}
for cid in server.clients_id().into_iter() {
server.send_message(
Expand Down
1 change: 1 addition & 0 deletions tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ fn connect_envs(env: &TestRun, sapp: &mut App, capps: &mut Vec<App>) -> Result<(
capp.add_plugins(ClientPlugin {
ip: env.ip,
port: env.port,
web_port: env.web_port,
});

wait_until_connected(sapp, capp, env.startup_max_wait_updates)?;
Expand Down

0 comments on commit 2c1a01b

Please sign in to comment.