bevy/examples/ecs
Trashtalk217 e4b368721d
One Shot Systems (#8963)
I'm adopting this ~~child~~ PR.

# Objective

- Working with exclusive world access is not always easy: in many cases,
a standard system or three is more ergonomic to write, and more
modularly maintainable.
- For small, one-off tasks (commonly handled with scripting), running an
event-reader system incurs a small but flat overhead cost and muddies
the schedule.
- Certain forms of logic (e.g. turn-based games) want very fine-grained
linear and/or branching control over logic.
- SystemState is not automatically cached, and so performance can suffer
and change detection breaks.
- Fixes https://github.com/bevyengine/bevy/issues/2192.
- Partial workaround for https://github.com/bevyengine/bevy/issues/279.

## Solution

- Adds a SystemRegistry resource to the World, which stores initialized
systems keyed by their SystemSet.
- Allows users to call world.run_system(my_system) and
commands.run_system(my_system), without re-initializing or losing state
(essential for change detection).
- Add a Callback type to enable convenient use of dynamic one shot
systems and reduce the mental overhead of working with Box<dyn
SystemSet>.
- Allow users to run systems based on their SystemSet, enabling more
complex user-made abstractions.

## Future work

- Parameterized one-shot systems would improve reusability and bring
them closer to events and commands. The API could be something like
run_system_with_input(my_system, my_input) and use the In SystemParam.
- We should evaluate the unification of commands and one-shot systems
since they are two different ways to run logic on demand over a World.

### Prior attempts

- https://github.com/bevyengine/bevy/pull/2234
- https://github.com/bevyengine/bevy/pull/2417
- https://github.com/bevyengine/bevy/pull/4090
- https://github.com/bevyengine/bevy/pull/7999

This PR continues the work done in
https://github.com/bevyengine/bevy/pull/7999.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Federico Rinaldi <gisquerin@gmail.com>
Co-authored-by: MinerSebas <66798382+MinerSebas@users.noreply.github.com>
Co-authored-by: Aevyrie <aevyrie@gmail.com>
Co-authored-by: Alejandro Pascual Pozo <alejandro.pascual.pozo@gmail.com>
Co-authored-by: Rob Parrett <robparrett@gmail.com>
Co-authored-by: François <mockersf@gmail.com>
Co-authored-by: Dmytro Banin <banind@cs.washington.edu>
Co-authored-by: James Liu <contact@jamessliu.com>
2023-09-19 20:17:05 +00:00
..
apply_deferred.rs Have a separate implicit viewport node per root node + make viewport node Display::Grid (#9637) 2023-09-19 15:14:46 +00:00
component_change_detection.rs Remove useless single tuples and trailing commas (#9720) 2023-09-08 21:46:54 +00:00
custom_query_param.rs Fixed several missing links in docs. (#8117) 2023-04-23 17:28:36 +00:00
ecs_guide.rs Allow tuples and single plugins in add_plugins, deprecate add_plugin (#8097) 2023-06-21 20:51:03 +00:00
event.rs Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
fixed_timestep.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
generic_system.rs Remove OnUpdate system set (#8260) 2023-04-04 00:49:41 +00:00
hierarchy.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
iter_combinations.rs Improve execution of examples in CI (#9331) 2023-08-03 12:45:28 +00:00
nondeterministic_system_order.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
one_shot_systems.rs One Shot Systems (#8963) 2023-09-19 20:17:05 +00:00
parallel_query.rs Improve execution of examples in CI (#9331) 2023-08-03 12:45:28 +00:00
removal_detection.rs Remove some old references to CoreSet (#9833) 2023-09-18 01:07:11 +00:00
run_conditions.rs Add or_else combinator to run_conditions.rs (#8714) 2023-05-31 16:52:36 +00:00
startup_system.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
state.rs Have a separate implicit viewport node per root node + make viewport node Display::Grid (#9637) 2023-09-19 15:14:46 +00:00
system_closure.rs Allow tuples and single plugins in add_plugins, deprecate add_plugin (#8097) 2023-06-21 20:51:03 +00:00
system_param.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
system_piping.rs Add system.map(...) for transforming the output of a system (#8526) 2023-08-28 16:36:46 +00:00
timers.rs Fix timers.rs documentation (#9290) 2023-07-30 15:30:05 +00:00