Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions benches/benches/bevy_ecs/world/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ pub fn get_or_spawn(criterion: &mut Criterion) {

bencher.iter(|| {
let mut commands = Commands::new(&mut command_queue, &world);
for i in 0..10_000 {
for i in 1..=10_000 {
commands
.get_or_spawn(Entity::from_raw(i))
.get_or_spawn(Entity::from_raw(i).unwrap())
.insert((Matrix::default(), Vec3::default()));
}
command_queue.apply(&mut world);
Expand All @@ -246,8 +246,8 @@ pub fn get_or_spawn(criterion: &mut Criterion) {
bencher.iter(|| {
let mut commands = Commands::new(&mut command_queue, &world);
let mut values = Vec::with_capacity(10_000);
for i in 0..10_000 {
values.push((Entity::from_raw(i), (Matrix::default(), Vec3::default())));
for i in 1..=10_000 {
values.push((Entity::from_raw(i).unwrap(), (Matrix::default(), Vec3::default())));
}
commands.insert_or_spawn_batch(values);
command_queue.apply(&mut world);
Expand Down
28 changes: 14 additions & 14 deletions benches/benches/bevy_ecs/world/world_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub fn world_entity(criterion: &mut Criterion) {
let world = setup::<Table>(entity_count);

bencher.iter(|| {
for i in 0..entity_count {
let entity = Entity::from_raw(i);
for i in 1..=entity_count {
let entity = Entity::from_raw(i).unwrap();
black_box(world.entity(entity));
}
});
Expand All @@ -72,8 +72,8 @@ pub fn world_get(criterion: &mut Criterion) {
let world = setup::<Table>(entity_count);

bencher.iter(|| {
for i in 0..entity_count {
let entity = Entity::from_raw(i);
for i in 1..=entity_count {
let entity = Entity::from_raw(i).unwrap();
assert!(world.get::<Table>(entity).is_some());
}
});
Expand All @@ -82,8 +82,8 @@ pub fn world_get(criterion: &mut Criterion) {
let world = setup::<Sparse>(entity_count);

bencher.iter(|| {
for i in 0..entity_count {
let entity = Entity::from_raw(i);
for i in 1..=entity_count {
let entity = Entity::from_raw(i).unwrap();
assert!(world.get::<Sparse>(entity).is_some());
}
});
Expand All @@ -104,8 +104,8 @@ pub fn world_query_get(criterion: &mut Criterion) {
let mut query = world.query::<&Table>();

bencher.iter(|| {
for i in 0..entity_count {
let entity = Entity::from_raw(i);
for i in 1..=entity_count {
let entity = Entity::from_raw(i).unwrap();
assert!(query.get(&world, entity).is_ok());
}
});
Expand All @@ -129,8 +129,8 @@ pub fn world_query_get(criterion: &mut Criterion) {
)>();

bencher.iter(|| {
for i in 0..entity_count {
let entity = Entity::from_raw(i);
for i in 1..=entity_count {
let entity = Entity::from_raw(i).unwrap();
assert!(query.get(&world, entity).is_ok());
}
});
Expand All @@ -140,8 +140,8 @@ pub fn world_query_get(criterion: &mut Criterion) {
let mut query = world.query::<&Sparse>();

bencher.iter(|| {
for i in 0..entity_count {
let entity = Entity::from_raw(i);
for i in 1..=entity_count {
let entity = Entity::from_raw(i).unwrap();
assert!(query.get(&world, entity).is_ok());
}
});
Expand All @@ -167,8 +167,8 @@ pub fn world_query_get(criterion: &mut Criterion) {
)>();

bencher.iter(|| {
for i in 0..entity_count {
let entity = Entity::from_raw(i);
for i in 1..=entity_count {
let entity = Entity::from_raw(i).unwrap();
assert!(query.get(&world, entity).is_ok());
}
});
Expand Down
18 changes: 14 additions & 4 deletions crates/bevy_ecs/src/entity/map_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<'m> EntityMapper<'m> {
// SAFETY: Entities data is kept in a valid state via `EntityMap::world_scope`
let entities = unsafe { world.entities_mut() };
assert!(entities.free(self.dead_start).is_some());
assert!(entities.reserve_generations(self.dead_start.index, self.generations));
assert!(entities.reserve_generations(self.dead_start.index(), self.generations));
}

/// Creates an [`EntityMapper`] from a provided [`World`] and [`HashMap<Entity, Entity>`], then calls the
Expand All @@ -131,6 +131,8 @@ impl<'m> EntityMapper<'m> {

#[cfg(test)]
mod tests {
use std::num::NonZeroU32;

use bevy_utils::HashMap;

use crate::{
Expand All @@ -140,8 +142,16 @@ mod tests {

#[test]
fn entity_mapper() {
const FIRST_IDX: u32 = 1;
const SECOND_IDX: u32 = 2;
const FIRST_IDX: NonZeroU32 = if let Some(v) = NonZeroU32::new(1) {
v
} else {
panic!("1 != 0")
};
const SECOND_IDX: NonZeroU32 = if let Some(v) = NonZeroU32::new(2) {
v
} else {
panic!("2 != 0")
};

let mut map = HashMap::default();
let mut world = World::new();
Expand Down Expand Up @@ -174,7 +184,7 @@ mod tests {
let mut world = World::new();

let dead_ref = EntityMapper::world_scope(&mut map, &mut world, |_, mapper| {
mapper.get_or_reserve(Entity::new(0, 0))
mapper.get_or_reserve(Entity::new(NonZeroU32::MIN, 0))
});

// Next allocated entity should be a further generation on the same index
Expand Down
Loading