Add a "run if any system param changed" run condition (building towards reactivity)
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Various state synchronization systems only need to be run when their inputs have changed.
If we can skip scheduling them, we can save work! However, keeping up with that requires a ton of boilerplate.
## What solution would you like?
WARNING: severe hand-waving ahead!
Create a simple `ReactiveSystem` trait, which caches information about the state of a system last time it ran (things like change ticks and event cursors).
For each system param, define a mechanism for it to check if things have changed. Events would use the event cursor, resource would use change ticks, queries might use the set of matched entities and/or change ticks.
A `input_changed` run condition would automatically inspect the system parameters, and then create a run condition system that caches and checks all of this information.
## What alternative(s) have you considered?
Obviously, these run conditions could be composed manually for each system, by combining our existing run conditions like `.resource_changed` and `.on_event`. This isn't particularly ergonomic or maintainable though!
This idea can also be extended via constructing a diff of events / entities between the last and current time the system ran. [In flecs, these are called monitors](https://www.flecs.dev/flecs/md_docs_2ObserversManual.html#monitors). This allows for a more granular diffing.
## Additional context
This idea was inspired by the flecs approach to reactivity via observers, which are effectively "systems that run when their query changes".
While this run condition would be handy in its own right, I think its true value lies in the infrastructure it would require. These concepts of "has this system param changed" could be
Contributor guide
Research direction
The issue names no files, tests, or entry points. Start by reviewing the existing `.resource_changed` and `.on_event` run conditions and the proposed `ReactiveSystem` trait; the design still needs to define how system parameters detect changes and what behavior establishes completion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100