diff --git a/benches/common/heavy_compute.rs b/benches/common/heavy_compute.rs index 8938638..8d1d768 100644 --- a/benches/common/heavy_compute.rs +++ b/benches/common/heavy_compute.rs @@ -10,15 +10,6 @@ component! { velocity: Vec3, } -#[derive(Copy, Clone)] -struct Position(Vec3); - -#[derive(Copy, Clone)] -struct Rotation(Vec3); - -#[derive(Copy, Clone)] -struct Velocity(Vec3); - pub struct Benchmark(World); impl Benchmark { diff --git a/benches/common/simple_iter.rs b/benches/common/simple_iter.rs index 51a2889..491bd2e 100644 --- a/benches/common/simple_iter.rs +++ b/benches/common/simple_iter.rs @@ -11,7 +11,7 @@ component! { velocity: Vec3, } -pub struct Benchmark(World, Query<(Component, Mutable)>); +pub struct Benchmark(World); impl Benchmark { pub fn new() -> Self { @@ -27,8 +27,7 @@ impl Benchmark { batch.set(velocity(), repeat(Vec3::X)).unwrap(); batch.spawn(&mut world); - let query = Query::new((velocity(), position().as_mut())); - Self(world, query) + Self(world) } pub fn run(&mut self) { diff --git a/src/entity/mod.rs b/src/entity/mod.rs index 41801b0..66eae2a 100644 --- a/src/entity/mod.rs +++ b/src/entity/mod.rs @@ -104,6 +104,28 @@ impl Entity { pub fn kind(&self) -> EntityKind { self.kind } + + /// Returns a bit representation of the entity + pub fn as_bits(&self) -> u64 { + let index = self.index as u64; + let gen = self.gen.get() as u64; + let kind = self.kind.bits() as u64; + + (index << 32) | (gen << 16) | kind + } + + /// Reconstruct an entity from its bit representation + pub fn try_from_bits(mut bits: u64) -> Option { + let kind = EntityKind::from_bits(bits as u16).unwrap(); + bits >>= 16; + + let gen = EntityGen::new(bits as u16).unwrap(); + bits >>= 16; + + let index = bits as u32; + + Some(Entity { index, gen, kind }) + } } #[cfg(feature = "serde")] @@ -300,4 +322,14 @@ mod tests { assert_eq!(align_of::(), 4); assert_eq!(size_of::>(), 8); } + + #[test] + fn test_bitcasts() { + let mut store = EntityStore::new(EntityKind::COMPONENT); + + let a = store.spawn("a"); + + let a2 = Entity::try_from_bits(a.as_bits()).unwrap(); + assert_eq!(a, a2); + } } diff --git a/src/fetch/mod.rs b/src/fetch/mod.rs index 7a5b571..99c8683 100644 --- a/src/fetch/mod.rs +++ b/src/fetch/mod.rs @@ -4,7 +4,7 @@ mod component; mod component_mut; mod copied; mod entity_ref; -pub mod expect; +mod expect; mod ext; mod map; mod maybe_mut; @@ -33,6 +33,7 @@ pub use component::*; pub use component_mut::*; pub use copied::*; pub use entity_ref::*; +pub use expect::*; pub use ext::FetchExt; pub use map::Map; pub use maybe_mut::{MaybeMut, MutGuard}; diff --git a/src/system/context.rs b/src/system/context.rs index f656f46..d6fa66c 100644 --- a/src/system/context.rs +++ b/src/system/context.rs @@ -11,11 +11,8 @@ use crate::{ use super::{input::ExtractDyn, SystemAccess, SystemData}; /// A resource that can be shared between systems -/// The difference between this and an `Arc>` is that this will be -/// taken into consideration when multithreading in the schedule, and will as -/// such not require locks. /// -/// The implementation is an `Arc` and is thus cheap to clone +/// Used for safe multithreaded scheduling #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct SharedResource(Arc>);