Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaeleragni committed Dec 11, 2023
1 parent d11f49e commit e0671b1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Current state is in development.
- [X] Entity synchronization
- [X] Component synchronization
- [X] Parent/Child entity synchronization
- [ ] Skippable channel for Unordered+Unreliable
- [ ] Transform
- [X] SimpleMaterial (through sync channel)
- [ ] Refactor asset transfer through http
- [x] Asset: Mesh
Expand Down
Binary file added assets/cube.glb
Binary file not shown.
30 changes: 28 additions & 2 deletions tests/asset_sync.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod assert;
mod setup;

use assert::{material_has_color, assets_has_sample_mesh};
use assert::{assets_has_sample_mesh, material_has_color};
use bevy::prelude::*;
use bevy_sync::SyncComponent;
use serial_test::serial;
use setup::{spawn_new_material, spawn_new_mesh, TestRun};
use setup::{spawn_new_material, spawn_new_mesh, TestRun, load_cube};

#[test]
#[serial]
Expand Down Expand Up @@ -105,3 +105,29 @@ fn test_mesh_transferred_from_client() {
},
);
}

#[test]
#[serial]
fn test_with_asset_loader() {
TestRun::default().run(
1,
|env| {
env.setup_registration::<Handle<Mesh>>();
env.setup_registration::<Handle<StandardMaterial>>();
for app in [&mut env.server, &mut env.clients[0]] {
app.sync_meshes(true);
app.sync_materials(true);
}
},
|env| {
let app = &mut env.server;
load_cube(app)
},
|env, _, (mesh_id, material_id)| {
println!("{:?} {:?}", mesh_id, material_id);
assets_has_sample_mesh(&mut env.clients[0], mesh_id);
material_has_color(&mut env.clients[0], material_id, Color::RED);
},
);
}

20 changes: 19 additions & 1 deletion tests/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
error::Error,
fmt::Display,
net::{IpAddr, Ipv4Addr},
net::{IpAddr, Ipv4Addr}, os::unix::thread, time::Duration,
};

use bevy::{
Expand Down Expand Up @@ -242,3 +242,21 @@ pub(crate) fn sample_mesh() -> Mesh {

mesh
}

#[allow(dead_code)]
pub(crate) fn load_cube(app: &mut App) -> (AssetId<Mesh>, AssetId<StandardMaterial>) {
app.init_asset::<Scene>();
app.init_asset::<Mesh>();
app.init_asset::<StandardMaterial>();
let assets = app.world.resource_mut::<AssetServer>();
let scene = assets.load("cube.glb#Scene0");
app.world.spawn(SceneBundle {
scene,
..Default::default()
});
let meshes = app.world.resource_mut::<Assets<Mesh>>();
let mesh_id = meshes.iter().next().unwrap().0;
let materials = app.world.resource_mut::<Assets<StandardMaterial>>();
let material_id = materials.iter().next().unwrap().0;
(mesh_id, material_id)
}

0 comments on commit e0671b1

Please sign in to comment.