-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Objective Working with `World` is painful due to lifetime issues and a lack of ergonomics, so you may want to delegate to the system API. Your current options are: - `world.run_system_once`, which initializes the system each time it's called (performance cost) and doesn't support `Local`. The docs recommend users not use this method outside of diagnostic use cases like unit tests. - `world.run_system`, which requires you to register the system and store the `SystemId` somewhere (made easier by implementing `FromWorld` for a newtyped `Local`, unless you're in e.g. a custom `Command` impl). These options work, but you're choosing between a performance cost and an ergonomic challenge. ## Solution Provide a cached `run_system` API that accepts an `S: IntoSystem` and checks for a `CachedSystemId<S::System>(SystemId)` resource. If it doesn't exist, it will register the system and save its `SystemId` in that resource. In other words, it hides the "save the `SystemId` in a `Local` or `Resource`" pattern as an implementation detail. Prior work: #10469. ## Testing This approach worked in a proof-of-concept: https://github.com/benfrankel/bevy_jam_template/blob/b34ee29531e3ceae287a9cc44ec6c520e83a4cdd/src/util/patch/run_system_cached.rs#L35. A new unit test was added and it passes in CI.
- Loading branch information
1 parent
4682f33
commit f78856b
Showing
3 changed files
with
212 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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