impl ExclusiveSystemParam for WorldId (#11164)
# Objective Mostly for consistency. ## Solution ```rust impl ExclusiveSystemParam for WorldId ``` - Also add a test for `SystemParam for WorldId` ## Changelog Added: Worldd now implements ExclusiveSystemParam.
This commit is contained in:
parent
71adb77a2e
commit
9f397d0cb6
@ -1,3 +1,4 @@
|
|||||||
|
use crate::system::{ExclusiveSystemParam, SystemMeta};
|
||||||
use crate::{
|
use crate::{
|
||||||
component::Tick,
|
component::Tick,
|
||||||
storage::SparseSetIndex,
|
storage::SparseSetIndex,
|
||||||
@ -65,6 +66,19 @@ unsafe impl SystemParam for WorldId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExclusiveSystemParam for WorldId {
|
||||||
|
type State = WorldId;
|
||||||
|
type Item<'s> = WorldId;
|
||||||
|
|
||||||
|
fn init(world: &mut World, _system_meta: &mut SystemMeta) -> Self::State {
|
||||||
|
world.id()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_param<'s>(state: &'s mut Self::State, _system_meta: &SystemMeta) -> Self::Item<'s> {
|
||||||
|
*state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SparseSetIndex for WorldId {
|
impl SparseSetIndex for WorldId {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sparse_set_index(&self) -> usize {
|
fn sparse_set_index(&self) -> usize {
|
||||||
@ -95,6 +109,30 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn world_id_system_param() {
|
||||||
|
fn test_system(world_id: WorldId) -> WorldId {
|
||||||
|
world_id
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut world = World::default();
|
||||||
|
let system_id = world.register_system(test_system);
|
||||||
|
let world_id = world.run_system(system_id).unwrap();
|
||||||
|
assert_eq!(world.id(), world_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn world_id_exclusive_system_param() {
|
||||||
|
fn test_system(_world: &mut World, world_id: WorldId) -> WorldId {
|
||||||
|
world_id
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut world = World::default();
|
||||||
|
let system_id = world.register_system(test_system);
|
||||||
|
let world_id = world.run_system(system_id).unwrap();
|
||||||
|
assert_eq!(world.id(), world_id);
|
||||||
|
}
|
||||||
|
|
||||||
// We cannot use this test as-is, as it causes other tests to panic due to using the same atomic variable.
|
// We cannot use this test as-is, as it causes other tests to panic due to using the same atomic variable.
|
||||||
// #[test]
|
// #[test]
|
||||||
// #[should_panic]
|
// #[should_panic]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user