-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Create a System Builder Syntax instead of using System Descriptors #2736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
0c6a837
Add SystemConfig and some basic options
569513c
Cargo format
983a2be
System Builder Rework - In Progress
abd6d8b
Rename StartupConfig to conform with other traits
52e7fff
Remove trait_casting feature
011af54
SystemSet handle ExclusiveSystems
ecb855b
Testing SubType impl for StageConfig
20fd625
Sort imports and remove double refs in app.rs
d9f7558
Attempt at fixing `SystemConfig`, `StartupConfig`.
Ratysz e83c519
Merge pull request #1 from Ratysz/system-builder-syntax
b540f79
Separate configs and conform with StageConfig
3bad094
Make more system additions use the new methods
325689b
Found a solution to exclusive errors
9aeb408
Revert solution
d7e1e2a
Fix broken startup functionality
4514032
Actually use the correct impl
251fb40
.stage all the things
0995f85
Fix bevy_render error
2d062e6
Fix final stage.rs error
9a2284e
Fix all remaining crate errors
5487f83
Fix examples
1d34d96
Format
9822b19
Merge branch 'main' into system-builder-syntax
e80fded
Format again
7b4bb30
Fix some ci errors
aee8c9d
Fix InsertionPoint panic
eb207e5
Fix startup error
0c9ac6a
Fixed copy pasta failure (insertion point test)
6c28d69
Remove redundant fn impl
085a5ef
Update System docs
55b797c
Reduce internal config function visibility and doc
c8914c1
More docs
0a32358
Update crates/bevy_ecs/src/schedule/stage.rs
0f6494b
Update crates/bevy_ecs/src/system/config/system_config.rs
91cb4c2
Update crates/bevy_ecs/src/system/system.rs
b272cb4
Add specific config trait docs
cf372a7
Add link to SystemStage doc
25b1d31
Add system set conflict validation
d360e14
Use .any rather than for loops
a762965
Maybe cleaner add system set conflict checking
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,9 @@ | ||
| use crate::{CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage}; | ||
| use bevy_ecs::{ | ||
| component::{Component, ComponentDescriptor}, | ||
| prelude::{FromWorld, IntoExclusiveSystem}, | ||
| schedule::{ | ||
| IntoSystemDescriptor, RunOnce, Schedule, Stage, StageLabel, State, SystemSet, SystemStage, | ||
| }, | ||
| prelude::{ExclusiveSystem, FromWorld, IntoExclusiveSystem, IntoSystem, StageConfig, System}, | ||
| schedule::{RunOnce, Schedule, Stage, StageLabel, State, SystemSet, SystemStage}, | ||
| system::BoxedSystem, | ||
| world::World, | ||
| }; | ||
| use bevy_utils::tracing::debug; | ||
|
|
@@ -50,7 +49,7 @@ impl Default for App { | |
|
|
||
| app.add_default_stages() | ||
| .add_event::<AppExit>() | ||
| .add_system_to_stage(CoreStage::Last, World::clear_trackers.exclusive_system()); | ||
| .add_exclusive(World::clear_trackers.stage(CoreStage::Last)); | ||
|
|
||
| #[cfg(feature = "bevy_ci_testing")] | ||
| { | ||
|
|
@@ -203,85 +202,108 @@ impl App { | |
| /// App::new() | ||
| /// .add_system(my_system); | ||
| /// ``` | ||
| pub fn add_system<Params>(&mut self, system: impl IntoSystemDescriptor<Params>) -> &mut Self { | ||
| self.add_system_to_stage(CoreStage::Update, system) | ||
| } | ||
|
|
||
| pub fn add_system_set(&mut self, system_set: SystemSet) -> &mut Self { | ||
| self.add_system_set_to_stage(CoreStage::Update, system_set) | ||
| } | ||
|
|
||
| pub fn add_system_to_stage<Params>( | ||
| &mut self, | ||
| stage_label: impl StageLabel, | ||
| system: impl IntoSystemDescriptor<Params>, | ||
| ) -> &mut Self { | ||
| self.schedule.add_system_to_stage(stage_label, system); | ||
| self | ||
| } | ||
|
|
||
| pub fn add_system_set_to_stage( | ||
| &mut self, | ||
| stage_label: impl StageLabel, | ||
| system_set: SystemSet, | ||
| ) -> &mut Self { | ||
| self.schedule | ||
| .add_system_set_to_stage(stage_label, system_set); | ||
| pub fn add_system<Params>(&mut self, system: impl IntoSystem<(), (), Params>) -> &mut Self { | ||
| let system = system.system(); | ||
| if system.config().startup { | ||
| let system = { | ||
| if system.config().stage.is_some() { | ||
| system | ||
| } else { | ||
| system.stage(StartupStage::Startup) | ||
| } | ||
| }; | ||
| self.schedule | ||
| .stage(CoreStage::Startup, |schedule: &mut Schedule| { | ||
| schedule.add_system(system) | ||
| }); | ||
| } else { | ||
| let system = { | ||
| if system.config().stage.is_some() { | ||
| system | ||
| } else { | ||
| system.stage(CoreStage::Update) | ||
| } | ||
| }; | ||
| self.schedule.add_system(system); | ||
| } | ||
| self | ||
| } | ||
|
|
||
| /// Adds a system that is run once at application startup | ||
| /// | ||
| /// Startup systems run exactly once BEFORE all other systems. These are generally used for | ||
| /// app initialization code (ex: adding entities and resources). | ||
| /// | ||
| /// * For adding a system that runs for every frame, see [`App::add_system`]. | ||
| /// * For adding a system to specific stage, see [`App::add_system_to_stage`]. | ||
| /// | ||
| /// ## Example | ||
| /// ``` | ||
| /// # use bevy_app::prelude::*; | ||
| /// # use bevy_ecs::prelude::*; | ||
| /// # | ||
| /// fn my_startup_system(_commands: Commands) { | ||
| /// println!("My startup system"); | ||
| /// } | ||
| /// | ||
| /// App::new() | ||
| /// .add_startup_system(my_startup_system); | ||
| /// ``` | ||
| pub fn add_startup_system<Params>( | ||
| &mut self, | ||
| system: impl IntoSystemDescriptor<Params>, | ||
| ) -> &mut Self { | ||
| self.add_startup_system_to_stage(StartupStage::Startup, system) | ||
| } | ||
|
|
||
| pub fn add_startup_system_set(&mut self, system_set: SystemSet) -> &mut Self { | ||
| self.add_startup_system_set_to_stage(StartupStage::Startup, system_set) | ||
| } | ||
| pub fn add_system_set(&mut self, set: SystemSet) -> &mut Self { | ||
keval6b marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fn ensure_no_conflicts(set: &SystemSet) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this could keep a reference to the conflicting stage name and add that to the panic message. Small suggestion, you could use this instead |
||
| if let Some(l) = set.systems | ||
| .iter() | ||
| .filter(|s| s.config().stage != set.config().stage) | ||
| .next() | ||
| .and_then(|s| s.config().stage.as_ref()) { | ||
| panic!("System set stage conflicts with internal exclusive system's stage: {:?}", l.as_ref()); | ||
| } | ||
| if let Some(l) = set.exclusive_systems | ||
| .iter() | ||
| .filter(|s| s.config().stage != set.config().stage) | ||
| .next() | ||
| .and_then(|s| s.config().stage.as_ref()) { | ||
| panic!("System set stage conflicts with internal exclusive system's stage: {:?}", l.as_ref()); | ||
| } | ||
| } | ||
|
|
||
| pub fn add_startup_system_to_stage<Params>( | ||
| &mut self, | ||
| stage_label: impl StageLabel, | ||
| system: impl IntoSystemDescriptor<Params>, | ||
| ) -> &mut Self { | ||
| self.schedule | ||
| .stage(CoreStage::Startup, |schedule: &mut Schedule| { | ||
| schedule.add_system_to_stage(stage_label, system) | ||
| }); | ||
| if set.config().startup { | ||
| let set = { | ||
| if set.config().stage.is_some() { | ||
| set | ||
| } else { | ||
| set.stage(StartupStage::Startup) | ||
| } | ||
| }; | ||
| ensure_no_conflicts(&set); | ||
| self.schedule | ||
| .stage(CoreStage::Startup, |schedule: &mut Schedule| { | ||
| schedule.add_system_set(set) | ||
| }); | ||
| } else { | ||
| let set = { | ||
| if set.config().stage.is_some() { | ||
| set | ||
| } else { | ||
| set.stage(CoreStage::Update) | ||
| } | ||
| }; | ||
| ensure_no_conflicts(&set); | ||
| self.schedule.add_system_set(set); | ||
| } | ||
| self | ||
| } | ||
|
|
||
| pub fn add_startup_system_set_to_stage( | ||
| pub fn add_exclusive<Params, SystemType>( | ||
| &mut self, | ||
| stage_label: impl StageLabel, | ||
| system_set: SystemSet, | ||
| ) -> &mut Self { | ||
| self.schedule | ||
| .stage(CoreStage::Startup, |schedule: &mut Schedule| { | ||
| schedule.add_system_set_to_stage(stage_label, system_set) | ||
| }); | ||
| system: impl IntoExclusiveSystem<Params, SystemType>, | ||
| ) -> &mut Self | ||
| where | ||
| SystemType: ExclusiveSystem + StageConfig<Params, SystemType>, | ||
| { | ||
| let system = system.exclusive_system(); | ||
| if system.config().startup { | ||
| let system = { | ||
| if system.config().stage.is_some() { | ||
| system | ||
| } else { | ||
| system.exclusive_system().stage(StartupStage::Startup) | ||
| } | ||
| }; | ||
| self.schedule | ||
| .stage(CoreStage::Startup, |schedule: &mut Schedule| { | ||
| schedule.add_exclusive(system) | ||
| }); | ||
| } else { | ||
| let system = { | ||
| if system.config().stage.is_some() { | ||
| system | ||
| } else { | ||
| system.exclusive_system().stage(CoreStage::Update) | ||
| } | ||
| }; | ||
| self.schedule.add_exclusive(system); | ||
| } | ||
| self | ||
| } | ||
|
|
||
|
|
@@ -307,7 +329,7 @@ impl App { | |
| T: Component + Debug + Clone + Eq + Hash, | ||
| { | ||
| self.insert_resource(State::new(initial)) | ||
| .add_system_set_to_stage(stage, State::<T>::get_driver()) | ||
| .add_system_set(State::<T>::get_driver().stage(stage)) | ||
| } | ||
|
|
||
| pub fn add_default_stages(&mut self) -> &mut Self { | ||
|
|
@@ -335,7 +357,7 @@ impl App { | |
| T: Component, | ||
| { | ||
| self.insert_resource(Events::<T>::default()) | ||
| .add_system_to_stage(CoreStage::First, Events::<T>::update_system) | ||
| .add_system(Events::<T>::update_system.stage(CoreStage::First)) | ||
| } | ||
|
|
||
| /// Inserts a resource to the current [App] and overwrites any resource previously added of the same type. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.