Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit bcdd15d

Browse files
committed
Add Edict ECS
Update other ECS implementations to latest versions
1 parent d9c108a commit bcdd15d

16 files changed

+221
-41
lines changed

Cargo.toml

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
bevy_ecs = "0.5.0"
11-
bevy_tasks = "0.5.0"
10+
bevy_ecs = "0.6.0"
11+
bevy_tasks = "0.6.0"
1212
bincode = "1.3"
13-
cgmath = { version = "0.17", features = ["serde"] }
14-
hecs = { version = "0.5", features = ["column-serialize", "row-serialize"] }
15-
legion = "0.3"
13+
cgmath = { version = "0.18", features = ["serde"] }
14+
hecs = { version = "0.7", features = ["column-serialize", "row-serialize"] }
15+
legion = "0.4"
1616
planck_ecs = { version = "1.1.0", features = ["parallel"] }
1717
rayon = "1.3"
18-
ron = "0.6"
18+
ron = "0.7"
1919
serde = { version = "1.0", features = ["derive"] }
2020
shipyard = "0.5.0"
21-
specs = {version = "0.16.1", features = ["serde"] }
21+
specs = {version = "0.17", features = ["serde"] }
2222
specs-derive = "0.4.1"
23+
edict = { version = "0.0.3" }
2324

2425
[dev-dependencies]
2526
criterion = "0.3"

benches/benchmarks.rs

+30-14
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ fn bench_simple_insert(c: &mut Criterion) {
77
let mut bench = legion::simple_insert::Benchmark::new();
88
b.iter(move || bench.run());
99
});
10-
group.bench_function("bevy", |b| {
11-
let mut bench = bevy::simple_insert::Benchmark::new();
12-
b.iter(move || bench.run());
13-
});
1410
group.bench_function("hecs", |b| {
1511
let mut bench = hecs::simple_insert::Benchmark::new();
1612
b.iter(move || bench.run());
1713
});
14+
group.bench_function("bevy", |b| {
15+
let mut bench = bevy::simple_insert::Benchmark::new();
16+
b.iter(move || bench.run());
17+
});
1818
group.bench_function("planck_ecs", |b| {
1919
let mut bench = planck_ecs::simple_insert::Benchmark::new();
2020
b.iter(move || bench.run());
@@ -27,6 +27,10 @@ fn bench_simple_insert(c: &mut Criterion) {
2727
let mut bench = specs::simple_insert::Benchmark::new();
2828
b.iter(move || bench.run());
2929
});
30+
group.bench_function("edict", |b| {
31+
let mut bench = edict::simple_insert::Benchmark::new();
32+
b.iter(move || bench.run());
33+
});
3034
}
3135

3236
fn bench_simple_iter(c: &mut Criterion) {
@@ -39,14 +43,14 @@ fn bench_simple_iter(c: &mut Criterion) {
3943
let mut bench = legion_packed::simple_iter::Benchmark::new();
4044
b.iter(move || bench.run());
4145
});
42-
group.bench_function("bevy", |b| {
43-
let mut bench = bevy::simple_iter::Benchmark::new();
44-
b.iter(move || bench.run());
45-
});
4646
group.bench_function("hecs", |b| {
4747
let mut bench = hecs::simple_iter::Benchmark::new();
4848
b.iter(move || bench.run());
4949
});
50+
group.bench_function("bevy", |b| {
51+
let mut bench = bevy::simple_iter::Benchmark::new();
52+
b.iter(move || bench.run());
53+
});
5054
group.bench_function("planck_ecs", |b| {
5155
let mut bench = planck_ecs::simple_iter::Benchmark::new();
5256
b.iter(move || bench.run());
@@ -59,6 +63,10 @@ fn bench_simple_iter(c: &mut Criterion) {
5963
let mut bench = specs::simple_iter::Benchmark::new();
6064
b.iter(move || bench.run());
6165
});
66+
group.bench_function("edict", |b| {
67+
let mut bench = edict::simple_iter::Benchmark::new();
68+
b.iter(move || bench.run());
69+
});
6270
}
6371

6472
fn bench_frag_iter_bc(c: &mut Criterion) {
@@ -67,14 +75,14 @@ fn bench_frag_iter_bc(c: &mut Criterion) {
6775
let mut bench = legion::frag_iter::Benchmark::new();
6876
b.iter(move || bench.run());
6977
});
70-
group.bench_function("bevy", |b| {
71-
let mut bench = bevy::frag_iter::Benchmark::new();
72-
b.iter(move || bench.run());
73-
});
7478
group.bench_function("hecs", |b| {
7579
let mut bench = hecs::frag_iter::Benchmark::new();
7680
b.iter(move || bench.run());
7781
});
82+
group.bench_function("bevy", |b| {
83+
let mut bench = bevy::frag_iter::Benchmark::new();
84+
b.iter(move || bench.run());
85+
});
7886
group.bench_function("planck_ecs", |b| {
7987
let mut bench = planck_ecs::frag_iter::Benchmark::new();
8088
b.iter(move || bench.run());
@@ -87,6 +95,10 @@ fn bench_frag_iter_bc(c: &mut Criterion) {
8795
let mut bench = specs::frag_iter::Benchmark::new();
8896
b.iter(move || bench.run());
8997
});
98+
group.bench_function("edict", |b| {
99+
let mut bench = edict::frag_iter::Benchmark::new();
100+
b.iter(move || bench.run());
101+
});
90102
}
91103

