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:
Stepan Koltsov 2024-01-01 15:59:53 +00:00 committed by GitHub
parent 71adb77a2e
commit 9f397d0cb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
use crate::system::{ExclusiveSystemParam, SystemMeta};
use crate::{
component::Tick,
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 {
#[inline]
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.
// #[test]
// #[should_panic]