Skip to content

Commit

Permalink
Cloneable component specialization of EntityBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Sep 19, 2021
1 parent 88e4f24 commit e97efb7
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 90 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@
- `Or` query combinator, allowing a single query to select entities that satisfy at least one of two
sub-queries.
- `EntityRef::has` to efficiently check for the presence of a component without borrowing it
- `EntityBulider::new_cloneable` constructs an `EntityBuilder` that builds a `ReusableBuiltEntity`,
which can be spawned repeatedly by reference.

### Changed
- Added a niche to `Entity`, making `Option<Entity>` the same size as a bare `Entity`. As a
Expand Down
15 changes: 14 additions & 1 deletion benches/bench.rs
Expand Up @@ -8,7 +8,9 @@
use bencher::{benchmark_group, benchmark_main, Bencher};
use hecs::*;

#[derive(Clone)]
struct Position(f32);
#[derive(Clone)]
struct Velocity(f32);

fn spawn_tuple(b: &mut Bencher) {
Expand Down Expand Up @@ -195,6 +197,16 @@ fn build(b: &mut Bencher) {
});
}

fn build_cloneable(b: &mut Bencher) {
let mut world = World::new();
let mut builder = EntityBuilder::new_cloneable();
builder.add(Position(0.0)).add(Velocity(0.0));
let bundle = builder.build();
b.iter(|| {
world.spawn(&bundle);
});
}

benchmark_group!(
benches,
spawn_tuple,
Expand All @@ -208,6 +220,7 @@ benchmark_group!(
iterate_cached_100_by_50,
iterate_mut_uncached_100_by_50,
iterate_mut_cached_100_by_50,
build
build,
build_cloneable,
);
benchmark_main!(benches);

0 comments on commit e97efb7

Please sign in to comment.