diff --git a/Cargo.toml b/Cargo.toml index 7ffdf08c..07d8867a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,18 +7,18 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy_ecs = "0.5.0" -bevy_tasks = "0.5.0" +bevy_ecs = "0.8.0" +bevy_tasks = "0.8.0" bincode = "1.3" -cgmath = { version = "0.17", features = ["serde"] } -hecs = { version = "0.5", features = ["column-serialize", "row-serialize"] } -legion = "0.3" +cgmath = { version = "0.18", features = ["serde"] } +hecs = { version = "0.9", features = ["column-serialize", "row-serialize"] } +legion = "0.4" planck_ecs = { version = "1.1.0", features = ["parallel"] } -rayon = "1.3" -ron = "0.6" +rayon = "1.5" +ron = "0.8" serde = { version = "1.0", features = ["derive"] } -shipyard = "0.5.0" -specs = {version = "0.16.1", features = ["serde"] } +shipyard = "0.6.0" +specs = {version = "0.18", features = ["serde"] } specs-derive = "0.4.1" [dev-dependencies] diff --git a/src/bevy/add_remove.rs b/src/bevy/add_remove.rs index 4d43a95c..80e7f28e 100644 --- a/src/bevy/add_remove.rs +++ b/src/bevy/add_remove.rs @@ -1,6 +1,9 @@ use bevy_ecs::prelude::*; +#[derive(bevy_ecs::component::Component)] struct A(f32); + +#[derive(bevy_ecs::component::Component)] struct B(f32); pub struct Benchmark(World, Vec); diff --git a/src/bevy/frag_iter.rs b/src/bevy/frag_iter.rs index b9e30b3e..453dfff8 100644 --- a/src/bevy/frag_iter.rs +++ b/src/bevy/frag_iter.rs @@ -3,12 +3,15 @@ use bevy_ecs::prelude::*; macro_rules! create_entities { ($world:ident; $( $variants:ident ),*) => { $( + #[derive(bevy_ecs::component::Component)] struct $variants(f32); + $world.spawn_batch((0..20).map(|_| ($variants(0.0), Data(1.0)))); )* }; } +#[derive(bevy_ecs::component::Component)] struct Data(f32); pub struct Benchmark(World); diff --git a/src/bevy/heavy_compute.rs b/src/bevy/heavy_compute.rs index fd76dadf..ee100d83 100644 --- a/src/bevy/heavy_compute.rs +++ b/src/bevy/heavy_compute.rs @@ -1,16 +1,18 @@ use bevy_ecs::prelude::*; -use bevy_tasks::TaskPool; use cgmath::*; -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Position(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Rotation(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Velocity(Vector3); +#[derive(Copy, Clone, bevy_ecs::component::Component)] +struct Affine(Matrix4); + pub struct Benchmark(World); impl Benchmark { @@ -19,7 +21,7 @@ impl Benchmark { world.spawn_batch((0..1000).map(|_| { ( - Matrix4::::from_angle_x(Rad(1.2)), + Affine(Matrix4::::from_angle_x(Rad(1.2))), Position(Vector3::unit_x()), Rotation(Vector3::unit_x()), Velocity(Vector3::unit_x()), @@ -30,15 +32,14 @@ impl Benchmark { } pub fn run(&mut self) { - let task_pool = TaskPool::new(); - let mut query = self.0.query::<(&mut Position, &mut Matrix4)>(); + let mut query = self.0.query::<(&mut Position, &mut Affine)>(); - query.par_for_each_mut(&mut self.0, &task_pool, 64, |(mut pos, mut mat)| { + query.par_for_each_mut(&mut self.0, 64, |(mut pos, mut aff)| { for _ in 0..100 { - *mat = mat.invert().unwrap(); + aff.0 = aff.0.invert().unwrap(); } - pos.0 = mat.transform_vector(pos.0); + pos.0 = aff.0.transform_vector(pos.0); }); } } diff --git a/src/bevy/schedule.rs b/src/bevy/schedule.rs index 224c266f..d0734d39 100644 --- a/src/bevy/schedule.rs +++ b/src/bevy/schedule.rs @@ -1,9 +1,18 @@ use bevy_ecs::{prelude::*, schedule::Schedule}; +#[derive(bevy_ecs::component::Component)] struct A(f32); + +#[derive(bevy_ecs::component::Component)] struct B(f32); + +#[derive(bevy_ecs::component::Component)] struct C(f32); + +#[derive(bevy_ecs::component::Component)] struct D(f32); + +#[derive(bevy_ecs::component::Component)] struct E(f32); fn ab(mut query: Query<(&mut A, &mut B)>) { @@ -40,9 +49,9 @@ impl Benchmark { let mut schedule = Schedule::default(); schedule.add_stage("main", SystemStage::parallel()); - schedule.add_system_to_stage("main", ab.system()); - schedule.add_system_to_stage("main", cd.system()); - schedule.add_system_to_stage("main", ce.system()); + schedule.add_system_to_stage("main", ab); + schedule.add_system_to_stage("main", cd); + schedule.add_system_to_stage("main", ce); Self(world, schedule) } diff --git a/src/bevy/simple_insert.rs b/src/bevy/simple_insert.rs index 4dee0cac..af4c8c56 100644 --- a/src/bevy/simple_insert.rs +++ b/src/bevy/simple_insert.rs @@ -1,16 +1,16 @@ use bevy_ecs::prelude::*; use cgmath::*; -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Transform(Matrix4); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Position(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Rotation(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Velocity(Vector3); pub struct Benchmark; diff --git a/src/bevy/simple_iter.rs b/src/bevy/simple_iter.rs index db6dc8c2..6cc688ec 100644 --- a/src/bevy/simple_iter.rs +++ b/src/bevy/simple_iter.rs @@ -1,16 +1,16 @@ use bevy_ecs::prelude::*; use cgmath::*; -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Transform(Matrix4); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Position(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Rotation(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, bevy_ecs::component::Component)] struct Velocity(Vector3); pub struct Benchmark(World); diff --git a/src/hecs/mod.rs b/src/hecs/mod.rs index efa2a923..de02b1df 100644 --- a/src/hecs/mod.rs +++ b/src/hecs/mod.rs @@ -4,4 +4,4 @@ pub mod heavy_compute; pub mod simple_insert; pub mod simple_iter; pub mod serialize_binary; -pub mod serialize_text; \ No newline at end of file +pub mod serialize_text; diff --git a/src/hecs/serialize_binary.rs b/src/hecs/serialize_binary.rs index f3aec7f4..d3fbb810 100644 --- a/src/hecs/serialize_binary.rs +++ b/src/hecs/serialize_binary.rs @@ -52,8 +52,8 @@ impl SerializeContext for SerContext { fn serialize_component_ids( &mut self, archetype: &Archetype, - out: &mut S, - ) -> Result<(), S::Error> { + mut out: S, + ) -> Result { if archetype.has::() { out.serialize_element(&ComponentId::Transform)?; } @@ -66,19 +66,19 @@ impl SerializeContext for SerContext { if archetype.has::() { out.serialize_element(&ComponentId::Velocity)?; } - Ok(()) + out.end() } fn serialize_components( &mut self, archetype: &Archetype, - out: &mut S, - ) -> Result<(), S::Error> { - try_serialize::(archetype, out)?; - try_serialize::(archetype, out)?; - try_serialize::(archetype, out)?; - try_serialize::(archetype, out)?; - Ok(()) + mut out: S, + ) -> Result { + try_serialize::(archetype, &mut out)?; + try_serialize::(archetype, &mut out)?; + try_serialize::(archetype, &mut out)?; + try_serialize::(archetype, &mut out)?; + out.end() } } diff --git a/src/hecs/serialize_text.rs b/src/hecs/serialize_text.rs index 61240fc8..701ae777 100644 --- a/src/hecs/serialize_text.rs +++ b/src/hecs/serialize_text.rs @@ -39,13 +39,13 @@ impl SerializeContext for SerContext { fn serialize_entity( &mut self, entity: EntityRef<'_>, - map: &mut S, - ) -> Result<(), S::Error> { - try_serialize::(&entity, &ComponentId::Transform, map)?; - try_serialize::(&entity, &ComponentId::Position, map)?; - try_serialize::(&entity, &ComponentId::Rotation, map)?; - try_serialize::(&entity, &ComponentId::Velocity, map)?; - Ok(()) + mut map: S, + ) -> Result { + try_serialize::(&entity, &ComponentId::Transform, &mut map)?; + try_serialize::(&entity, &ComponentId::Position, &mut map)?; + try_serialize::(&entity, &ComponentId::Rotation, &mut map)?; + try_serialize::(&entity, &ComponentId::Velocity, &mut map)?; + map.end() } } @@ -104,7 +104,7 @@ impl Benchmark { serialize( &world, &mut SerContext, - &mut ron::Serializer::new(&mut encoded, None, false).unwrap(), + &mut ron::Serializer::new(&mut encoded, None).unwrap(), ) .unwrap(); deserialize( diff --git a/src/legion/serialize_binary.rs b/src/legion/serialize_binary.rs index cb8219d0..f51e1643 100644 --- a/src/legion/serialize_binary.rs +++ b/src/legion/serialize_binary.rs @@ -52,7 +52,10 @@ impl Benchmark { pub fn run(&mut self) { let Self(world, registry) = self; - let serializable = &world.as_serializable(any(), &*registry); + + let mut canon = legion::serialize::Canon::default(); + + let serializable = &world.as_serializable(any(), &*registry, &mut canon); let encoded = bincode::serialize(serializable).unwrap(); @@ -65,7 +68,7 @@ impl Benchmark { ); registry - .as_deserialize() + .as_deserialize(&mut canon) .deserialize(&mut deserializer) .unwrap(); } diff --git a/src/legion/serialize_text.rs b/src/legion/serialize_text.rs index 07a33101..93d3bbf2 100644 --- a/src/legion/serialize_text.rs +++ b/src/legion/serialize_text.rs @@ -52,13 +52,15 @@ impl Benchmark { pub fn run(&mut self) { let Self(world, registry) = self; - let serializable = &world.as_serializable(any(), &*registry); + let mut canon = legion::serialize::Canon::default(); + + let serializable = &world.as_serializable(any(), &*registry, &mut canon); let serialized = ron::ser::to_string(serializable).unwrap(); let mut deserializer = ron::de::Deserializer::from_str(&serialized).unwrap(); registry - .as_deserialize() + .as_deserialize(&mut canon) .deserialize(&mut deserializer) .unwrap(); } diff --git a/src/shipyard/add_remove.rs b/src/shipyard/add_remove.rs index 05c758fa..dab538d4 100644 --- a/src/shipyard/add_remove.rs +++ b/src/shipyard/add_remove.rs @@ -1,6 +1,9 @@ use shipyard::*; +#[derive(Component)] struct A(f32); + +#[derive(Component)] struct B(f32); pub struct Benchmark(World, Vec); @@ -16,7 +19,7 @@ impl Benchmark { entity_ids.push(entity); } entity_ids - }).unwrap(); + }); Self(world, entities) } @@ -26,12 +29,12 @@ impl Benchmark { for entity in &self.1 { entities.add_component(*entity, &mut b, B(0.0)); } - }).unwrap(); + }); self.0.run(|mut b: ViewMut| { for entity in &self.1 { b.remove(*entity); } - }).unwrap(); + }); } } diff --git a/src/shipyard/frag_iter.rs b/src/shipyard/frag_iter.rs index a0546614..46366dc3 100644 --- a/src/shipyard/frag_iter.rs +++ b/src/shipyard/frag_iter.rs @@ -3,6 +3,7 @@ use shipyard::*; macro_rules! create_entities { ($world:ident; $( $variants:ident ),*) => { $( + #[derive(Component)] struct $variants(f32); $world.run( | mut entities: EntitiesViewMut, @@ -14,11 +15,12 @@ macro_rules! create_entities { ($variants(0.0), Data(1.0)), ); } - }).unwrap(); + }); )* }; } +#[derive(Component)] struct Data(f32); pub struct Benchmark(World); @@ -37,6 +39,6 @@ impl Benchmark { (&mut data).iter().for_each(|mut data| { data.0 *= 2.0; }) - }).unwrap(); + }); } } diff --git a/src/shipyard/heavy_compute.rs b/src/shipyard/heavy_compute.rs index 20a177ac..734da41e 100644 --- a/src/shipyard/heavy_compute.rs +++ b/src/shipyard/heavy_compute.rs @@ -1,16 +1,19 @@ -use cgmath::*; +use cgmath::{Transform as _, *}; use rayon::prelude::*; use shipyard::*; -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Position(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Rotation(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Velocity(Vector3); +#[derive(Copy, Clone, Component)] +struct Transform(Matrix4); + pub struct Benchmark(World); impl Benchmark { @@ -19,7 +22,7 @@ impl Benchmark { world.run( |mut entities: EntitiesViewMut, - mut transforms: ViewMut>, + mut transforms: ViewMut, mut positions: ViewMut, mut rotations: ViewMut, mut velocities: ViewMut| { @@ -32,7 +35,7 @@ impl Benchmark { &mut velocities, ), ( - Matrix4::::from_angle_x(Rad(1.2)), + Transform(Matrix4::::from_angle_x(Rad(1.2))), Position(Vector3::unit_x()), Rotation(Vector3::unit_x()), Velocity(Vector3::unit_x()), @@ -40,23 +43,24 @@ impl Benchmark { ); } }, - ).unwrap(); + ); Self(world) } pub fn run(&mut self) { self.0.run( - |mut positions: ViewMut, mut transforms: ViewMut>| { - (&mut positions, &mut transforms) - .par_iter() - .for_each(|(mut pos, mut mat)| { + |mut positions: ViewMut, mut transforms: ViewMut| { + (&mut positions, &mut transforms).par_iter().for_each( + |(mut pos, mut transform)| { for _ in 0..100 { - *mat = mat.invert().unwrap(); + transform.0 = transform.0.invert().unwrap(); } - pos.0 = mat.transform_vector(pos.0); - }); + + pos.0 = transform.0.transform_vector(pos.0); + }, + ); }, - ).unwrap(); + ); } } diff --git a/src/shipyard/schedule.rs b/src/shipyard/schedule.rs index a84d9937..8d53d1e2 100644 --- a/src/shipyard/schedule.rs +++ b/src/shipyard/schedule.rs @@ -1,25 +1,34 @@ use shipyard::*; +#[derive(Component)] struct A(f32); + +#[derive(Component)] struct B(f32); + +#[derive(Component)] struct C(f32); + +#[derive(Component)] struct D(f32); + +#[derive(Component)] struct E(f32); fn ab(mut a: ViewMut, mut b: ViewMut) { - (&mut a, &mut b).iter().for_each(|(mut a, mut b)| { + (&mut a, &mut b).iter().for_each(|(a, b)| { std::mem::swap(&mut a.0, &mut b.0); }) } fn cd(mut c: ViewMut, mut d: ViewMut) { - (&mut c, &mut d).iter().for_each(|(mut c, mut d)| { + (&mut c, &mut d).iter().for_each(|(c, d)| { std::mem::swap(&mut c.0, &mut d.0); }) } fn ce(mut c: ViewMut, mut e: ViewMut) { - (&mut c, &mut e).iter().for_each(|(mut c, mut e)| { + (&mut c, &mut e).iter().for_each(|(c, e)| { std::mem::swap(&mut c.0, &mut e.0); }) } @@ -36,7 +45,7 @@ impl Benchmark { entities.add_entity((&mut a, &mut b), (A(0.0), B(0.0))); } }, - ).unwrap(); + ); world.run( |mut entities: EntitiesViewMut, @@ -47,7 +56,7 @@ impl Benchmark { entities.add_entity((&mut a, &mut b, &mut c), (A(0.0), B(0.0), C(0.0))); } }, - ).unwrap(); + ); world.run( |mut entities: EntitiesViewMut, @@ -62,7 +71,7 @@ impl Benchmark { ); } }, - ).unwrap(); + ); world.run( |mut entities: EntitiesViewMut, @@ -77,9 +86,9 @@ impl Benchmark { ); } }, - ).unwrap(); + ); - Workload::builder("run") + Workload::new("run") .with_system(&ab) .with_system(&cd) .with_system(&ce) diff --git a/src/shipyard/simple_insert.rs b/src/shipyard/simple_insert.rs index 27d6a94a..5e4a66fe 100644 --- a/src/shipyard/simple_insert.rs +++ b/src/shipyard/simple_insert.rs @@ -1,16 +1,16 @@ use cgmath::*; use shipyard::*; -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Transform(Matrix4); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Position(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Rotation(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Velocity(Vector3); pub struct Benchmark; @@ -46,6 +46,6 @@ impl Benchmark { ); } }, - ).unwrap(); + ); } } diff --git a/src/shipyard/simple_iter.rs b/src/shipyard/simple_iter.rs index 9c0c6dbf..cfb44374 100644 --- a/src/shipyard/simple_iter.rs +++ b/src/shipyard/simple_iter.rs @@ -1,16 +1,16 @@ use cgmath::*; use shipyard::*; -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Transform(Matrix4); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Position(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Rotation(Vector3); -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Component)] struct Velocity(Vector3); pub struct Benchmark(World); @@ -42,7 +42,7 @@ impl Benchmark { ); } }, - ).unwrap(); + ); Self(world) } @@ -52,10 +52,10 @@ impl Benchmark { |velocities: View, mut positions: ViewMut| { (&velocities, &mut positions) .iter() - .for_each(|(velocity, mut position)| { + .for_each(|(velocity, position)| { position.0 += velocity.0; }) }, - ).unwrap(); + ); } }