use crate::{ prelude::{FromWorld, QueryState}, query::{ReadOnlyWorldQuery, WorldQuery}, system::{Local, LocalState, SystemMeta, SystemParam, SystemState}, world::World, }; use bevy_ecs_macros::all_tuples; use bevy_utils::synccell::SyncCell; pub trait ExclusiveSystemParam: Sized { type Fetch: for<'s> ExclusiveSystemParamFetch<'s>; } pub type ExclusiveSystemParamItem<'s, P> = <
::Fetch as ExclusiveSystemParamFetch<'s>>::Item;
/// The state of a [`SystemParam`].
pub trait ExclusiveSystemParamState: Send + Sync {
fn init(world: &mut World, system_meta: &mut SystemMeta) -> Self;
#[inline]
fn apply(&mut self, _world: &mut World) {}
}
pub trait ExclusiveSystemParamFetch<'state>: ExclusiveSystemParamState {
type Item: ExclusiveSystemParam {
type Fetch = SystemState ;
}
impl<'s, P: SystemParam + 'static> ExclusiveSystemParamFetch<'s> for SystemState {
type Item = &'s mut SystemState ;
fn get_param(state: &'s mut Self, _system_meta: &SystemMeta) -> Self::Item {
state
}
}
impl {
fn init(world: &mut World, _system_meta: &mut SystemMeta) -> Self {
SystemState::new(world)
}
}
impl<'s, T: FromWorld + Send + Sync + 'static> ExclusiveSystemParam for Local<'s, T> {
type Fetch = LocalState
{
type Fetch = QueryState
;
}
impl<'s, Q: WorldQuery + 'static, F: ReadOnlyWorldQuery + 'static> ExclusiveSystemParamFetch<'s>
for QueryState
{
type Item = &'s mut QueryState
;
fn get_param(state: &'s mut Self, _system_meta: &SystemMeta) -> Self::Item {
state
}
}
impl
{
fn init(world: &mut World, _system_meta: &mut SystemMeta) -> Self {
QueryState::new(world)
}
}
impl<'a, P: SystemParam + 'static> ExclusiveSystemParam for &'a mut SystemState