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. 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