mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Adopt a Fetch pattern for SystemParams (#1074)
This commit is contained in:
parent
51650f114f
commit
841755aaf2
94 changed files with 634 additions and 483 deletions
|
@ -24,7 +24,7 @@ impl Default for AppBuilder {
|
|||
app_builder
|
||||
.add_default_stages()
|
||||
.add_event::<AppExit>()
|
||||
.add_system_to_stage(stage::LAST, clear_trackers_system);
|
||||
.add_system_to_stage(stage::LAST, clear_trackers_system.system());
|
||||
app_builder
|
||||
}
|
||||
}
|
||||
|
@ -125,68 +125,48 @@ impl AppBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add_system<S, Params, IntoS>(&mut self, system: IntoS) -> &mut Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
pub fn add_system<S: System<In = (), Out = ()>>(&mut self, system: S) -> &mut Self {
|
||||
self.add_system_to_stage(stage::UPDATE, system)
|
||||
}
|
||||
|
||||
pub fn on_state_enter<T: Clone + Resource, S, Params, IntoS>(
|
||||
pub fn on_state_enter<T: Clone + Resource, S: System<In = (), Out = ()>>(
|
||||
&mut self,
|
||||
stage: &str,
|
||||
state: T,
|
||||
system: IntoS,
|
||||
) -> &mut Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
system: S,
|
||||
) -> &mut Self {
|
||||
self.stage(stage, |stage: &mut StateStage<T>| {
|
||||
stage.on_state_enter(state, system)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn on_state_update<T: Clone + Resource, S, Params, IntoS>(
|
||||
pub fn on_state_update<T: Clone + Resource, S: System<In = (), Out = ()>>(
|
||||
&mut self,
|
||||
stage: &str,
|
||||
state: T,
|
||||
system: IntoS,
|
||||
) -> &mut Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
system: S,
|
||||
) -> &mut Self {
|
||||
self.stage(stage, |stage: &mut StateStage<T>| {
|
||||
stage.on_state_update(state, system)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn on_state_exit<T: Clone + Resource, S, Params, IntoS>(
|
||||
pub fn on_state_exit<T: Clone + Resource, S: System<In = (), Out = ()>>(
|
||||
&mut self,
|
||||
stage: &str,
|
||||
state: T,
|
||||
system: IntoS,
|
||||
) -> &mut Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
system: S,
|
||||
) -> &mut Self {
|
||||
self.stage(stage, |stage: &mut StateStage<T>| {
|
||||
stage.on_state_exit(state, system)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn add_startup_system_to_stage<S, Params, IntoS>(
|
||||
pub fn add_startup_system_to_stage<S: System<In = (), Out = ()>>(
|
||||
&mut self,
|
||||
stage_name: &'static str,
|
||||
system: IntoS,
|
||||
) -> &mut Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
system: S,
|
||||
) -> &mut Self {
|
||||
self.app
|
||||
.schedule
|
||||
.stage(stage::STARTUP, |schedule: &mut Schedule| {
|
||||
|
@ -195,11 +175,7 @@ impl AppBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add_startup_system<S, Params, IntoS>(&mut self, system: IntoS) -> &mut Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
pub fn add_startup_system<S: System<In = (), Out = ()>>(&mut self, system: S) -> &mut Self {
|
||||
self.add_startup_system_to_stage(startup_stage::STARTUP, system)
|
||||
}
|
||||
|
||||
|
@ -221,15 +197,11 @@ impl AppBuilder {
|
|||
.add_stage(stage::LAST, SystemStage::parallel())
|
||||
}
|
||||
|
||||
pub fn add_system_to_stage<S, Params, IntoS>(
|
||||
pub fn add_system_to_stage<S: System<In = (), Out = ()>>(
|
||||
&mut self,
|
||||
stage_name: &'static str,
|
||||
system: IntoS,
|
||||
) -> &mut Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
system: S,
|
||||
) -> &mut Self {
|
||||
self.app.schedule.add_system_to_stage(stage_name, system);
|
||||
self
|
||||
}
|
||||
|
@ -239,7 +211,7 @@ impl AppBuilder {
|
|||
T: Send + Sync + 'static,
|
||||
{
|
||||
self.add_resource(Events::<T>::default())
|
||||
.add_system_to_stage(stage::EVENT, Events::<T>::update_system)
|
||||
.add_system_to_stage(stage::EVENT, Events::<T>::update_system.system())
|
||||
}
|
||||
|
||||
/// Adds a resource to the current [App] and overwrites any resource previously added of the same type.
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
|||
update_asset_storage_system, Asset, AssetLoader, AssetServer, Handle, HandleId, RefChange,
|
||||
};
|
||||
use bevy_app::{prelude::Events, AppBuilder};
|
||||
use bevy_ecs::{FromResources, ResMut};
|
||||
use bevy_ecs::{FromResources, IntoSystem, ResMut};
|
||||
use bevy_reflect::RegisterTypeBuilder;
|
||||
use bevy_utils::HashMap;
|
||||
use crossbeam_channel::Sender;
|
||||
|
@ -218,8 +218,14 @@ impl AddAsset for AppBuilder {
|
|||
};
|
||||
|
||||
self.add_resource(assets)
|
||||
.add_system_to_stage(super::stage::ASSET_EVENTS, Assets::<T>::asset_event_system)
|
||||
.add_system_to_stage(crate::stage::LOAD_ASSETS, update_asset_storage_system::<T>)
|
||||
.add_system_to_stage(
|
||||
super::stage::ASSET_EVENTS,
|
||||
Assets::<T>::asset_event_system.system(),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
crate::stage::LOAD_ASSETS,
|
||||
update_asset_storage_system::<T>.system(),
|
||||
)
|
||||
.register_type::<Handle<T>>()
|
||||
.add_event::<AssetEvent<T>>()
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ mod path;
|
|||
|
||||
pub use asset_server::*;
|
||||
pub use assets::*;
|
||||
use bevy_ecs::SystemStage;
|
||||
use bevy_ecs::{IntoSystem, SystemStage};
|
||||
use bevy_reflect::RegisterTypeBuilder;
|
||||
use bevy_tasks::IoTaskPool;
|
||||
pub use handle::*;
|
||||
|
@ -88,13 +88,13 @@ impl Plugin for AssetPlugin {
|
|||
.register_type::<HandleId>()
|
||||
.add_system_to_stage(
|
||||
bevy_app::stage::PRE_UPDATE,
|
||||
asset_server::free_unused_assets_system,
|
||||
asset_server::free_unused_assets_system.system(),
|
||||
);
|
||||
|
||||
#[cfg(all(
|
||||
feature = "filesystem_watcher",
|
||||
all(not(target_arch = "wasm32"), not(target_os = "android"))
|
||||
))]
|
||||
app.add_system_to_stage(stage::LOAD_ASSETS, io::filesystem_watcher_system);
|
||||
app.add_system_to_stage(stage::LOAD_ASSETS, io::filesystem_watcher_system.system());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ pub mod prelude {
|
|||
|
||||
use bevy_app::prelude::*;
|
||||
use bevy_asset::AddAsset;
|
||||
use bevy_ecs::IntoSystem;
|
||||
|
||||
/// Adds support for audio playback to an App
|
||||
#[derive(Default)]
|
||||
|
@ -23,6 +24,9 @@ impl Plugin for AudioPlugin {
|
|||
.add_asset::<AudioSource>()
|
||||
.init_asset_loader::<Mp3Loader>()
|
||||
.init_resource::<Audio<AudioSource>>()
|
||||
.add_system_to_stage(stage::POST_UPDATE, play_queued_audio_system::<AudioSource>);
|
||||
.add_system_to_stage(
|
||||
stage::POST_UPDATE,
|
||||
play_queued_audio_system::<AudioSource>.system(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ mod time;
|
|||
|
||||
use std::ops::Range;
|
||||
|
||||
use bevy_ecs::IntoSystem;
|
||||
use bevy_reflect::RegisterTypeBuilder;
|
||||
pub use bytes::*;
|
||||
pub use float_ord::*;
|
||||
|
@ -37,7 +38,7 @@ impl Plugin for CorePlugin {
|
|||
.register_type::<Option<String>>()
|
||||
.register_type::<Range<f32>>()
|
||||
.register_type::<Timer>()
|
||||
.add_system_to_stage(stage::FIRST, time_system)
|
||||
.add_system_to_stage(stage::PRE_UPDATE, entity_labels_system);
|
||||
.add_system_to_stage(stage::FIRST, time_system.system())
|
||||
.add_system_to_stage(stage::PRE_UPDATE, entity_labels_system.system());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{Diagnostic, DiagnosticId, Diagnostics};
|
||||
use bevy_app::prelude::*;
|
||||
use bevy_core::Time;
|
||||
use bevy_ecs::{Res, ResMut};
|
||||
use bevy_ecs::{IntoSystem, Res, ResMut};
|
||||
|
||||
/// Adds "frame time" diagnostic to an App, specifically "frame time", "fps" and "frame count"
|
||||
#[derive(Default)]
|
||||
|
@ -13,9 +13,9 @@ pub struct FrameTimeDiagnosticsState {
|
|||
|
||||
impl Plugin for FrameTimeDiagnosticsPlugin {
|
||||
fn build(&self, app: &mut bevy_app::AppBuilder) {
|
||||
app.add_startup_system(Self::setup_system)
|
||||
app.add_startup_system(Self::setup_system.system())
|
||||
.add_resource(FrameTimeDiagnosticsState { frame_count: 0.0 })
|
||||
.add_system(Self::diagnostic_system);
|
||||
.add_system(Self::diagnostic_system.system());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::{Diagnostic, DiagnosticId, Diagnostics};
|
||||
use bevy_app::prelude::*;
|
||||
use bevy_core::{Time, Timer};
|
||||
use bevy_ecs::{Res, ResMut};
|
||||
use bevy_ecs::{IntoSystem, Res, ResMut};
|
||||
use bevy_utils::Duration;
|
||||
|
||||
/// An App Plugin that prints diagnostics to the console
|
||||
|
@ -35,9 +35,12 @@ impl Plugin for PrintDiagnosticsPlugin {
|
|||
});
|
||||
|
||||
if self.debug {
|
||||
app.add_system_to_stage(stage::POST_UPDATE, Self::print_diagnostics_debug_system);
|
||||
app.add_system_to_stage(
|
||||
stage::POST_UPDATE,
|
||||
Self::print_diagnostics_debug_system.system(),
|
||||
);
|
||||
} else {
|
||||
app.add_system_to_stage(stage::POST_UPDATE, Self::print_diagnostics_system);
|
||||
app.add_system_to_stage(stage::POST_UPDATE, Self::print_diagnostics_system.system());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -411,21 +411,27 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream {
|
|||
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||
|
||||
let struct_name = &ast.ident;
|
||||
let fetch_struct_name = Ident::new(&format!("Fetch{}", struct_name), Span::call_site());
|
||||
|
||||
TokenStream::from(quote! {
|
||||
impl #impl_generics #path::SystemParam<()> for #struct_name#ty_generics #where_clause {
|
||||
pub struct #fetch_struct_name;
|
||||
impl #impl_generics #path::SystemParam for #struct_name#ty_generics #where_clause {
|
||||
type Fetch = #fetch_struct_name;
|
||||
}
|
||||
|
||||
impl #impl_generics #path::FetchSystemParam<'a> for #fetch_struct_name {
|
||||
type Item = #struct_name#ty_generics;
|
||||
fn init(system_state: &mut #path::SystemState, world: &#path::World, resources: &mut #path::Resources) {
|
||||
#(<#field_types as SystemParam<()>>::init(system_state, world, resources);)*
|
||||
#(<<#field_types as SystemParam>::Fetch as #path::FetchSystemParam>::init(system_state, world, resources);)*
|
||||
}
|
||||
|
||||
unsafe fn get_param(
|
||||
input: &mut Option<()>,
|
||||
system_state: &mut #path::SystemState,
|
||||
world: &#path::World,
|
||||
resources: &#path::Resources,
|
||||
) -> Option<Self> {
|
||||
system_state: &'a #path::SystemState,
|
||||
world: &'a #path::World,
|
||||
resources: &'a #path::Resources,
|
||||
) -> Option<Self::Item> {
|
||||
Some(#struct_name {
|
||||
#(#fields: <#field_types as SystemParam<()>>::get_param(input, system_state, world, resources)?,)*
|
||||
#(#fields: <<#field_types as SystemParam>::Fetch as #path::FetchSystemParam>::get_param(system_state, world, resources)?,)*
|
||||
#(#ignored_fields: <#ignored_field_types>::default(),)*
|
||||
})
|
||||
}
|
||||
|
|
|
@ -33,33 +33,24 @@ impl Schedule {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_run_criteria<S, Params, IntoS>(mut self, system: IntoS) -> Self
|
||||
where
|
||||
S: System<In = (), Out = ShouldRun>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
pub fn with_run_criteria<S: System<In = (), Out = ShouldRun>>(mut self, system: S) -> Self {
|
||||
self.set_run_criteria(system);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_system_in_stage<S, Params, IntoS>(
|
||||
pub fn with_system_in_stage<S: System<In = (), Out = ()>>(
|
||||
mut self,
|
||||
stage_name: &'static str,
|
||||
system: IntoS,
|
||||
) -> Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
system: S,
|
||||
) -> Self {
|
||||
self.add_system_to_stage(stage_name, system);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_run_criteria<S, Params, IntoS>(&mut self, system: IntoS) -> &mut Self
|
||||
where
|
||||
S: System<In = (), Out = ShouldRun>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
pub fn set_run_criteria<S: System<In = (), Out = ShouldRun>>(
|
||||
&mut self,
|
||||
system: S,
|
||||
) -> &mut Self {
|
||||
self.run_criteria = Some(Box::new(system.system()));
|
||||
self.run_criteria_initialized = false;
|
||||
self
|
||||
|
@ -107,15 +98,11 @@ impl Schedule {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add_system_to_stage<S, Params, IntoS>(
|
||||
pub fn add_system_to_stage<S: System<In = (), Out = ()>>(
|
||||
&mut self,
|
||||
stage_name: &'static str,
|
||||
system: IntoS,
|
||||
) -> &mut Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
system: S,
|
||||
) -> &mut Self {
|
||||
let stage = self
|
||||
.get_stage_mut::<SystemStage>(stage_name)
|
||||
.unwrap_or_else(|| {
|
||||
|
@ -124,7 +111,7 @@ impl Schedule {
|
|||
stage_name
|
||||
)
|
||||
});
|
||||
stage.add_system(system);
|
||||
stage.add_system(system.system());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -221,7 +208,7 @@ mod tests {
|
|||
resource::{Res, ResMut, Resources},
|
||||
schedule::{ParallelSystemStageExecutor, Schedule, SystemStage},
|
||||
system::Query,
|
||||
Commands, Entity, World,
|
||||
Commands, Entity, IntoSystem, World,
|
||||
};
|
||||
use bevy_tasks::{ComputeTaskPool, TaskPool};
|
||||
use fixedbitset::FixedBitSet;
|
||||
|
@ -255,10 +242,10 @@ mod tests {
|
|||
|
||||
let mut schedule = Schedule::default();
|
||||
let mut pre_archetype_change = SystemStage::parallel();
|
||||
pre_archetype_change.add_system(insert);
|
||||
pre_archetype_change.add_system(insert.system());
|
||||
schedule.add_stage("PreArchetypeChange", pre_archetype_change);
|
||||
let mut post_archetype_change = SystemStage::parallel();
|
||||
post_archetype_change.add_system(read);
|
||||
post_archetype_change.add_system(read.system());
|
||||
schedule.add_stage("PostArchetypeChange", post_archetype_change);
|
||||
|
||||
schedule.initialize_and_run(&mut world, &mut resources);
|
||||
|
@ -285,8 +272,8 @@ mod tests {
|
|||
}
|
||||
|
||||
let mut update = SystemStage::parallel();
|
||||
update.add_system(insert);
|
||||
update.add_system(read);
|
||||
update.add_system(insert.system());
|
||||
update.add_system(read.system());
|
||||
|
||||
let mut schedule = Schedule::default();
|
||||
schedule.add_stage("update", update);
|
||||
|
@ -356,10 +343,10 @@ mod tests {
|
|||
completed_systems.insert(READ_U64_SYSTEM_NAME);
|
||||
}
|
||||
|
||||
stage_a.add_system(read_u32);
|
||||
stage_a.add_system(write_float);
|
||||
stage_a.add_system(read_u32_write_u64);
|
||||
stage_a.add_system(read_u64);
|
||||
stage_a.add_system(read_u32.system());
|
||||
stage_a.add_system(write_float.system());
|
||||
stage_a.add_system(read_u32_write_u64.system());
|
||||
stage_a.add_system(read_u64.system());
|
||||
|
||||
// B systems
|
||||
|
||||
|
@ -387,9 +374,9 @@ mod tests {
|
|||
completed_systems.insert(WRITE_F32_SYSTEM_NAME);
|
||||
}
|
||||
|
||||
stage_b.add_system(write_u64);
|
||||
stage_b.add_system(thread_local_system);
|
||||
stage_b.add_system(write_f32);
|
||||
stage_b.add_system(write_u64.system());
|
||||
stage_b.add_system(thread_local_system.system());
|
||||
stage_b.add_system(write_f32.system());
|
||||
|
||||
// C systems
|
||||
|
||||
|
@ -424,10 +411,10 @@ mod tests {
|
|||
completed_systems.insert(WRITE_F64_RES_SYSTEM_NAME);
|
||||
}
|
||||
|
||||
stage_c.add_system(read_f64_res);
|
||||
stage_c.add_system(read_isize_res);
|
||||
stage_c.add_system(read_isize_write_f64_res);
|
||||
stage_c.add_system(write_f64_res);
|
||||
stage_c.add_system(read_f64_res.system());
|
||||
stage_c.add_system(read_isize_res.system());
|
||||
stage_c.add_system(read_isize_write_f64_res.system());
|
||||
stage_c.add_system(write_f64_res.system());
|
||||
|
||||
fn run_and_validate(schedule: &mut Schedule, world: &mut World, resources: &mut Resources) {
|
||||
schedule.initialize_and_run(world, resources);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use std::{any::TypeId, borrow::Cow};
|
||||
|
||||
use crate::{
|
||||
ArchetypeComponent, IntoSystem, Resources, System, SystemId, ThreadLocalExecution, TypeAccess,
|
||||
World,
|
||||
ArchetypeComponent, Resources, System, SystemId, ThreadLocalExecution, TypeAccess, World,
|
||||
};
|
||||
use bevy_utils::HashSet;
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
|
@ -47,9 +46,7 @@ impl SystemStage {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn single<Params, S: System<In = (), Out = ()>, Into: IntoSystem<Params, S>>(
|
||||
system: Into,
|
||||
) -> Self {
|
||||
pub fn single<S: System<In = (), Out = ()>>(system: S) -> Self {
|
||||
Self::serial().with_system(system)
|
||||
}
|
||||
|
||||
|
@ -61,31 +58,19 @@ impl SystemStage {
|
|||
Self::new(Box::new(ParallelSystemStageExecutor::default()))
|
||||
}
|
||||
|
||||
pub fn with_system<S, Params, IntoS>(mut self, system: IntoS) -> Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
self.add_system_boxed(Box::new(system.system()));
|
||||
pub fn with_system<S: System<In = (), Out = ()>>(mut self, system: S) -> Self {
|
||||
self.add_system_boxed(Box::new(system));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_run_criteria<S, Params, IntoS>(mut self, system: IntoS) -> Self
|
||||
where
|
||||
S: System<In = (), Out = ShouldRun>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
self.run_criteria = Some(Box::new(system.system()));
|
||||
pub fn with_run_criteria<S: System<In = (), Out = ShouldRun>>(mut self, system: S) -> Self {
|
||||
self.run_criteria = Some(Box::new(system));
|
||||
self.run_criteria_initialized = false;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_system<S, Params, IntoS>(&mut self, system: IntoS) -> &mut Self
|
||||
where
|
||||
S: System<In = (), Out = ()>,
|
||||
IntoS: IntoSystem<Params, S>,
|
||||
{
|
||||
self.add_system_boxed(Box::new(system.system()));
|
||||
pub fn add_system<S: System<In = (), Out = ()>>(&mut self, system: S) -> &mut Self {
|
||||
self.add_system_boxed(Box::new(system));
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{IntoSystem, Resource, Resources, Stage, System, SystemStage, World};
|
||||
use crate::{Resource, Resources, Stage, System, SystemStage, World};
|
||||
use bevy_utils::HashMap;
|
||||
use std::{mem::Discriminant, ops::Deref};
|
||||
use thiserror::Error;
|
||||
|
@ -51,30 +51,30 @@ impl<T> StateStage<T> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn on_state_enter<Params, S: System<In = (), Out = ()>, IntoS: IntoSystem<Params, S>>(
|
||||
pub fn on_state_enter<S: System<In = (), Out = ()>>(
|
||||
&mut self,
|
||||
state: T,
|
||||
system: IntoS,
|
||||
system: S,
|
||||
) -> &mut Self {
|
||||
self.enter_stage(state, |system_stage: &mut SystemStage| {
|
||||
system_stage.add_system(system)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn on_state_exit<Params, S: System<In = (), Out = ()>, IntoS: IntoSystem<Params, S>>(
|
||||
pub fn on_state_exit<S: System<In = (), Out = ()>>(
|
||||
&mut self,
|
||||
state: T,
|
||||
system: IntoS,
|
||||
system: S,
|
||||
) -> &mut Self {
|
||||
self.exit_stage(state, |system_stage: &mut SystemStage| {
|
||||
system_stage.add_system(system)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn on_state_update<Params, S: System<In = (), Out = ()>, IntoS: IntoSystem<Params, S>>(
|
||||
pub fn on_state_update<S: System<In = (), Out = ()>>(
|
||||
&mut self,
|
||||
state: T,
|
||||
system: IntoS,
|
||||
system: S,
|
||||
) -> &mut Self {
|
||||
self.update_stage(state, |system_stage: &mut SystemStage| {
|
||||
system_stage.add_system(system)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use super::system_param::FetchSystemParam;
|
||||
use crate::{
|
||||
ArchetypeComponent, Commands, QueryAccess, Resources, System, SystemId, SystemParam,
|
||||
ThreadLocalExecution, TypeAccess, World,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use std::{any::TypeId, borrow::Cow, sync::Arc};
|
||||
use std::{any::TypeId, borrow::Cow, cell::UnsafeCell, sync::Arc};
|
||||
|
||||
pub struct SystemState {
|
||||
pub(crate) id: SystemId,
|
||||
|
@ -14,14 +15,20 @@ pub struct SystemState {
|
|||
pub(crate) query_archetype_component_accesses: Vec<TypeAccess<ArchetypeComponent>>,
|
||||
pub(crate) query_accesses: Vec<Vec<QueryAccess>>,
|
||||
pub(crate) query_type_names: Vec<&'static str>,
|
||||
pub(crate) commands: Commands,
|
||||
pub(crate) commands: UnsafeCell<Commands>,
|
||||
pub(crate) arc_commands: Option<Arc<Mutex<Commands>>>,
|
||||
pub(crate) current_query_index: usize,
|
||||
pub(crate) current_query_index: UnsafeCell<usize>,
|
||||
}
|
||||
|
||||
// SAFE: UnsafeCell<Commands> and UnsafeCell<usize> only accessed from the thread they are scheduled on
|
||||
unsafe impl Sync for SystemState {}
|
||||
|
||||
impl SystemState {
|
||||
pub fn reset_indices(&mut self) {
|
||||
self.current_query_index = 0;
|
||||
// SAFE: done with unique mutable access to Self
|
||||
unsafe {
|
||||
*self.current_query_index.get() = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, world: &World) {
|
||||
|
@ -72,7 +79,62 @@ impl SystemState {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct FuncSystem<In, Out> {
|
||||
pub struct FuncSystem<Out> {
|
||||
func:
|
||||
Box<dyn FnMut(&mut SystemState, &World, &Resources) -> Option<Out> + Send + Sync + 'static>,
|
||||
thread_local_func:
|
||||
Box<dyn FnMut(&mut SystemState, &mut World, &mut Resources) + Send + Sync + 'static>,
|
||||
init_func: Box<dyn FnMut(&mut SystemState, &World, &mut Resources) + Send + Sync + 'static>,
|
||||
state: SystemState,
|
||||
}
|
||||
|
||||
impl<Out: 'static> System for FuncSystem<Out> {
|
||||
type In = ();
|
||||
type Out = Out;
|
||||
|
||||
fn name(&self) -> std::borrow::Cow<'static, str> {
|
||||
self.state.name.clone()
|
||||
}
|
||||
|
||||
fn id(&self) -> SystemId {
|
||||
self.state.id
|
||||
}
|
||||
|
||||
fn update(&mut self, world: &World) {
|
||||
self.state.update(world);
|
||||
}
|
||||
|
||||
fn archetype_component_access(&self) -> &TypeAccess<ArchetypeComponent> {
|
||||
&self.state.archetype_component_access
|
||||
}
|
||||
|
||||
fn resource_access(&self) -> &TypeAccess<std::any::TypeId> {
|
||||
&self.state.resource_access
|
||||
}
|
||||
|
||||
fn thread_local_execution(&self) -> ThreadLocalExecution {
|
||||
ThreadLocalExecution::NextFlush
|
||||
}
|
||||
|
||||
unsafe fn run_unsafe(
|
||||
&mut self,
|
||||
_input: Self::In,
|
||||
world: &World,
|
||||
resources: &Resources,
|
||||
) -> Option<Out> {
|
||||
(self.func)(&mut self.state, world, resources)
|
||||
}
|
||||
|
||||
fn run_thread_local(&mut self, world: &mut World, resources: &mut Resources) {
|
||||
(self.thread_local_func)(&mut self.state, world, resources)
|
||||
}
|
||||
|
||||
fn initialize(&mut self, world: &mut World, resources: &mut Resources) {
|
||||
(self.init_func)(&mut self.state, world, resources);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InputFuncSystem<In, Out> {
|
||||
func: Box<
|
||||
dyn FnMut(In, &mut SystemState, &World, &Resources) -> Option<Out> + Send + Sync + 'static,
|
||||
>,
|
||||
|
@ -82,7 +144,7 @@ pub struct FuncSystem<In, Out> {
|
|||
state: SystemState,
|
||||
}
|
||||
|
||||
impl<In: 'static, Out: 'static> System for FuncSystem<In, Out> {
|
||||
impl<In: 'static, Out: 'static> System for InputFuncSystem<In, Out> {
|
||||
type In = In;
|
||||
type Out = Out;
|
||||
|
||||
|
@ -138,16 +200,21 @@ impl<Sys: System> IntoSystem<(), Sys> for Sys {
|
|||
self
|
||||
}
|
||||
}
|
||||
pub struct In<In>(pub In);
|
||||
|
||||
macro_rules! impl_into_system {
|
||||
($($param: ident),*) => {
|
||||
impl<Func, In, Out, $($param: SystemParam<In>),*> IntoSystem<($($param,)*), FuncSystem<In, Out>> for Func
|
||||
where Func: FnMut($($param),*) -> Out + Send + Sync + 'static, Out: 'static, In: 'static
|
||||
impl<Func, Out, $($param: SystemParam),*> IntoSystem<($($param,)*), FuncSystem<Out>> for Func
|
||||
where
|
||||
Func:
|
||||
FnMut($($param),*) -> Out +
|
||||
FnMut($(<<$param as SystemParam>::Fetch as FetchSystemParam>::Item),*) -> Out +
|
||||
Send + Sync + 'static, Out: 'static
|
||||
{
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_unsafe)]
|
||||
#[allow(non_snake_case)]
|
||||
fn system(mut self) -> FuncSystem<In, Out> {
|
||||
fn system(mut self) -> FuncSystem<Out> {
|
||||
FuncSystem {
|
||||
state: SystemState {
|
||||
name: std::any::type_name::<Self>().into(),
|
||||
|
@ -155,18 +222,18 @@ macro_rules! impl_into_system {
|
|||
resource_access: TypeAccess::default(),
|
||||
local_resource_access: TypeAccess::default(),
|
||||
id: SystemId::new(),
|
||||
commands: Commands::default(),
|
||||
commands: Default::default(),
|
||||
arc_commands: Default::default(),
|
||||
current_query_index: Default::default(),
|
||||
query_archetype_component_accesses: Vec::new(),
|
||||
query_accesses: Vec::new(),
|
||||
query_type_names: Vec::new(),
|
||||
current_query_index: 0,
|
||||
},
|
||||
func: Box::new(move |input, state, world, resources| {
|
||||
func: Box::new(move |state, world, resources| {
|
||||
state.reset_indices();
|
||||
let mut input = Some(input);
|
||||
// let mut input = Some(input);
|
||||
unsafe {
|
||||
if let Some(($($param,)*)) = <($($param,)*)>::get_param(&mut input, state, world, resources) {
|
||||
if let Some(($($param,)*)) = <<($($param,)*) as SystemParam>::Fetch as FetchSystemParam>::get_param(state, world, resources) {
|
||||
Some(self($($param),*))
|
||||
} else {
|
||||
None
|
||||
|
@ -174,14 +241,69 @@ macro_rules! impl_into_system {
|
|||
}
|
||||
}),
|
||||
thread_local_func: Box::new(|state, world, resources| {
|
||||
state.commands.apply(world, resources);
|
||||
// SAFE: this is called with unique access to SystemState
|
||||
unsafe {
|
||||
(&mut *state.commands.get()).apply(world, resources);
|
||||
}
|
||||
if let Some(ref commands) = state.arc_commands {
|
||||
let mut commands = commands.lock();
|
||||
commands.apply(world, resources);
|
||||
}
|
||||
}),
|
||||
init_func: Box::new(|state, world, resources| {
|
||||
$($param::init(state, world, resources);)*
|
||||
<<($($param,)*) as SystemParam>::Fetch as FetchSystemParam>::init(state, world, resources)
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<Func, Input, Out, $($param: SystemParam),*> IntoSystem<(Input, $($param,)*), InputFuncSystem<Input, Out>> for Func
|
||||
where
|
||||
Func:
|
||||
FnMut(In<Input>, $($param),*) -> Out +
|
||||
FnMut(In<Input>, $(<<$param as SystemParam>::Fetch as FetchSystemParam>::Item),*) -> Out +
|
||||
Send + Sync + 'static, Input: 'static, Out: 'static
|
||||
{
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_unsafe)]
|
||||
#[allow(non_snake_case)]
|
||||
fn system(mut self) -> InputFuncSystem<Input, Out> {
|
||||
InputFuncSystem {
|
||||
state: SystemState {
|
||||
name: std::any::type_name::<Self>().into(),
|
||||
archetype_component_access: TypeAccess::default(),
|
||||
resource_access: TypeAccess::default(),
|
||||
local_resource_access: TypeAccess::default(),
|
||||
id: SystemId::new(),
|
||||
commands: Default::default(),
|
||||
arc_commands: Default::default(),
|
||||
current_query_index: Default::default(),
|
||||
query_archetype_component_accesses: Vec::new(),
|
||||
query_accesses: Vec::new(),
|
||||
query_type_names: Vec::new(),
|
||||
},
|
||||
func: Box::new(move |input, state, world, resources| {
|
||||
state.reset_indices();
|
||||
// let mut input = Some(input);
|
||||
unsafe {
|
||||
if let Some(($($param,)*)) = <<($($param,)*) as SystemParam>::Fetch as FetchSystemParam>::get_param(state, world, resources) {
|
||||
Some(self(In(input), $($param),*))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}),
|
||||
thread_local_func: Box::new(|state, world, resources| {
|
||||
// SAFE: this is called with unique access to SystemState
|
||||
unsafe {
|
||||
(&mut *state.commands.get()).apply(world, resources);
|
||||
}
|
||||
if let Some(ref commands) = state.arc_commands {
|
||||
let mut commands = commands.lock();
|
||||
commands.apply(world, resources);
|
||||
}
|
||||
}),
|
||||
init_func: Box::new(|state, world, resources| {
|
||||
<<($($param,)*) as SystemParam>::Fetch as FetchSystemParam>::init(state, world, resources)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -277,7 +399,7 @@ mod tests {
|
|||
world.spawn((A, C));
|
||||
world.spawn((A, D));
|
||||
|
||||
run_system(&mut world, &mut resources, query_system);
|
||||
run_system(&mut world, &mut resources, query_system.system());
|
||||
|
||||
assert!(*resources.get::<bool>().unwrap(), "system ran");
|
||||
}
|
||||
|
@ -286,12 +408,14 @@ mod tests {
|
|||
fn or_query_set_system() {
|
||||
// Regression test for issue #762
|
||||
use crate::{Added, Changed, Mutated, Or};
|
||||
let query_system = move |mut ran: ResMut<bool>,
|
||||
set: QuerySet<(
|
||||
Query<(), Or<(Changed<A>, Changed<B>)>>,
|
||||
Query<(), Or<(Added<A>, Added<B>)>>,
|
||||
Query<(), Or<(Mutated<A>, Mutated<B>)>>,
|
||||
)>| {
|
||||
fn query_system(
|
||||
mut ran: ResMut<bool>,
|
||||
set: QuerySet<(
|
||||
Query<(), Or<(Changed<A>, Changed<B>)>>,
|
||||
Query<(), Or<(Added<A>, Added<B>)>>,
|
||||
Query<(), Or<(Mutated<A>, Mutated<B>)>>,
|
||||
)>,
|
||||
) {
|
||||
let changed = set.q0().iter().count();
|
||||
let added = set.q1().iter().count();
|
||||
let mutated = set.q2().iter().count();
|
||||
|
@ -308,7 +432,7 @@ mod tests {
|
|||
resources.insert(false);
|
||||
world.spawn((A, B));
|
||||
|
||||
run_system(&mut world, &mut resources, query_system);
|
||||
run_system(&mut world, &mut resources, query_system.system());
|
||||
|
||||
assert!(*resources.get::<bool>().unwrap(), "system ran");
|
||||
}
|
||||
|
@ -328,9 +452,12 @@ mod tests {
|
|||
|
||||
let mut schedule = Schedule::default();
|
||||
let mut update = SystemStage::parallel();
|
||||
update.add_system(incr_e_on_flip);
|
||||
update.add_system(incr_e_on_flip.system());
|
||||
schedule.add_stage("update", update);
|
||||
schedule.add_stage("clear_trackers", SystemStage::single(clear_trackers_system));
|
||||
schedule.add_stage(
|
||||
"clear_trackers",
|
||||
SystemStage::single(clear_trackers_system.system()),
|
||||
);
|
||||
|
||||
schedule.initialize_and_run(&mut world, &mut resources);
|
||||
assert_eq!(*(world.get::<i32>(ent).unwrap()), 1);
|
||||
|
@ -362,9 +489,12 @@ mod tests {
|
|||
|
||||
let mut schedule = Schedule::default();
|
||||
let mut update = SystemStage::parallel();
|
||||
update.add_system(incr_e_on_flip);
|
||||
update.add_system(incr_e_on_flip.system());
|
||||
schedule.add_stage("update", update);
|
||||
schedule.add_stage("clear_trackers", SystemStage::single(clear_trackers_system));
|
||||
schedule.add_stage(
|
||||
"clear_trackers",
|
||||
SystemStage::single(clear_trackers_system.system()),
|
||||
);
|
||||
|
||||
schedule.initialize_and_run(&mut world, &mut resources);
|
||||
assert_eq!(*(world.get::<i32>(ent).unwrap()), 1);
|
||||
|
@ -393,7 +523,7 @@ mod tests {
|
|||
let mut resources = Resources::default();
|
||||
world.spawn((A,));
|
||||
|
||||
run_system(&mut world, &mut resources, sys);
|
||||
run_system(&mut world, &mut resources, sys.system());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -405,7 +535,7 @@ mod tests {
|
|||
let mut resources = Resources::default();
|
||||
world.spawn((A,));
|
||||
|
||||
run_system(&mut world, &mut resources, sys);
|
||||
run_system(&mut world, &mut resources, sys.system());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -416,7 +546,7 @@ mod tests {
|
|||
let mut resources = Resources::default();
|
||||
world.spawn((A,));
|
||||
|
||||
run_system(&mut world, &mut resources, sys);
|
||||
run_system(&mut world, &mut resources, sys.system());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -428,7 +558,7 @@ mod tests {
|
|||
let mut resources = Resources::default();
|
||||
world.spawn((A,));
|
||||
|
||||
run_system(&mut world, &mut resources, sys);
|
||||
run_system(&mut world, &mut resources, sys.system());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -439,17 +569,13 @@ mod tests {
|
|||
let mut world = World::default();
|
||||
let mut resources = Resources::default();
|
||||
world.spawn((A,));
|
||||
run_system(&mut world, &mut resources, sys);
|
||||
run_system(&mut world, &mut resources, sys.system());
|
||||
}
|
||||
|
||||
fn run_system<
|
||||
Params,
|
||||
SystemType: System<In = (), Out = ()>,
|
||||
Sys: IntoSystem<Params, SystemType>,
|
||||
>(
|
||||
fn run_system<S: System<In = (), Out = ()>>(
|
||||
world: &mut World,
|
||||
resources: &mut Resources,
|
||||
system: Sys,
|
||||
system: S,
|
||||
) {
|
||||
let mut schedule = Schedule::default();
|
||||
let mut update = SystemStage::parallel();
|
||||
|
@ -463,40 +589,34 @@ mod tests {
|
|||
_buffer: Vec<u8>,
|
||||
}
|
||||
|
||||
fn test_for_conflicting_resources<
|
||||
Params,
|
||||
SystemType: System<In = (), Out = ()>,
|
||||
Sys: IntoSystem<Params, SystemType>,
|
||||
>(
|
||||
sys: Sys,
|
||||
) {
|
||||
fn test_for_conflicting_resources<S: System<In = (), Out = ()>>(sys: S) {
|
||||
let mut world = World::default();
|
||||
let mut resources = Resources::default();
|
||||
resources.insert(BufferRes::default());
|
||||
resources.insert(A);
|
||||
resources.insert(B);
|
||||
run_system(&mut world, &mut resources, sys);
|
||||
run_system(&mut world, &mut resources, sys.system());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn conflicting_system_resources() {
|
||||
fn sys(_: ResMut<BufferRes>, _: Res<BufferRes>) {}
|
||||
test_for_conflicting_resources(sys)
|
||||
test_for_conflicting_resources(sys.system())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn conflicting_system_resources_reverse_order() {
|
||||
fn sys(_: Res<BufferRes>, _: ResMut<BufferRes>) {}
|
||||
test_for_conflicting_resources(sys)
|
||||
test_for_conflicting_resources(sys.system())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn conflicting_system_resources_multiple_mutable() {
|
||||
fn sys(_: ResMut<BufferRes>, _: ResMut<BufferRes>) {}
|
||||
test_for_conflicting_resources(sys)
|
||||
test_for_conflicting_resources(sys.system())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -504,19 +624,19 @@ mod tests {
|
|||
fn conflicting_changed_and_mutable_resource() {
|
||||
// A tempting pattern, but unsound if allowed.
|
||||
fn sys(_: ResMut<BufferRes>, _: ChangedRes<BufferRes>) {}
|
||||
test_for_conflicting_resources(sys)
|
||||
test_for_conflicting_resources(sys.system())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn conflicting_system_local_resources() {
|
||||
fn sys(_: Local<BufferRes>, _: Local<BufferRes>) {}
|
||||
test_for_conflicting_resources(sys)
|
||||
test_for_conflicting_resources(sys.system())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nonconflicting_system_resources() {
|
||||
fn sys(_: Local<BufferRes>, _: ResMut<BufferRes>, _: Local<A>, _: ResMut<A>) {}
|
||||
test_for_conflicting_resources(sys)
|
||||
test_for_conflicting_resources(sys.system())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::{
|
||||
ArchetypeComponent, IntoSystem, Resources, System, SystemId, ThreadLocalExecution, TypeAccess,
|
||||
World,
|
||||
ArchetypeComponent, Resources, System, SystemId, ThreadLocalExecution, TypeAccess, World,
|
||||
};
|
||||
use std::{any::TypeId, borrow::Cow};
|
||||
|
||||
|
@ -69,31 +68,23 @@ impl<SystemA: System, SystemB: System<In = SystemA::Out>> System for ChainSystem
|
|||
}
|
||||
}
|
||||
|
||||
pub trait IntoChainSystem<AParams, BParams, IntoB, SystemA, SystemB>:
|
||||
IntoSystem<AParams, SystemA> + Sized
|
||||
pub trait IntoChainSystem<SystemB>: System + Sized
|
||||
where
|
||||
IntoB: IntoSystem<BParams, SystemB>,
|
||||
SystemA: System,
|
||||
SystemB: System<In = SystemA::Out>,
|
||||
SystemB: System<In = Self::Out>,
|
||||
{
|
||||
fn chain(self, system: IntoB) -> ChainSystem<SystemA, SystemB>;
|
||||
fn chain(self, system: SystemB) -> ChainSystem<Self, SystemB>;
|
||||
}
|
||||
|
||||
impl<AParams, BParams, IntoA, IntoB, SystemA, SystemB>
|
||||
IntoChainSystem<AParams, BParams, IntoB, SystemA, SystemB> for IntoA
|
||||
impl<SystemA, SystemB> IntoChainSystem<SystemB> for SystemA
|
||||
where
|
||||
SystemA: System,
|
||||
SystemB: System<In = SystemA::Out>,
|
||||
IntoA: IntoSystem<AParams, SystemA>,
|
||||
IntoB: IntoSystem<BParams, SystemB>,
|
||||
{
|
||||
fn chain(self, system: IntoB) -> ChainSystem<SystemA, SystemB> {
|
||||
let system_a = self.system();
|
||||
let system_b = system.system();
|
||||
fn chain(self, system: SystemB) -> ChainSystem<SystemA, SystemB> {
|
||||
ChainSystem {
|
||||
name: Cow::Owned(format!("Chain({}, {})", system_a.name(), system_b.name())),
|
||||
system_a,
|
||||
system_b,
|
||||
name: Cow::Owned(format!("Chain({}, {})", self.name(), system.name())),
|
||||
system_a: self,
|
||||
system_b: system,
|
||||
archetype_component_access: Default::default(),
|
||||
resource_access: Default::default(),
|
||||
id: SystemId::new(),
|
||||
|
|
|
@ -4,50 +4,43 @@ use crate::{
|
|||
SystemState, TypeAccess, World, WorldQuery,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use std::{any::TypeId, sync::Arc};
|
||||
|
||||
pub struct In<Input>(pub Input);
|
||||
|
||||
impl<Input> SystemParam<Input> for In<Input> {
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
input: &mut Option<Input>,
|
||||
_system_state: &mut SystemState,
|
||||
_world: &World,
|
||||
_resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
Some(In(input.take().unwrap()))
|
||||
}
|
||||
|
||||
fn init(_system_state: &mut SystemState, _world: &World, _resources: &mut Resources) {}
|
||||
use std::{any::TypeId, marker::PhantomData, sync::Arc};
|
||||
pub trait SystemParam: Sized {
|
||||
type Fetch: for<'a> FetchSystemParam<'a>;
|
||||
}
|
||||
|
||||
pub trait SystemParam<Input>: Sized {
|
||||
pub trait FetchSystemParam<'a> {
|
||||
type Item;
|
||||
fn init(system_state: &mut SystemState, world: &World, resources: &mut Resources);
|
||||
/// # Safety
|
||||
/// This call might access any of the input parameters in an unsafe way. Make sure the data access is safe in
|
||||
/// the context of the system scheduler
|
||||
unsafe fn get_param(
|
||||
input: &mut Option<Input>,
|
||||
system_state: &mut SystemState,
|
||||
world: &World,
|
||||
resources: &Resources,
|
||||
) -> Option<Self>;
|
||||
system_state: &'a SystemState,
|
||||
world: &'a World,
|
||||
resources: &'a Resources,
|
||||
) -> Option<Self::Item>;
|
||||
}
|
||||
|
||||
impl<'a, Q: WorldQuery, F: QueryFilter, Input> SystemParam<Input> for Query<'a, Q, F> {
|
||||
pub struct FetchQuery<Q, F>(PhantomData<(Q, F)>);
|
||||
|
||||
impl<'a, Q: WorldQuery, F: QueryFilter> SystemParam for Query<'a, Q, F> {
|
||||
type Fetch = FetchQuery<Q, F>;
|
||||
}
|
||||
|
||||
impl<'a, Q: WorldQuery, F: QueryFilter> FetchSystemParam<'a> for FetchQuery<Q, F> {
|
||||
type Item = Query<'a, Q, F>;
|
||||
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
_input: &mut Option<Input>,
|
||||
system_state: &mut SystemState,
|
||||
world: &World,
|
||||
_resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
let query_index = system_state.current_query_index;
|
||||
let world: &'a World = std::mem::transmute(world);
|
||||
system_state: &'a SystemState,
|
||||
world: &'a World,
|
||||
_resources: &'a Resources,
|
||||
) -> Option<Self::Item> {
|
||||
let query_index = *system_state.current_query_index.get();
|
||||
let archetype_component_access: &'a TypeAccess<ArchetypeComponent> =
|
||||
std::mem::transmute(&system_state.query_archetype_component_accesses[query_index]);
|
||||
system_state.current_query_index += 1;
|
||||
&system_state.query_archetype_component_accesses[query_index];
|
||||
*system_state.current_query_index.get() += 1;
|
||||
Some(Query::new(world, archetype_component_access))
|
||||
}
|
||||
|
||||
|
@ -63,16 +56,23 @@ impl<'a, Q: WorldQuery, F: QueryFilter, Input> SystemParam<Input> for Query<'a,
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: QueryTuple, Input> SystemParam<Input> for QuerySet<T> {
|
||||
pub struct FetchQuerySet<T>(PhantomData<T>);
|
||||
|
||||
impl<T: QueryTuple> SystemParam for QuerySet<T> {
|
||||
type Fetch = FetchQuerySet<T>;
|
||||
}
|
||||
|
||||
impl<'a, T: QueryTuple> FetchSystemParam<'a> for FetchQuerySet<T> {
|
||||
type Item = QuerySet<T>;
|
||||
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
_input: &mut Option<Input>,
|
||||
system_state: &mut SystemState,
|
||||
world: &World,
|
||||
_resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
let query_index = system_state.current_query_index;
|
||||
system_state.current_query_index += 1;
|
||||
system_state: &'a SystemState,
|
||||
world: &'a World,
|
||||
_resources: &'a Resources,
|
||||
) -> Option<Self::Item> {
|
||||
let query_index = *system_state.current_query_index.get();
|
||||
*system_state.current_query_index.get() += 1;
|
||||
Some(QuerySet::new(
|
||||
world,
|
||||
&system_state.query_archetype_component_accesses[query_index],
|
||||
|
@ -90,26 +90,39 @@ impl<T: QueryTuple, Input> SystemParam<Input> for QuerySet<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, Input> SystemParam<Input> for &'a mut Commands {
|
||||
pub struct FetchCommands;
|
||||
|
||||
impl<'a> SystemParam for &'a mut Commands {
|
||||
type Fetch = FetchCommands;
|
||||
}
|
||||
impl<'a> FetchSystemParam<'a> for FetchCommands {
|
||||
type Item = &'a mut Commands;
|
||||
|
||||
fn init(system_state: &mut SystemState, world: &World, _resources: &mut Resources) {
|
||||
system_state
|
||||
.commands
|
||||
.set_entity_reserver(world.get_entity_reserver())
|
||||
// SAFE: this is called with unique access to SystemState
|
||||
unsafe {
|
||||
(&mut *system_state.commands.get()).set_entity_reserver(world.get_entity_reserver())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
_input: &mut Option<Input>,
|
||||
system_state: &mut SystemState,
|
||||
_world: &World,
|
||||
_resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
let commands: &'a mut Commands = std::mem::transmute(&mut system_state.commands);
|
||||
Some(commands)
|
||||
system_state: &'a SystemState,
|
||||
_world: &'a World,
|
||||
_resources: &'a Resources,
|
||||
) -> Option<Self::Item> {
|
||||
Some(&mut *system_state.commands.get())
|
||||
}
|
||||
}
|
||||
|
||||
impl<Input> SystemParam<Input> for Arc<Mutex<Commands>> {
|
||||
pub struct FetchArcCommands;
|
||||
impl SystemParam for Arc<Mutex<Commands>> {
|
||||
type Fetch = FetchArcCommands;
|
||||
}
|
||||
|
||||
impl<'a> FetchSystemParam<'a> for FetchArcCommands {
|
||||
type Item = Arc<Mutex<Commands>>;
|
||||
|
||||
fn init(system_state: &mut SystemState, world: &World, _resources: &mut Resources) {
|
||||
system_state.arc_commands.get_or_insert_with(|| {
|
||||
let mut commands = Commands::default();
|
||||
|
@ -120,16 +133,23 @@ impl<Input> SystemParam<Input> for Arc<Mutex<Commands>> {
|
|||
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
_input: &mut Option<Input>,
|
||||
system_state: &mut SystemState,
|
||||
system_state: &SystemState,
|
||||
_world: &World,
|
||||
_resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
) -> Option<Self::Item> {
|
||||
Some(system_state.arc_commands.as_ref().unwrap().clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Resource, Input> SystemParam<Input> for Res<'a, T> {
|
||||
pub struct FetchRes<T>(PhantomData<T>);
|
||||
|
||||
impl<'a, T: Resource> SystemParam for Res<'a, T> {
|
||||
type Fetch = FetchRes<T>;
|
||||
}
|
||||
|
||||
impl<'a, T: Resource> FetchSystemParam<'a> for FetchRes<T> {
|
||||
type Item = Res<'a, T>;
|
||||
|
||||
fn init(system_state: &mut SystemState, _world: &World, _resources: &mut Resources) {
|
||||
if system_state.resource_access.is_write(&TypeId::of::<T>()) {
|
||||
panic!(
|
||||
|
@ -144,18 +164,24 @@ impl<'a, T: Resource, Input> SystemParam<Input> for Res<'a, T> {
|
|||
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
_input: &mut Option<Input>,
|
||||
_system_state: &mut SystemState,
|
||||
_world: &World,
|
||||
resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
_system_state: &'a SystemState,
|
||||
_world: &'a World,
|
||||
resources: &'a Resources,
|
||||
) -> Option<Self::Item> {
|
||||
Some(Res::new(
|
||||
resources.get_unsafe_ref::<T>(ResourceIndex::Global),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Resource, Input> SystemParam<Input> for ResMut<'a, T> {
|
||||
pub struct FetchResMut<T>(PhantomData<T>);
|
||||
|
||||
impl<'a, T: Resource> SystemParam for ResMut<'a, T> {
|
||||
type Fetch = FetchResMut<T>;
|
||||
}
|
||||
impl<'a, T: Resource> FetchSystemParam<'a> for FetchResMut<T> {
|
||||
type Item = ResMut<'a, T>;
|
||||
|
||||
fn init(system_state: &mut SystemState, _world: &World, _resources: &mut Resources) {
|
||||
// If a system already has access to the resource in another parameter, then we fail early.
|
||||
// e.g. `fn(Res<Foo>, ResMut<Foo>)` or `fn(ResMut<Foo>, ResMut<Foo>)` must not be allowed.
|
||||
|
@ -175,18 +201,25 @@ impl<'a, T: Resource, Input> SystemParam<Input> for ResMut<'a, T> {
|
|||
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
_input: &mut Option<Input>,
|
||||
_system_state: &mut SystemState,
|
||||
_world: &World,
|
||||
resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
_system_state: &'a SystemState,
|
||||
_world: &'a World,
|
||||
resources: &'a Resources,
|
||||
) -> Option<Self::Item> {
|
||||
let (value, _added, mutated) =
|
||||
resources.get_unsafe_ref_with_added_and_mutated::<T>(ResourceIndex::Global);
|
||||
Some(ResMut::new(value, mutated))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Resource, Input> SystemParam<Input> for ChangedRes<'a, T> {
|
||||
pub struct FetchChangedRes<T>(PhantomData<T>);
|
||||
|
||||
impl<'a, T: Resource> SystemParam for ChangedRes<'a, T> {
|
||||
type Fetch = FetchChangedRes<T>;
|
||||
}
|
||||
|
||||
impl<'a, T: Resource> FetchSystemParam<'a> for FetchChangedRes<T> {
|
||||
type Item = ChangedRes<'a, T>;
|
||||
|
||||
fn init(system_state: &mut SystemState, _world: &World, _resources: &mut Resources) {
|
||||
if system_state.resource_access.is_write(&TypeId::of::<T>()) {
|
||||
panic!(
|
||||
|
@ -201,11 +234,10 @@ impl<'a, T: Resource, Input> SystemParam<Input> for ChangedRes<'a, T> {
|
|||
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
_input: &mut Option<Input>,
|
||||
_system_state: &mut SystemState,
|
||||
_world: &World,
|
||||
resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
_system_state: &'a SystemState,
|
||||
_world: &'a World,
|
||||
resources: &'a Resources,
|
||||
) -> Option<Self::Item> {
|
||||
let (value, added, mutated) =
|
||||
resources.get_unsafe_ref_with_added_and_mutated::<T>(ResourceIndex::Global);
|
||||
if *added.as_ptr() || *mutated.as_ptr() {
|
||||
|
@ -216,7 +248,14 @@ impl<'a, T: Resource, Input> SystemParam<Input> for ChangedRes<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Resource + FromResources, Input> SystemParam<Input> for Local<'a, T> {
|
||||
pub struct FetchLocal<T>(PhantomData<T>);
|
||||
|
||||
impl<'a, T: Resource + FromResources> SystemParam for Local<'a, T> {
|
||||
type Fetch = FetchLocal<T>;
|
||||
}
|
||||
impl<'a, T: Resource + FromResources> FetchSystemParam<'a> for FetchLocal<T> {
|
||||
type Item = Local<'a, T>;
|
||||
|
||||
fn init(system_state: &mut SystemState, _world: &World, resources: &mut Resources) {
|
||||
if system_state
|
||||
.local_resource_access
|
||||
|
@ -244,52 +283,61 @@ impl<'a, T: Resource + FromResources, Input> SystemParam<Input> for Local<'a, T>
|
|||
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
_input: &mut Option<Input>,
|
||||
system_state: &mut SystemState,
|
||||
_world: &World,
|
||||
resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
system_state: &'a SystemState,
|
||||
_world: &'a World,
|
||||
resources: &'a Resources,
|
||||
) -> Option<Self::Item> {
|
||||
Some(Local::new(resources, system_state.id))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FetchParamTuple<T>(PhantomData<T>);
|
||||
pub struct FetchOr<T>(PhantomData<T>);
|
||||
|
||||
macro_rules! impl_system_param_tuple {
|
||||
($($param: ident),*) => {
|
||||
impl<$($param: SystemParam),*> SystemParam for ($($param,)*) {
|
||||
type Fetch = FetchParamTuple<($($param::Fetch,)*)>;
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
impl<Input, $($param: SystemParam<Input>),*> SystemParam<Input> for ($($param,)*) {
|
||||
impl<'a, $($param: FetchSystemParam<'a>),*> FetchSystemParam<'a> for FetchParamTuple<($($param,)*)> {
|
||||
type Item = ($($param::Item,)*);
|
||||
fn init(system_state: &mut SystemState, world: &World, resources: &mut Resources) {
|
||||
$($param::init(system_state, world, resources);)*
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
input: &mut Option<Input>,
|
||||
system_state: &mut SystemState,
|
||||
world: &World,
|
||||
resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
Some(($($param::get_param(input, system_state, world, resources)?,)*))
|
||||
system_state: &'a SystemState,
|
||||
world: &'a World,
|
||||
resources: &'a Resources,
|
||||
) -> Option<Self::Item> {
|
||||
Some(($($param::get_param(system_state, world, resources)?,)*))
|
||||
}
|
||||
}
|
||||
|
||||
impl<$($param: SystemParam),*> SystemParam for Or<($(Option<$param>,)*)> {
|
||||
type Fetch = FetchOr<($($param::Fetch,)*)>;
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_mut)]
|
||||
#[allow(non_snake_case)]
|
||||
impl<Input, $($param: SystemParam<Input>),*> SystemParam<Input> for Or<($(Option<$param>,)*)> {
|
||||
impl<'a, $($param: FetchSystemParam<'a>),*> FetchSystemParam<'a> for FetchOr<($($param,)*)> {
|
||||
type Item = Or<($(Option<$param::Item>,)*)>;
|
||||
fn init(system_state: &mut SystemState, world: &World, resources: &mut Resources) {
|
||||
$($param::init(system_state, world, resources);)*
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn get_param(
|
||||
input: &mut Option<Input>,
|
||||
system_state: &mut SystemState,
|
||||
world: &World,
|
||||
resources: &Resources,
|
||||
) -> Option<Self> {
|
||||
system_state: &'a SystemState,
|
||||
world: &'a World,
|
||||
resources: &'a Resources,
|
||||
) -> Option<Self::Item> {
|
||||
let mut has_some = false;
|
||||
$(
|
||||
let $param = $param::get_param(input, system_state, world, resources);
|
||||
let $param = $param::get_param(system_state, world, resources);
|
||||
if $param.is_some() {
|
||||
has_some = true;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ mod converter;
|
|||
mod gilrs_system;
|
||||
|
||||
use bevy_app::{prelude::*, startup_stage::PRE_STARTUP};
|
||||
use bevy_ecs::IntoSystem;
|
||||
use bevy_utils::tracing::error;
|
||||
use gilrs::GilrsBuilder;
|
||||
use gilrs_system::{gilrs_event_startup_system, gilrs_event_system};
|
||||
|
@ -18,8 +19,8 @@ impl Plugin for GilrsPlugin {
|
|||
{
|
||||
Ok(gilrs) => {
|
||||
app.add_thread_local_resource(gilrs)
|
||||
.add_startup_system_to_stage(PRE_STARTUP, gilrs_event_startup_system)
|
||||
.add_system_to_stage(stage::PRE_EVENT, gilrs_event_system);
|
||||
.add_startup_system_to_stage(PRE_STARTUP, gilrs_event_startup_system.system())
|
||||
.add_system_to_stage(stage::PRE_EVENT, gilrs_event_system.system());
|
||||
}
|
||||
Err(err) => error!("Failed to start Gilrs. {}", err),
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ pub mod system;
|
|||
pub mod touch;
|
||||
|
||||
pub use axis::*;
|
||||
use bevy_ecs::IntoSystem;
|
||||
pub use input::*;
|
||||
|
||||
pub mod prelude {
|
||||
|
@ -43,20 +44,23 @@ impl Plugin for InputPlugin {
|
|||
.add_event::<MouseMotion>()
|
||||
.add_event::<MouseWheel>()
|
||||
.init_resource::<Input<KeyCode>>()
|
||||
.add_system_to_stage(bevy_app::stage::EVENT, keyboard_input_system)
|
||||
.add_system_to_stage(bevy_app::stage::EVENT, keyboard_input_system.system())
|
||||
.init_resource::<Input<MouseButton>>()
|
||||
.add_system_to_stage(bevy_app::stage::EVENT, mouse_button_input_system)
|
||||
.add_system_to_stage(bevy_app::stage::EVENT, mouse_button_input_system.system())
|
||||
.add_event::<GamepadEvent>()
|
||||
.add_event::<GamepadEventRaw>()
|
||||
.init_resource::<GamepadSettings>()
|
||||
.init_resource::<Input<GamepadButton>>()
|
||||
.init_resource::<Axis<GamepadAxis>>()
|
||||
.init_resource::<Axis<GamepadButton>>()
|
||||
.add_system_to_stage(bevy_app::stage::EVENT, gamepad_event_system)
|
||||
.add_startup_system_to_stage(bevy_app::startup_stage::STARTUP, gamepad_event_system)
|
||||
.add_system_to_stage(bevy_app::stage::EVENT, gamepad_event_system.system())
|
||||
.add_startup_system_to_stage(
|
||||
bevy_app::startup_stage::STARTUP,
|
||||
gamepad_event_system.system(),
|
||||
)
|
||||
.add_event::<TouchInput>()
|
||||
.init_resource::<Touches>()
|
||||
.add_system_to_stage(bevy_app::stage::EVENT, touch_screen_input_system);
|
||||
.add_system_to_stage(bevy_app::stage::EVENT, touch_screen_input_system.system());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ mod entity;
|
|||
mod light;
|
||||
mod material;
|
||||
|
||||
use bevy_ecs::IntoSystem;
|
||||
pub use entity::*;
|
||||
pub use light::*;
|
||||
pub use material::*;
|
||||
|
@ -29,7 +30,7 @@ impl Plugin for PbrPlugin {
|
|||
.register_type::<Light>()
|
||||
.add_system_to_stage(
|
||||
stage::POST_UPDATE,
|
||||
shader::asset_shader_defs_system::<StandardMaterial>,
|
||||
shader::asset_shader_defs_system::<StandardMaterial>.system(),
|
||||
)
|
||||
.init_resource::<AmbientLight>();
|
||||
let resources = app.resources();
|
||||
|
|
|
@ -147,9 +147,6 @@ pub struct DrawContext<'a> {
|
|||
pub current_pipeline: Option<Handle<PipelineDescriptor>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FetchDrawContext;
|
||||
|
||||
impl<'a> DrawContext<'a> {
|
||||
pub fn get_uniform_buffer<T: RenderResource>(
|
||||
&mut self,
|
||||
|
|
|
@ -11,7 +11,7 @@ pub mod renderer;
|
|||
pub mod shader;
|
||||
pub mod texture;
|
||||
|
||||
use bevy_ecs::SystemStage;
|
||||
use bevy_ecs::{IntoSystem, SystemStage};
|
||||
use bevy_reflect::RegisterTypeBuilder;
|
||||
use draw::Visible;
|
||||
pub use once_cell;
|
||||
|
@ -136,30 +136,48 @@ impl Plugin for RenderPlugin {
|
|||
.init_resource::<TextureResourceSystemState>()
|
||||
.init_resource::<AssetRenderResourceBindings>()
|
||||
.init_resource::<ActiveCameras>()
|
||||
.add_system_to_stage(bevy_app::stage::PRE_UPDATE, draw::clear_draw_system)
|
||||
.add_system_to_stage(bevy_app::stage::POST_UPDATE, camera::active_cameras_system)
|
||||
.add_system_to_stage(
|
||||
bevy_app::stage::POST_UPDATE,
|
||||
camera::camera_system::<OrthographicProjection>,
|
||||
bevy_app::stage::PRE_UPDATE,
|
||||
draw::clear_draw_system.system(),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
bevy_app::stage::POST_UPDATE,
|
||||
camera::camera_system::<PerspectiveProjection>,
|
||||
camera::active_cameras_system.system(),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
bevy_app::stage::POST_UPDATE,
|
||||
camera::camera_system::<OrthographicProjection>.system(),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
bevy_app::stage::POST_UPDATE,
|
||||
camera::camera_system::<PerspectiveProjection>.system(),
|
||||
)
|
||||
// registration order matters here. this must come after all camera_system::<T> systems
|
||||
.add_system_to_stage(
|
||||
bevy_app::stage::POST_UPDATE,
|
||||
camera::visible_entities_system,
|
||||
camera::visible_entities_system.system(),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
stage::RENDER_RESOURCE,
|
||||
shader::shader_update_system.system(),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
stage::RENDER_RESOURCE,
|
||||
mesh::mesh_resource_provider_system.system(),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
stage::RENDER_RESOURCE,
|
||||
Texture::texture_resource_system.system(),
|
||||
)
|
||||
.add_system_to_stage(stage::RENDER_RESOURCE, shader::shader_update_system)
|
||||
.add_system_to_stage(stage::RENDER_RESOURCE, mesh::mesh_resource_provider_system)
|
||||
.add_system_to_stage(stage::RENDER_RESOURCE, Texture::texture_resource_system)
|
||||
.add_system_to_stage(
|
||||
stage::RENDER_GRAPH_SYSTEMS,
|
||||
render_graph::render_graph_schedule_executor_system,
|
||||
render_graph::render_graph_schedule_executor_system.system(),
|
||||
)
|
||||
.add_system_to_stage(stage::DRAW, pipeline::draw_render_pipelines_system)
|
||||
.add_system_to_stage(stage::POST_RENDER, shader::clear_shader_defs_system);
|
||||
.add_system_to_stage(stage::DRAW, pipeline::draw_render_pipelines_system.system())
|
||||
.add_system_to_stage(
|
||||
stage::POST_RENDER,
|
||||
shader::clear_shader_defs_system.system(),
|
||||
);
|
||||
|
||||
if app.resources().get::<Msaa>().is_none() {
|
||||
app.init_resource::<Msaa>();
|
||||
|
|
|
@ -5,7 +5,7 @@ mod scene_loader;
|
|||
mod scene_spawner;
|
||||
pub mod serde;
|
||||
|
||||
use bevy_ecs::SystemStage;
|
||||
use bevy_ecs::{IntoSystem, SystemStage};
|
||||
pub use command::*;
|
||||
pub use dynamic_scene::*;
|
||||
pub use scene::*;
|
||||
|
@ -33,6 +33,6 @@ impl Plugin for ScenePlugin {
|
|||
.init_asset_loader::<SceneLoader>()
|
||||
.init_resource::<SceneSpawner>()
|
||||
.add_stage_after(stage::EVENT, SCENE_STAGE, SystemStage::parallel())
|
||||
.add_system_to_stage(SCENE_STAGE, scene_spawner_system);
|
||||
.add_system_to_stage(SCENE_STAGE, scene_spawner_system.system());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ mod sprite;
|
|||
mod texture_atlas;
|
||||
mod texture_atlas_builder;
|
||||
|
||||
use bevy_ecs::IntoSystem;
|
||||
pub use color_material::*;
|
||||
pub use dynamic_texture_atlas_builder::*;
|
||||
pub use rect::*;
|
||||
|
@ -46,10 +47,10 @@ impl Plugin for SpritePlugin {
|
|||
app.add_asset::<ColorMaterial>()
|
||||
.add_asset::<TextureAtlas>()
|
||||
.register_type::<Sprite>()
|
||||
.add_system_to_stage(stage::POST_UPDATE, sprite_system)
|
||||
.add_system_to_stage(stage::POST_UPDATE, sprite_system.system())
|
||||
.add_system_to_stage(
|
||||
stage::POST_UPDATE,
|
||||
asset_shader_defs_system::<ColorMaterial>,
|
||||
asset_shader_defs_system::<ColorMaterial>.system(),
|
||||
);
|
||||
|
||||
let resources = app.resources_mut();
|
||||
|
|
|
@ -71,7 +71,7 @@ pub fn parent_update_system(
|
|||
mod test {
|
||||
use super::*;
|
||||
use crate::{hierarchy::BuildChildren, transform_propagate_system::transform_propagate_system};
|
||||
use bevy_ecs::{Resources, Schedule, SystemStage, World};
|
||||
use bevy_ecs::{IntoSystem, Resources, Schedule, SystemStage, World};
|
||||
use bevy_math::Vec3;
|
||||
|
||||
#[test]
|
||||
|
@ -80,8 +80,8 @@ mod test {
|
|||
let mut resources = Resources::default();
|
||||
|
||||
let mut update_stage = SystemStage::parallel();
|
||||
update_stage.add_system(parent_update_system);
|
||||
update_stage.add_system(transform_propagate_system);
|
||||
update_stage.add_system(parent_update_system.system());
|
||||
update_stage.add_system(transform_propagate_system.system());
|
||||
|
||||
let mut schedule = Schedule::default();
|
||||
schedule.add_stage("update", update_stage);
|
||||
|
|
|
@ -7,6 +7,7 @@ pub mod prelude {
|
|||
}
|
||||
|
||||
use bevy_app::{prelude::*, startup_stage};
|
||||
use bevy_ecs::IntoSystem;
|
||||
use bevy_reflect::RegisterTypeBuilder;
|
||||
use prelude::{parent_update_system, Children, GlobalTransform, Parent, PreviousParent, Transform};
|
||||
|
||||
|
@ -21,15 +22,15 @@ impl Plugin for TransformPlugin {
|
|||
.register_type::<Transform>()
|
||||
.register_type::<GlobalTransform>()
|
||||
// add transform systems to startup so the first update is "correct"
|
||||
.add_startup_system_to_stage(startup_stage::POST_STARTUP, parent_update_system)
|
||||
.add_startup_system_to_stage(startup_stage::POST_STARTUP, parent_update_system.system())
|
||||
.add_startup_system_to_stage(
|
||||
startup_stage::POST_STARTUP,
|
||||
transform_propagate_system::transform_propagate_system,
|
||||
transform_propagate_system::transform_propagate_system.system(),
|
||||
)
|
||||
.add_system_to_stage(stage::POST_UPDATE, parent_update_system)
|
||||
.add_system_to_stage(stage::POST_UPDATE, parent_update_system.system())
|
||||
.add_system_to_stage(
|
||||
stage::POST_UPDATE,
|
||||
transform_propagate_system::transform_propagate_system,
|
||||
transform_propagate_system::transform_propagate_system.system(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,8 +80,8 @@ mod test {
|
|||
let mut resources = Resources::default();
|
||||
|
||||
let mut update_stage = SystemStage::parallel();
|
||||
update_stage.add_system(parent_update_system);
|
||||
update_stage.add_system(transform_propagate_system);
|
||||
update_stage.add_system(parent_update_system.system());
|
||||
update_stage.add_system(transform_propagate_system.system());
|
||||
|
||||
let mut schedule = Schedule::default();
|
||||
schedule.add_stage("update", update_stage);
|
||||
|
@ -133,8 +133,8 @@ mod test {
|
|||
let mut resources = Resources::default();
|
||||
|
||||
let mut update_stage = SystemStage::parallel();
|
||||
update_stage.add_system(parent_update_system);
|
||||
update_stage.add_system(transform_propagate_system);
|
||||
update_stage.add_system(parent_update_system.system());
|
||||
update_stage.add_system(transform_propagate_system.system());
|
||||
|
||||
let mut schedule = Schedule::default();
|
||||
schedule.add_stage("update", update_stage);
|
||||
|
|
|
@ -25,7 +25,7 @@ pub mod prelude {
|
|||
}
|
||||
|
||||
use bevy_app::prelude::*;
|
||||
use bevy_ecs::SystemStage;
|
||||
use bevy_ecs::{IntoSystem, SystemStage};
|
||||
use bevy_render::render_graph::RenderGraph;
|
||||
use update::ui_z_system;
|
||||
|
||||
|
@ -44,13 +44,13 @@ impl Plugin for UiPlugin {
|
|||
stage::UI,
|
||||
SystemStage::parallel(),
|
||||
)
|
||||
.add_system_to_stage(bevy_app::stage::PRE_UPDATE, ui_focus_system)
|
||||
.add_system_to_stage(bevy_app::stage::PRE_UPDATE, ui_focus_system.system())
|
||||
// add these stages to front because these must run before transform update systems
|
||||
.add_system_to_stage(stage::UI, widget::text_system)
|
||||
.add_system_to_stage(stage::UI, widget::image_node_system)
|
||||
.add_system_to_stage(stage::UI, ui_z_system)
|
||||
.add_system_to_stage(stage::UI, flex_node_system)
|
||||
.add_system_to_stage(bevy_render::stage::DRAW, widget::draw_text_system);
|
||||
.add_system_to_stage(stage::UI, widget::text_system.system())
|
||||
.add_system_to_stage(stage::UI, widget::image_node_system.system())
|
||||
.add_system_to_stage(stage::UI, ui_z_system.system())
|
||||
.add_system_to_stage(stage::UI, flex_node_system.system())
|
||||
.add_system_to_stage(bevy_render::stage::DRAW, widget::draw_text_system.system());
|
||||
|
||||
let resources = app.resources();
|
||||
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
|
||||
|
|
|
@ -48,7 +48,7 @@ fn update_hierarchy(
|
|||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bevy_ecs::{Commands, Resources, Schedule, SystemStage, World};
|
||||
use bevy_ecs::{Commands, IntoSystem, Resources, Schedule, SystemStage, World};
|
||||
use bevy_transform::{components::Transform, hierarchy::BuildChildren};
|
||||
|
||||
use crate::Node;
|
||||
|
@ -116,7 +116,7 @@ mod tests {
|
|||
|
||||
let mut schedule = Schedule::default();
|
||||
let mut update_stage = SystemStage::parallel();
|
||||
update_stage.add_system(ui_z_system);
|
||||
update_stage.add_system(ui_z_system.system());
|
||||
schedule.add_stage("update", update_stage);
|
||||
schedule.initialize_and_run(&mut world, &mut resources);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::renderer::WgpuRenderResourceContext;
|
||||
use bevy_app::prelude::*;
|
||||
use bevy_diagnostic::{Diagnostic, DiagnosticId, Diagnostics};
|
||||
use bevy_ecs::{Res, ResMut};
|
||||
use bevy_ecs::{IntoSystem, Res, ResMut};
|
||||
use bevy_render::renderer::RenderResourceContext;
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -9,8 +9,8 @@ pub struct WgpuResourceDiagnosticsPlugin;
|
|||
|
||||
impl Plugin for WgpuResourceDiagnosticsPlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
app.add_startup_system(Self::setup_system)
|
||||
.add_system(Self::diagnostic_system);
|
||||
app.add_startup_system(Self::setup_system.system())
|
||||
.add_system(Self::diagnostic_system.system());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ pub use wgpu_renderer::*;
|
|||
pub use wgpu_resources::*;
|
||||
|
||||
use bevy_app::prelude::*;
|
||||
use bevy_ecs::{Resources, World};
|
||||
use bevy_ecs::{IntoSystem, Resources, World};
|
||||
use bevy_render::renderer::{shared_buffers_update_system, RenderResourceContext, SharedBuffers};
|
||||
use renderer::WgpuRenderResourceContext;
|
||||
|
||||
|
@ -21,10 +21,10 @@ pub struct WgpuPlugin;
|
|||
impl Plugin for WgpuPlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
let render_system = get_wgpu_render_system(app.resources_mut());
|
||||
app.add_system_to_stage(bevy_render::stage::RENDER, render_system)
|
||||
app.add_system_to_stage(bevy_render::stage::RENDER, render_system.system())
|
||||
.add_system_to_stage(
|
||||
bevy_render::stage::POST_RENDER,
|
||||
shared_buffers_update_system,
|
||||
shared_buffers_update_system.system(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ mod system;
|
|||
mod window;
|
||||
mod windows;
|
||||
|
||||
use bevy_ecs::IntoSystem;
|
||||
pub use event::*;
|
||||
pub use system::*;
|
||||
pub use window::*;
|
||||
|
@ -59,7 +60,7 @@ impl Plugin for WindowPlugin {
|
|||
}
|
||||
|
||||
if self.exit_on_close {
|
||||
app.add_system(exit_on_window_close_system);
|
||||
app.add_system(exit_on_window_close_system.system());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ pub use winit_config::*;
|
|||
pub use winit_windows::*;
|
||||
|
||||
use bevy_app::{prelude::*, AppExit};
|
||||
use bevy_ecs::{Resources, World};
|
||||
use bevy_ecs::{IntoSystem, Resources, World};
|
||||
use bevy_math::Vec2;
|
||||
use bevy_utils::tracing::{error, trace};
|
||||
use bevy_window::{
|
||||
|
@ -29,7 +29,7 @@ impl Plugin for WinitPlugin {
|
|||
fn build(&self, app: &mut AppBuilder) {
|
||||
app.init_resource::<WinitWindows>()
|
||||
.set_runner(winit_runner)
|
||||
.add_system(change_window);
|
||||
.add_system(change_window.system());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@ use std::{
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_system(velocity_system)
|
||||
.add_system(move_system)
|
||||
.add_system(collision_system)
|
||||
.add_system(select_system)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(velocity_system.system())
|
||||
.add_system(move_system.system())
|
||||
.add_system(collision_system.system())
|
||||
.add_system(select_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use bevy::prelude::*;
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ use bevy::prelude::*;
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_system(animate_sprite_system)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(animate_sprite_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@ fn main() {
|
|||
.add_plugins(DefaultPlugins)
|
||||
.add_resource(State::new(AppState::Setup))
|
||||
.add_stage_after(stage::UPDATE, STAGE, StateStage::<AppState>::default())
|
||||
.on_state_enter(STAGE, AppState::Setup, load_textures)
|
||||
.on_state_update(STAGE, AppState::Setup, check_textures)
|
||||
.on_state_enter(STAGE, AppState::Finshed, setup)
|
||||
.on_state_enter(STAGE, AppState::Setup, load_textures.system())
|
||||
.on_state_update(STAGE, AppState::Setup, check_textures.system())
|
||||
.on_state_enter(STAGE, AppState::Finshed, setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_resource(Msaa { samples: 4 })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_resource(Msaa { samples: 4 })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_resource(Msaa { samples: 4 })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ fn main() {
|
|||
App::build()
|
||||
.add_resource(Msaa { samples: 4 })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_system(rotator_system)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(rotator_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ fn main() {
|
|||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_plugin(PrintDiagnosticsPlugin::default())
|
||||
.add_startup_system(setup)
|
||||
.add_system(move_cubes)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(move_cubes.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use bevy::prelude::*;
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,9 @@ use bevy::{
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_system(rotator_system)
|
||||
.add_system(camera_order_color_system)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(rotator_system.system())
|
||||
.add_system(camera_order_color_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_resource(Msaa { samples: 2 })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,6 @@ fn main() {
|
|||
App::build()
|
||||
.add_resource(Input(String::new()))
|
||||
.set_runner(my_runner)
|
||||
.add_system(print_system)
|
||||
.add_system(print_system.system())
|
||||
.run();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_resource(ScheduleRunnerSettings::run_once())
|
||||
.add_plugins(MinimalPlugins)
|
||||
.add_system(hello_world_system)
|
||||
.add_system(hello_world_system.system())
|
||||
.run();
|
||||
|
||||
// this app loops forever at 60 fps
|
||||
|
@ -22,7 +22,7 @@ fn main() {
|
|||
1.0 / 60.0,
|
||||
)))
|
||||
.add_plugins(MinimalPlugins)
|
||||
.add_system(counter)
|
||||
.add_system(counter.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ fn main() {
|
|||
// filter: "wgpu=warn,bevy_ecs=info".to_string(),
|
||||
// })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_system(log_system)
|
||||
.add_system(log_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@ impl Plugin for PrintMessagePlugin {
|
|||
message: self.message.clone(),
|
||||
timer: Timer::new(self.wait_duration, true),
|
||||
};
|
||||
app.add_resource(state).add_system(print_message_system);
|
||||
app.add_resource(state)
|
||||
.add_system(print_message_system.system());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ pub struct PrintHelloPlugin;
|
|||
|
||||
impl Plugin for PrintHelloPlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
app.add_system(print_hello_system);
|
||||
app.add_system(print_hello_system.system());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ pub struct PrintWorldPlugin;
|
|||
|
||||
impl Plugin for PrintWorldPlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
app.add_system(print_world_system);
|
||||
app.add_system(print_world_system.system());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_resource(Msaa { samples: 4 })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ fn main() {
|
|||
.init_resource::<State>()
|
||||
.add_asset::<CustomAsset>()
|
||||
.init_asset_loader::<CustomAssetLoader>()
|
||||
.add_startup_system(setup)
|
||||
.add_system(print_on_load)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(print_on_load.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use bevy::prelude::*;
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use bevy::prelude::*;
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ fn main() {
|
|||
.add_plugins(DefaultPlugins)
|
||||
// The "print diagnostics" plugin is optional. It just visualizes our diagnostics in the console
|
||||
.add_plugin(PrintDiagnosticsPlugin::default())
|
||||
.add_startup_system(setup_diagnostic_system)
|
||||
.add_system(my_system)
|
||||
.add_startup_system(setup_diagnostic_system.system())
|
||||
.add_system(my_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -257,9 +257,9 @@ fn main() {
|
|||
.init_resource::<GameState>()
|
||||
// Startup systems run exactly once BEFORE all other systems. These are generally used for
|
||||
// app initialization code (ex: adding entities and resources)
|
||||
.add_startup_system(startup_system)
|
||||
.add_startup_system(startup_system.system())
|
||||
// my_system calls converts normal rust functions into ECS systems:
|
||||
.add_system(print_message_system)
|
||||
.add_system(print_message_system.system())
|
||||
//
|
||||
// SYSTEM EXECUTION ORDER
|
||||
//
|
||||
|
@ -278,17 +278,17 @@ fn main() {
|
|||
// and the next stage won't start until all systems in the current stage have finished.
|
||||
// add_system(system) adds systems to the UPDATE stage by default
|
||||
// However we can manually specify the stage if we want to. The following is equivalent to add_system(score_system)
|
||||
.add_system_to_stage(stage::UPDATE, score_system)
|
||||
.add_system_to_stage(stage::UPDATE, score_system.system())
|
||||
// We can also create new stages. Here is what our games stage order will look like:
|
||||
// "before_round": new_player_system, new_round_system
|
||||
// "update": print_message_system, score_system
|
||||
// "after_round": score_check_system, game_over_system
|
||||
.add_stage_before(stage::UPDATE, "before_round", SystemStage::parallel())
|
||||
.add_stage_after(stage::UPDATE, "after_round", SystemStage::parallel())
|
||||
.add_system_to_stage("before_round", new_round_system)
|
||||
.add_system_to_stage("before_round", new_player_system)
|
||||
.add_system_to_stage("after_round", score_check_system)
|
||||
.add_system_to_stage("after_round", game_over_system)
|
||||
.add_system_to_stage("before_round", new_round_system.system())
|
||||
.add_system_to_stage("before_round", new_player_system.system())
|
||||
.add_system_to_stage("after_round", score_check_system.system())
|
||||
.add_system_to_stage("after_round", game_over_system.system())
|
||||
// score_check_system will run before game_over_system because score_check_system modifies GameState and game_over_system
|
||||
// reads GameState. This works, but it's a bit confusing. In practice, it would be clearer to create a new stage that runs
|
||||
// before "after_round"
|
||||
|
|
|
@ -7,8 +7,8 @@ fn main() {
|
|||
.add_plugins(DefaultPlugins)
|
||||
.add_event::<MyEvent>()
|
||||
.init_resource::<EventTriggerState>()
|
||||
.add_system(event_trigger_system)
|
||||
.add_system(event_listener_system)
|
||||
.add_system(event_trigger_system.system())
|
||||
.add_system(event_listener_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
// this system will run once every update (it should match your screen's refresh rate)
|
||||
.add_system(update)
|
||||
.add_system(update.system())
|
||||
// add a new stage that runs every two seconds
|
||||
.add_stage_after(
|
||||
stage::UPDATE,
|
||||
|
@ -20,7 +20,7 @@ fn main() {
|
|||
// labels are optional. they provide a way to access the current FixedTimestep state from within a system
|
||||
.with_label(LABEL),
|
||||
)
|
||||
.with_system(fixed_update),
|
||||
.with_system(fixed_update.system()),
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ use bevy::prelude::*;
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_system(rotate)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(rotate.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -74,8 +74,8 @@ fn bounce_system(
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(spawn_system)
|
||||
.add_system(move_system)
|
||||
.add_system(bounce_system)
|
||||
.add_startup_system(spawn_system.system())
|
||||
.add_system(move_system.system())
|
||||
.add_system(bounce_system.system())
|
||||
.run();
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ use bevy::prelude::*;
|
|||
|
||||
fn main() {
|
||||
App::build()
|
||||
.add_startup_system(startup_system)
|
||||
.add_system(normal_system)
|
||||
.add_startup_system(startup_system.system())
|
||||
.add_system(normal_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ fn main() {
|
|||
.init_resource::<ButtonMaterials>()
|
||||
.add_resource(State::new(AppState::Menu))
|
||||
.add_stage_after(stage::UPDATE, STAGE, StateStage::<AppState>::default())
|
||||
.on_state_enter(STAGE, AppState::Menu, setup_menu)
|
||||
.on_state_update(STAGE, AppState::Menu, menu)
|
||||
.on_state_exit(STAGE, AppState::Menu, cleanup_menu)
|
||||
.on_state_enter(STAGE, AppState::InGame, setup_game)
|
||||
.on_state_update(STAGE, AppState::InGame, movement)
|
||||
.on_state_update(STAGE, AppState::InGame, change_color)
|
||||
.on_state_enter(STAGE, AppState::Menu, setup_menu.system())
|
||||
.on_state_update(STAGE, AppState::Menu, menu.system())
|
||||
.on_state_exit(STAGE, AppState::Menu, cleanup_menu.system())
|
||||
.on_state_enter(STAGE, AppState::InGame, setup_game.system())
|
||||
.on_state_update(STAGE, AppState::InGame, movement.system())
|
||||
.on_state_update(STAGE, AppState::InGame, change_color.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use bevy::prelude::*;
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_resource(Message("42".to_string()))
|
||||
.add_system(parse_message_system.chain(handler_system))
|
||||
.add_system(parse_message_system.system().chain(handler_system.system()))
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ fn main() {
|
|||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_resource(Countdown::default())
|
||||
.add_startup_system(setup_system)
|
||||
.add_system(countdown_system)
|
||||
.add_system(timer_system)
|
||||
.add_startup_system(setup_system.system())
|
||||
.add_system(countdown_system.system())
|
||||
.add_system(timer_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,11 +10,11 @@ fn main() {
|
|||
.add_plugins(DefaultPlugins)
|
||||
.add_resource(Scoreboard { score: 0 })
|
||||
.add_resource(ClearColor(Color::rgb(0.9, 0.9, 0.9)))
|
||||
.add_startup_system(setup)
|
||||
.add_system(paddle_movement_system)
|
||||
.add_system(ball_collision_system)
|
||||
.add_system(ball_movement_system)
|
||||
.add_system(scoreboard_system)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(paddle_movement_system.system())
|
||||
.add_system(ball_collision_system.system())
|
||||
.add_system(ball_movement_system.system())
|
||||
.add_system(scoreboard_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
fn main() {
|
||||
App::build().add_system(hello_world_system).run();
|
||||
App::build().add_system(hello_world_system.system()).run();
|
||||
}
|
||||
|
||||
fn hello_world_system() {
|
||||
|
|
|
@ -3,7 +3,7 @@ use bevy::{prelude::*, window::ReceivedCharacter};
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_system(print_char_event_system)
|
||||
.add_system(print_char_event_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ fn main() {
|
|||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.init_resource::<GamepadLobby>()
|
||||
.add_system_to_stage(stage::PRE_UPDATE, connection_system)
|
||||
.add_system(gamepad_system)
|
||||
.add_system_to_stage(stage::PRE_UPDATE, connection_system.system())
|
||||
.add_system(gamepad_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use bevy::{
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_system(gamepad_events)
|
||||
.add_system(gamepad_events.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use bevy::{
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_system(keyboard_input_system)
|
||||
.add_system(keyboard_input_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use bevy::{input::keyboard::KeyboardInput, prelude::*};
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_system(print_keyboard_event_system)
|
||||
.add_system(print_keyboard_event_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use bevy::prelude::*;
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_system(mouse_click_system)
|
||||
.add_system(mouse_click_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use bevy::{
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_system(print_mouse_events_system)
|
||||
.add_system(print_mouse_events_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use bevy::{input::touch::*, prelude::*};
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_system(touch_system)
|
||||
.add_system(touch_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use bevy::{input::touch::*, prelude::*};
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_system(touch_event_system)
|
||||
.add_system(touch_event_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ fn main() {
|
|||
})
|
||||
.add_resource(Msaa { samples: 4 })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
/// set up a simple 3D scene
|
||||
|
|
|
@ -8,7 +8,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.register_type::<MyType<u32>>()
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ fn main() {
|
|||
.add_plugins(DefaultPlugins)
|
||||
.register_type::<Foo>()
|
||||
.register_type::<Bar>()
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use bevy::{prelude::*, reflect::TypeRegistry};
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.register_type::<MyType>()
|
||||
.run();
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@ fn main() {
|
|||
.add_plugins(DefaultPlugins)
|
||||
.register_type::<ComponentA>()
|
||||
.register_type::<ComponentB>()
|
||||
.add_startup_system(save_scene_system)
|
||||
.add_startup_system(load_scene_system)
|
||||
.add_startup_system(infotext_system)
|
||||
.add_system(print_system)
|
||||
.add_startup_system(save_scene_system.system())
|
||||
.add_startup_system(load_scene_system.system())
|
||||
.add_startup_system(infotext_system.system())
|
||||
.add_system(print_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_asset::<MyMaterial>()
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_asset::<MyMaterialWithVertexColorSupport>()
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_asset::<MyMaterial>()
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,11 @@ fn main() {
|
|||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_asset::<MyMaterial>()
|
||||
.add_startup_system(setup)
|
||||
.add_system_to_stage(stage::POST_UPDATE, asset_shader_defs_system::<MyMaterial>)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system_to_stage(
|
||||
stage::POST_UPDATE,
|
||||
asset_shader_defs_system::<MyMaterial>.system(),
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,11 +40,11 @@ fn main() {
|
|||
.add_plugin(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_resource(BevyCounter { count: 0 })
|
||||
.init_resource::<BirdMaterial>()
|
||||
.add_startup_system(setup)
|
||||
.add_system(mouse_handler)
|
||||
.add_system(movement_system)
|
||||
.add_system(collision_system)
|
||||
.add_system(counter_system)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(mouse_handler.system())
|
||||
.add_system(movement_system.system())
|
||||
.add_system(collision_system.system())
|
||||
.add_system(counter_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ fn main() {
|
|||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.init_resource::<ButtonMaterials>()
|
||||
.add_startup_system(setup)
|
||||
.add_system(button_system)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(button_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ fn main() {
|
|||
App::build()
|
||||
.init_resource::<State>()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_system(text_update_system)
|
||||
.add_system(atlas_render_system)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(text_update_system.system())
|
||||
.add_system(atlas_render_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ fn main() {
|
|||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_startup_system(setup)
|
||||
.add_system(text_update_system)
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(text_update_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ fn main() {
|
|||
})
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(FrameTimeDiagnosticsPlugin)
|
||||
.add_startup_system(infotext_system)
|
||||
.add_system(change_text_system)
|
||||
.add_startup_system(infotext_system.system())
|
||||
.add_system(change_text_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use bevy::prelude::*;
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ fn main() {
|
|||
.add_plugins(DefaultPlugins)
|
||||
.add_asset::<RustSourceCode>()
|
||||
.init_asset_loader::<RustSourceCodeLoader>()
|
||||
.add_startup_system(load_asset)
|
||||
.add_system(print_asset)
|
||||
.add_startup_system(load_asset.system())
|
||||
.add_system(print_asset.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ fn main() {
|
|||
)))
|
||||
.add_plugin(ScheduleRunnerPlugin::default())
|
||||
.add_plugin(LogPlugin::default())
|
||||
.add_startup_system(hello_world_system)
|
||||
.add_system(counter)
|
||||
.add_startup_system(hello_world_system.system())
|
||||
.add_system(counter.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use bevy::{log::LogPlugin, prelude::*};
|
|||
fn main() {
|
||||
App::build()
|
||||
.add_plugin(LogPlugin::default())
|
||||
.add_system(hello_wasm_system)
|
||||
.add_system(hello_wasm_system.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,12 +15,12 @@ fn main() {
|
|||
})
|
||||
.add_plugins(DefaultPlugins)
|
||||
// One time greet
|
||||
.add_startup_system(hello_wasm_system)
|
||||
.add_startup_system(hello_wasm_system.system())
|
||||
// Track ticks (sanity check, whether game loop is running)
|
||||
.add_system(counter)
|
||||
.add_system(counter.system())
|
||||
// Track input events
|
||||
.init_resource::<TrackInputState>()
|
||||
.add_system(track_input_events)
|
||||
.add_system(track_input_events.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ fn main() {
|
|||
App::build()
|
||||
.add_resource(Msaa { samples: 4 })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(setup.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ fn main() {
|
|||
..Default::default()
|
||||
})
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_system(change_title)
|
||||
.add_system(toggle_cursor)
|
||||
.add_system(change_title.system())
|
||||
.add_system(toggle_cursor.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue