mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
Add more FromWorld implementations (#3945)
# Objective Make `FromWorld` more useful for abstractions with a form similar to ```rs trait FancyAbstraction { type PreInitializedData: FromWorld; } ``` ## Solution Add a `FromWorld` implementation for `SystemState` as well as a way to group together multiple `FromWorld` implementing types as one. Note: I plan to follow up this PR with another to add `Local` support to exclusive systems, which should get a fair amount of use from the `FromWorld` implementation on `SystemState`.
This commit is contained in:
parent
ea6e6f7db2
commit
73edb11db6
2 changed files with 17 additions and 0 deletions
|
@ -2,6 +2,7 @@ use crate::{
|
|||
archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId},
|
||||
component::ComponentId,
|
||||
entity::Entity,
|
||||
prelude::FromWorld,
|
||||
query::{
|
||||
Access, Fetch, FetchState, FilterFetch, FilteredAccess, NopFetch, QueryCombinationIter,
|
||||
QueryIter, WorldQuery,
|
||||
|
@ -32,6 +33,15 @@ where
|
|||
pub(crate) filter_state: F::State,
|
||||
}
|
||||
|
||||
impl<Q: WorldQuery, F: WorldQuery> FromWorld for QueryState<Q, F>
|
||||
where
|
||||
F::Fetch: FilterFetch,
|
||||
{
|
||||
fn from_world(world: &mut World) -> Self {
|
||||
world.query_filtered()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Q: WorldQuery, F: WorldQuery> QueryState<Q, F>
|
||||
where
|
||||
F::Fetch: FilterFetch,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{
|
||||
archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId},
|
||||
component::ComponentId,
|
||||
prelude::FromWorld,
|
||||
query::{Access, FilteredAccessSet},
|
||||
schedule::SystemLabel,
|
||||
system::{
|
||||
|
@ -229,6 +230,12 @@ impl<Param: SystemParam> SystemState<Param> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Param: SystemParam> FromWorld for SystemState<Param> {
|
||||
fn from_world(world: &mut World) -> Self {
|
||||
Self::new(world)
|
||||
}
|
||||
}
|
||||
|
||||
/// Conversion trait to turn something into a [`System`].
|
||||
///
|
||||
/// Use this to get a system from a function. Also note that every system implements this trait as
|
||||
|
|
Loading…
Reference in a new issue