-
Notifications
You must be signed in to change notification settings - Fork 422
0.13: One-Shot system Improvements #909
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
Changes from 2 commits
479c118
2cebad7
ef61402
8d314c2
22be921
140118c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,11 +63,38 @@ TODO. | |
|
|
||
| TODO. | ||
|
|
||
| ## Input for One-Shot Systems | ||
| ## One-Shot Systems Improvements | ||
|
|
||
| <div class="release-feature-authors">authors: @TODO</div> | ||
| <div class="release-feature-authors">authors: @Nathan-Fenner</div> | ||
|
|
||
| TODO. | ||
| In 0.12, we introduced [one-shot systems](https://bevyengine.org/news/bevy-0-12/#one-shot-systems), a handy way to call systems on demand without having to add them to a schedule. | ||
| The initial implementation had some limitations with regards to what systems could and could not be used as one-shot systems. | ||
| These limitations have since been resolved, starting with one-shot systems with in- and output. | ||
|
|
||
| ```rust | ||
|
|
||
| fn increment_sys(In(increment_by): In<i32>, mut counter: ResMut<Counter>) -> i32 { | ||
| counter.0 += increment_by; | ||
| counter.0 | ||
| } | ||
|
|
||
| let mut world = World::new(); | ||
| let id = world.register_system(increment_sys); | ||
|
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. The type of
Contributor
Author
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. For the sake of brevity, I think I'll leave it out of the main post, but I like the idea of adding type annotations and maybe a comment to the code example. I'll do that later. |
||
|
|
||
| world.insert_resource(Counter(1)); | ||
| let count_one = world.run_system_with_input(id, 5).unwrap(); // increment counter by 5 and return 6 | ||
| let count_two = world.run_system_with_input(id, 2).unwrap(); // increment counter by 2 and return 8 | ||
| ``` | ||
|
|
||
| Using either `world.run_system_with_input(system_id, input)` or `commands.run_system_with_input(system_id, input)`, you can now supply input parameters to systems that accept them. Additionally, both `world.run_system` and `world.run_system_with_input` now return system output as `Ok(output)`. Note that output cannot be returned when calling the system through commands, because of their deferred nature. | ||
|
|
||
| Some smaller improvements to one-shot systems include registering boxed systems with `register_boxed_system` (which was already possible since 12.1, but didn't get a blog post) and it being possible to register exclusive systems as one-shot systems. | ||
alice-i-cecile marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```rust | ||
| world.system_register(|world: &mut World| { /* do anything */ }); | ||
alice-i-cecile marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| All these improvements round out one-shot systems significantly and they should now behave normally in any Bevy context. | ||
|
|
||
| ## WGPU Upgrade | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.