Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Implement SystemParam for WorldId #7741

Closed
wants to merge 3 commits into from
Closed
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
26 changes: 25 additions & 1 deletion crates/bevy_ecs/src/world/identifier.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::storage::SparseSetIndex;
use crate::{
storage::SparseSetIndex,
system::{ReadOnlySystemParam, SystemParam},
};
use std::sync::atomic::{AtomicUsize, Ordering};

#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
Expand Down Expand Up @@ -27,6 +30,27 @@ impl WorldId {
}
}

// SAFETY: Has read-only access to shared World metadata
unsafe impl ReadOnlySystemParam for WorldId {}

// SAFETY: A World's ID is immutable and fetching it from the World does not borrow anything
unsafe impl SystemParam for WorldId {
type State = ();

type Item<'world, 'state> = WorldId;

fn init_state(_: &mut super::World, _: &mut crate::system::SystemMeta) -> Self::State {}

unsafe fn get_param<'world, 'state>(
_: &'state mut Self::State,
_: &crate::system::SystemMeta,
world: &'world super::World,
_: u32,
) -> Self::Item<'world, 'state> {
world.id
}
}

impl SparseSetIndex for WorldId {
#[inline]
fn sparse_set_index(&self) -> usize {
Expand Down