Skip to content

Commit 0ea5f15

Browse files
BoxyUwUmrk-its
authored andcommitted
Bump entities to u128 to avoid collisions (bevyengine#117) (bevyengine#393)
1 parent c8cd47c commit 0ea5f15

File tree

10 files changed

+19
-19
lines changed

10 files changed

+19
-19
lines changed

crates/bevy_ecs/hecs/src/archetype.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct Archetype {
3838
types: Vec<TypeInfo>,
3939
state: HashMap<TypeId, TypeState>,
4040
len: u32,
41-
entities: Box<[u32]>,
41+
entities: Box<[u128]>,
4242
// UnsafeCell allows unique references into `data` to be constructed while shared references
4343
// containing the `Archetype` exist
4444
data: UnsafeCell<NonNull<u8>>,
@@ -226,16 +226,16 @@ impl Archetype {
226226
}
227227

228228
#[allow(missing_docs)]
229-
pub fn iter_entities(&self) -> impl Iterator<Item = &u32> {
229+
pub fn iter_entities(&self) -> impl Iterator<Item = &u128> {
230230
self.entities.iter().take(self.len as usize)
231231
}
232232

233233
#[inline]
234-
pub(crate) fn entities(&self) -> NonNull<u32> {
234+
pub(crate) fn entities(&self) -> NonNull<u128> {
235235
unsafe { NonNull::new_unchecked(self.entities.as_ptr() as *mut _) }
236236
}
237237

238-
pub(crate) fn entity_id(&self, index: u32) -> u32 {
238+
pub(crate) fn entity_id(&self, index: u32) -> u128 {
239239
self.entities[index as usize]
240240
}
241241

@@ -263,7 +263,7 @@ impl Archetype {
263263

264264
/// # Safety
265265
/// Every type must be written immediately after this call
266-
pub unsafe fn allocate(&mut self, id: u32) -> u32 {
266+
pub unsafe fn allocate(&mut self, id: u128) -> u32 {
267267
if self.len as usize == self.entities.len() {
268268
self.grow(self.len.max(self.grow_size));
269269
}
@@ -341,7 +341,7 @@ impl Archetype {
341341
}
342342

343343
/// Returns the ID of the entity moved into `index`, if any
344-
pub(crate) unsafe fn remove(&mut self, index: u32) -> Option<u32> {
344+
pub(crate) unsafe fn remove(&mut self, index: u32) -> Option<u128> {
345345
let last = self.len - 1;
346346
for ty in &self.types {
347347
let removed = self
@@ -380,7 +380,7 @@ impl Archetype {
380380
&mut self,
381381
index: u32,
382382
mut f: impl FnMut(*mut u8, TypeId, usize, bool, bool),
383-
) -> Option<u32> {
383+
) -> Option<u128> {
384384
let last = self.len - 1;
385385
for ty in &self.types {
386386
let moved = self

crates/bevy_ecs/hecs/src/entities.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ use std::error::Error;
99
///
1010
/// Obtained from `World::spawn`. Can be stored to refer to an entity in the future.
1111
#[derive(Debug, Clone, Copy, Hash, Eq, Ord, PartialEq, PartialOrd)]
12-
pub struct Entity(u32);
12+
pub struct Entity(u128);
1313

1414
#[allow(clippy::new_without_default)]
1515
impl Entity {
1616
#[allow(missing_docs)]
1717
pub fn new() -> Self {
18-
Self(rand::random::<u32>())
18+
Self(rand::random::<u128>())
1919
}
2020

2121
#[allow(missing_docs)]
2222
#[inline]
23-
pub fn from_id(id: u32) -> Self {
23+
pub fn from_id(id: u128) -> Self {
2424
Self(id)
2525
}
2626

@@ -30,7 +30,7 @@ impl Entity {
3030
/// with both live and dead entities. Useful for compactly representing entities within a
3131
/// specific snapshot of the world, such as when serializing.
3232
#[inline]
33-
pub fn id(self) -> u32 {
33+
pub fn id(self) -> u128 {
3434
self.0
3535
}
3636
}

crates/bevy_ecs/hecs/src/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub enum Access {
7676
}
7777

7878
#[derive(Copy, Clone, Debug)]
79-
pub struct EntityFetch(NonNull<u32>);
79+
pub struct EntityFetch(NonNull<u128>);
8080

8181
impl Query for Entity {
8282
type Fetch = EntityFetch;

crates/bevy_ecs/hecs/src/serde.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ impl Serialize for Entity {
88
where
99
S: Serializer,
1010
{
11-
serializer.serialize_u32(self.id())
11+
serializer.serialize_u128(self.id())
1212
}
1313
}

crates/bevy_ecs/src/resource/resources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Resources {
9494
use std::cmp::Ordering;
9595
match index.cmp(&archetype.len()) {
9696
Ordering::Equal => {
97-
unsafe { archetype.allocate(index) };
97+
unsafe { archetype.allocate(index as u128) };
9898
}
9999
Ordering::Greater => panic!("attempted to access index beyond 'current_capacity + 1'"),
100100
Ordering::Less => (),

crates/bevy_property/src/impl_property/impl_property_bevy_ecs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ impl_property!(Entity, serialize_entity, deserialize_entity);
88
mod private {
99
use serde::{Deserialize, Serialize};
1010
#[derive(Serialize, Deserialize)]
11-
pub(super) struct Entity(pub(super) u32);
11+
pub(super) struct Entity(pub(super) u128);
1212
}
1313

1414
fn serialize_entity(entity: &Entity) -> Serializable {

crates/bevy_scene/src/scene.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct Scene {
1111
}
1212

1313
pub struct Entity {
14-
pub entity: u32,
14+
pub entity: u128,
1515
pub components: Vec<DynamicProperties>,
1616
}
1717

crates/bevy_scene/src/scene_spawner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use thiserror::Error;
88
use uuid::Uuid;
99

1010
struct InstanceInfo {
11-
entity_map: HashMap<u32, bevy_ecs::Entity>,
11+
entity_map: HashMap<u128, bevy_ecs::Entity>,
1212
}
1313

1414
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]

crates/bevy_scene/src/serde.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'a, 'de> Visitor<'de> for SceneEntityVisiter<'a> {
182182
if id.is_some() {
183183
return Err(Error::duplicate_field(ENTITY_FIELD_ENTITY));
184184
}
185-
id = Some(map.next_value::<u32>()?);
185+
id = Some(map.next_value::<u128>()?);
186186
}
187187
EntityField::Components => {
188188
if components.is_some() {

crates/bevy_transform/src/components/parent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct Parent(pub Entity);
1111
// ways to handle cases like this.
1212
impl FromResources for Parent {
1313
fn from_resources(_resources: &bevy_ecs::Resources) -> Self {
14-
Parent(Entity::from_id(u32::MAX))
14+
Parent(Entity::from_id(u128::MAX))
1515
}
1616
}
1717

0 commit comments

Comments
 (0)