92104
fn bench_schedule(c: &mut Criterion) {
@@ -155,6 +167,10 @@ fn bench_add_remove(c: &mut Criterion) {
155167
let mut bench = hecs::add_remove::Benchmark::new();
156168
b.iter(move || bench.run());
157169
});
170+
group.bench_function("bevy", |b| {
171+
let mut bench = bevy::add_remove::Benchmark::new();
172+
b.iter(move || bench.run());
173+
});
158174
group.bench_function("planck_ecs", |b| {
159175
let mut bench = planck_ecs::add_remove::Benchmark::new();
160176
b.iter(move || bench.run());
@@ -167,8 +183,8 @@ fn bench_add_remove(c: &mut Criterion) {
167183
let mut bench = specs::add_remove::Benchmark::new();
168184
b.iter(move || bench.run());
169185
});
170-
group.bench_function("bevy", |b| {
171-
let mut bench = bevy::add_remove::Benchmark::new();
186+
group.bench_function("edict", |b| {
187+
let mut bench = edict::add_remove::Benchmark::new();
172188
b.iter(move || bench.run());
173189
});
174190
}

src/bevy/add_remove.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use bevy_ecs::prelude::*;
22

3+
#[derive(bevy_ecs::component::Component)]
34
struct A(f32);
5+
6+
#[derive(bevy_ecs::component::Component)]
47
struct B(f32);
58

69
pub struct Benchmark(World, Vec<Entity>);

src/bevy/frag_iter.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ use bevy_ecs::prelude::*;
33
macro_rules! create_entities {
44
($world:ident; $( $variants:ident ),*) => {
55
$(
6+
#[derive(bevy_ecs::component::Component)]
67
struct $variants(f32);
8+
79
$world.spawn_batch((0..20).map(|_| ($variants(0.0), Data(1.0))));
810
)*
911
};
1012
}
1113

14+
#[derive(bevy_ecs::component::Component)]
1215
struct Data(f32);
1316

1417
pub struct Benchmark(World);

src/bevy/heavy_compute.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ use bevy_ecs::prelude::*;
22
use bevy_tasks::TaskPool;
33
use cgmath::*;
44

5-
#[derive(Copy, Clone)]
5+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
66
struct Position(Vector3<f32>);
77

8-
#[derive(Copy, Clone)]
8+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
99
struct Rotation(Vector3<f32>);
1010

11-
#[derive(Copy, Clone)]
11+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
1212
struct Velocity(Vector3<f32>);
1313

14+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
15+
struct Affine(Matrix4<f32>);
16+
1417
pub struct Benchmark(World);
1518

1619
impl Benchmark {
@@ -19,7 +22,7 @@ impl Benchmark {
1922

2023
world.spawn_batch((0..1000).map(|_| {
2124
(
22-
Matrix4::<f32>::from_angle_x(Rad(1.2)),
25+
Affine(Matrix4::<f32>::from_angle_x(Rad(1.2))),
2326
Position(Vector3::unit_x()),
2427
Rotation(Vector3::unit_x()),
2528
Velocity(Vector3::unit_x()),
@@ -31,14 +34,14 @@ impl Benchmark {
3134

3235
pub fn run(&mut self) {
3336
let task_pool = TaskPool::new();
34-
let mut query = self.0.query::<(&mut Position, &mut Matrix4<f32>)>();
37+
let mut query = self.0.query::<(&mut Position, &mut Affine)>();
3538

36-
query.par_for_each_mut(&mut self.0, &task_pool, 64, |(mut pos, mut mat)| {
39+
query.par_for_each_mut(&mut self.0, &task_pool, 64, |(mut pos, mut aff)| {
3740
for _ in 0..100 {
38-
*mat = mat.invert().unwrap();
41+
aff.0 = aff.0.invert().unwrap();
3942
}
4043

41-
pos.0 = mat.transform_vector(pos.0);
44+
pos.0 = aff.0.transform_vector(pos.0);
4245
});
4346
}
4447
}

src/bevy/schedule.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
use bevy_ecs::{prelude::*, schedule::Schedule};
22

3+
#[derive(bevy_ecs::component::Component)]
34
struct A(f32);
5+
6+
#[derive(bevy_ecs::component::Component)]
47
struct B(f32);
8+
9+
#[derive(bevy_ecs::component::Component)]
510
struct C(f32);
11+
12+
#[derive(bevy_ecs::component::Component)]
613
struct D(f32);
14+
15+
#[derive(bevy_ecs::component::Component)]
716
struct E(f32);
817

918
fn ab(mut query: Query<(&mut A, &mut B)>) {

src/bevy/simple_insert.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use bevy_ecs::prelude::*;
22
use cgmath::*;
33

4-
#[derive(Copy, Clone)]
4+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
55
struct Transform(Matrix4<f32>);
66

7-
#[derive(Copy, Clone)]
7+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
88
struct Position(Vector3<f32>);
99

10-
#[derive(Copy, Clone)]
10+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
1111
struct Rotation(Vector3<f32>);
1212

13-
#[derive(Copy, Clone)]
13+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
1414
struct Velocity(Vector3<f32>);
1515

1616
pub struct Benchmark;

src/bevy/simple_iter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use bevy_ecs::prelude::*;
22
use cgmath::*;
33

4-
#[derive(Copy, Clone)]
4+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
55
struct Transform(Matrix4<f32>);
66

7-
#[derive(Copy, Clone)]
7+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
88
struct Position(Vector3<f32>);
99

10-
#[derive(Copy, Clone)]
10+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
1111
struct Rotation(Vector3<f32>);
1212

13-
#[derive(Copy, Clone)]
13+
#[derive(Copy, Clone, bevy_ecs::component::Component)]
1414
struct Velocity(Vector3<f32>);
1515

1616
pub struct Benchmark(World);

src/edict/add_remove.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use edict::prelude::*;
2+
3+
struct A(f32);
4+
struct B(f32);
5+
6+
pub struct Benchmark(World, Vec<Entity>);
7+
8+
impl Benchmark {
9+
pub fn new() -> Self {
10+
let mut world = World::new();
11+
12+
let entities = (0..10_000).map(|_| world.spawn((A(0.0),))).collect();
13+
14+
Self(world, entities)
15+
}
16+
17+
pub fn run(&mut self) {
18+
for entity in &self.1 {
19+
self.0.insert(entity, B(0.0));
20+
}
21+
22+
for entity in &self.1 {
23+
let _ = self.0.remove::<B>(entity);
24+
}
25+
}
26+
}

src/edict/frag_iter.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use edict::prelude::*;
2+
3+
macro_rules! create_entities {
4+
($world:ident; $entities:ident; $( $variants:ident ),*) => {
5+
$(
6+
struct $variants(f32);
7+
$entities.extend($world.spawn_batch((0..20).map(|_| ($variants(0.0), Data(1.0)))));
8+
)*
9+
};
10+
}
11+
12+
struct Data(f32);
13+
14+
pub struct Benchmark(World, Vec<Entity>);
15+
16+
impl Benchmark {
17+
pub fn new() -> Self {
18+
let mut world = World::default();
19+
let mut entities = Vec::new();
20+
21+
create_entities!(world; entities; A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z);
22+
23+
Self(world, entities)
24+
}
25+
26+
pub fn run(&mut self) {
27+
self.0.for_each_mut::<&mut Data, _>(|data| data.0 *= 2.0);
28+
}
29+
}

src/edict/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub mod add_remove;
2+
pub mod frag_iter;
3+
pub mod simple_insert;
4+
pub mod simple_iter;

src/edict/simple_insert.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use cgmath::*;
2+
use edict::prelude::*;
3+
4+
#[derive(Copy, Clone)]
5+
struct Transform(Matrix4<f32>);
6+
7+
#[derive(Copy, Clone)]
8+
struct Position(Vector3<f32>);
9+
10+
#[derive(Copy, Clone)]
11+
struct Rotation(Vector3<f32>);
12+
13+
#[derive(Copy, Clone)]
14+
struct Velocity(Vector3<f32>);
15+
16+
pub struct Benchmark {
17+
entities: Vec<Entity>,
18+
}
19+
20+
impl Benchmark {
21+
pub fn new() -> Self {
22+
Benchmark {
23+
entities: Vec::new(),
24+
}
25+
}
26+
27+
pub fn run(&mut self) {
28+
let mut world = World::new();
29+
30+
self.entities.extend(world.spawn_batch((0..10_000).map(|_| {
31+
(
32+
Transform(Matrix4::from_scale(1.0)),
33+
Position(Vector3::unit_x()),
34+
Rotation(Vector3::unit_x()),
35+
Velocity(Vector3::unit_x()),
36+
)
37+
})));
38+
}
39+
}

0 commit comments

Comments
 (0)