Implement SystemParam for WorldId (#7741)
				
					
				
			# Objective Fixes #7736 ## Solution Implement the `SystemParam` trait for `WorldId` ## Changelog - `WorldId` can now be taken as a system parameter and will return the id of the world the system is running in
This commit is contained in:
		
							parent
							
								
									5a66d035e2
								
							
						
					
					
						commit
						64b0f19a65
					
				@ -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)]
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user