Skip to content

Commit

Permalink
Use all 64-bits of the Entity for a hash all the time.
Browse files Browse the repository at this point in the history
Fixes PassHash only using Entity.index.
  • Loading branch information
superdump committed Sep 26, 2023
1 parent c3ef067 commit ad94257
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 8 additions & 2 deletions crates/bevy_ecs/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::{
storage::{SparseSetIndex, TableId, TableRow},
};
use serde::{Deserialize, Serialize};
use std::{convert::TryFrom, fmt, mem, sync::atomic::Ordering};
use std::{convert::TryFrom, fmt, hash::Hash, mem, sync::atomic::Ordering};

#[cfg(target_has_atomic = "64")]
use std::sync::atomic::AtomicI64 as AtomicIdCursor;
Expand Down Expand Up @@ -115,12 +115,18 @@ type IdCursor = isize;
/// [`EntityCommands`]: crate::system::EntityCommands
/// [`Query::get`]: crate::system::Query::get
/// [`World`]: crate::world::World
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
pub struct Entity {
generation: u32,
index: u32,
}

impl Hash for Entity {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.to_bits().hash(state);
}
}

pub(crate) enum AllocAtWithoutReplacement {
Exists(EntityLocation),
DidNotExist,
Expand Down
5 changes: 0 additions & 5 deletions crates/bevy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,6 @@ impl Hasher for PassHasher {
panic!("can only hash u64 using PassHasher");
}

#[inline]
fn write_u32(&mut self, i: u32) {
self.hash = i as u64;
}

#[inline]
fn write_u64(&mut self, i: u64) {
self.hash = i;
Expand Down

0 comments on commit ad94257

Please sign in to comment.