-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Ergonomic pause functionality #1353
Comments
How does this work? Is this intentional? |
Events are buffered for exactly one frame. Change detection flags are cleared at the end of the frame. One of the proposals at #68 would fix the problem for change detection. As far as I know there is nothing for events (yet). |
You can manually handle Events' survival by adding them as a Resource, rather than using |
Yeah theres nothing that solves this problem for events yet. Some options:
The last one feels like a reasonable approach that could be used everywhere. |
This is a very interesting idea, especially as a standard behavior. You could extend it to support "consuming events" nicely, and I wonder if you could use it to enable #1273. The main drawback I could see is that it would complicate adding systems dynamically mid-execution, but I don't think that's impossible to get around. I'm partial to the idea of making change detection and events both robust to systems not being run: it seems much more elegant than implementing a special |
|
An implementation needed for the subscriber approach can be seen in the |
👍 for storing events in a RingBuffer and tracking consumers to know when to drop events. It seems like there is kind of a general pattern between this and change detection where basically the system wants to apply its own state to some resource/component before passing a view of the data to the user's function. For instance:
Or for events
I think there is an opportunity to implement this generally enough to support various cases like this, but I'm not familiar enough with the inner workings of bevy to know exactly how to accomplish this. |
Would it be possible for the scheduler to calculate the number of |
@Davier don't you still need a way for each consumer to individually track what events they've seen? Otherwise systems that run every tick will see repeated events as long as they're kept alive from systems that haven't run yet. Also seems like excess memory to track things on an event-by-event basis rather than just tracking an index. |
Event readers already do this by saving the event counter, what I suggested builds on top of it.
Yes, if we register the event readers we can have a system that periodically checks their event counter and drops events, avoiding the extra memory per event. I think that it's a trade-off between memory and execution time. |
There's another ongoing discussion where one of proposals replaces the flag by the generation number field exactly to solve that kind of issue, events won't be lost in that case. Would not it solve this problem too? |
Currently events are not components, they are stored in their own buffers. It could be great to have each event instance be an entity and the event type a component, but the problem is that events need to be sent instantly while entities are spawned at the end of the stage. |
You could get around this by spawning an event entity on startup when the event is initialized. The larger issue, IMO, is that by making them entities with components, you lose the ability to write to events from multiple systems at once by appending to the end of the buffer. |
Additional use case example. I would like to build a universe simulation with an in game clock. The Res<WorldTime> would need to be in sync with Res<Time> but could be paused or accelerated. While certain systems may still be run for things like animation, input handling, etc and use realtime. Certain other simulations like physics, orbital mechanics, day night cycles, etc would be tied to the WorldTime, especially ones which use that time to control certain aspects of their updates or component mutations. It would be nice if Time and WorldTime were synced within the engine and ergonomic to use. |
Tied up in the life-cycle / states / scheduling designs discussed in #2801. |
Looking at the implementation and demo of #8063, I think we can very lightly tweak the tools added there to get this basically for free! |
I'm calling this fixed by #8964 now. |
What problem does this solve or what need does it fill?
We can disable systems using run criteria (or StateStages) to pause the game. Unfortunately, if you simply disable the systems using StateStage, any events (and change detection) changes that are currently in flight are lost.
What solution would you like?
A pair of methods to pause and unpause a system set, activated via commands. Under the hood, this should implement the work-around listed below, automatically caching any events and changes that the systems in the system set consume.
Under the hood, this might makes sense to be a State, and use the enter / exit logic to handle this.
What alternative(s) have you considered?
To get around this, you could write some logic to handle system entry and exit, but then you need to repeat it for every relevant event type, and also muck around by manually caching component flags (but only the ones that are used by the paused systems?) and then reloading them
Additional context
This relates to #68, #1157 and #1297. This issue was created in response to this comment in #1345 .
The text was updated successfully, but these errors were encountered: