feat(ecs): entity spawning
All checks were successful
Build Zenyx ⚡ / 🧪 Run Cargo Tests (push) Successful in 4m9s
Build Zenyx ⚡ / 🧪 Run Cargo Tests (pull_request) Successful in 4m14s
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (push) Successful in 8m12s
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (push) Successful in 9m13s
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (push) Successful in 9m11s
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (push) Successful in 9m27s
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (pull_request) Successful in 7m51s
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Successful in 8m39s
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Successful in 8m28s
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Successful in 9m7s
All checks were successful
Build Zenyx ⚡ / 🧪 Run Cargo Tests (push) Successful in 4m9s
Build Zenyx ⚡ / 🧪 Run Cargo Tests (pull_request) Successful in 4m14s
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (push) Successful in 8m12s
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (push) Successful in 9m13s
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (push) Successful in 9m11s
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (push) Successful in 9m27s
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (pull_request) Successful in 7m51s
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Successful in 8m39s
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Successful in 8m28s
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Successful in 9m7s
This commit is contained in:
parent
96d44163fc
commit
1b89120b73
1 changed files with 13 additions and 3 deletions
|
@ -27,6 +27,7 @@ where
|
||||||
return *id;
|
return *id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_id = ComponentId(
|
let new_id = ComponentId(
|
||||||
NonZeroU64::new(COMPONENT_ID_CREATOR.fetch_add(1, core::sync::atomic::Ordering::Relaxed))
|
NonZeroU64::new(COMPONENT_ID_CREATOR.fetch_add(1, core::sync::atomic::Ordering::Relaxed))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
@ -48,11 +49,10 @@ pub trait Component: core::fmt::Debug + Send + Sized + 'static {
|
||||||
|
|
||||||
fn id() -> ComponentId {
|
fn id() -> ComponentId {
|
||||||
static COMPONENT_ID: AtomicU64 = AtomicU64::new(0);
|
static COMPONENT_ID: AtomicU64 = AtomicU64::new(0);
|
||||||
// TODO: reevaluate ordering later
|
let mut current_id = COMPONENT_ID.load(core::sync::atomic::Ordering::Relaxed);
|
||||||
let mut current_id = COMPONENT_ID.load(core::sync::atomic::Ordering::SeqCst);
|
|
||||||
if current_id == 0 {
|
if current_id == 0 {
|
||||||
current_id = create_component_id::<Self>().0.into_integer();
|
current_id = create_component_id::<Self>().0.into_integer();
|
||||||
COMPONENT_ID.store(current_id, core::sync::atomic::Ordering::SeqCst);
|
COMPONENT_ID.store(current_id, core::sync::atomic::Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
ComponentId(NonZeroU64::new(current_id).unwrap())
|
ComponentId(NonZeroU64::new(current_id).unwrap())
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,16 @@ pub struct ComponentSet<A = allocator_api2::alloc::Global> {
|
||||||
|
|
||||||
pub struct EntityComponentSystem {
|
pub struct EntityComponentSystem {
|
||||||
components: ComponentSet,
|
components: ComponentSet,
|
||||||
|
next_id: AtomicU64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EntityComponentSystem {
|
||||||
|
fn spawn(&mut self) -> Entity {
|
||||||
|
let entity_id = self
|
||||||
|
.next_id
|
||||||
|
.fetch_add(1, core::sync::atomic::Ordering::Relaxed);
|
||||||
|
Entity(entity_id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComponentSet {
|
impl ComponentSet {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue