-
-
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
Consolidate Events and Commands #1251
Comments
Commands are currently made of two "parts":
Unlike events, commands handle a state with the current entity. I can see a few ways to split the two and make it work as events, but I don't think the user facing api would be nicer that the current one |
Theres also a potential non-event layer to commands that I think we want: command optimization. Ex: we can cut down on archetype changes by merging "insert bundle and insert component" commands together. |
That's very useful context. Handling the list of commands as an event queue seems like a fairly clear win, but the larger change would have more costs. If we wanted to push forward with fully merging events and commands I think we would need to:
Then, you could have commands.spawn return the
Advantages
Disadvantages
Edit: it also looks like this functionality is used by |
I'm closing this for now: the idea will crop up again naturally if there's ever a clean way to do it. |
What problem does this solve or what need does it fill?
Events and Commands share very similar conceptual models, but use completely disjoint code.
What solution would you like?
Make
Commands
a built-in event type that stores data, and then useEvent<Commands>
to access commands in the system. Consume the commands one at a time as they're processed at the end of each stage.Reuse the existing tech from
Commands
to allow for parallel write-to-end behavior of events when supplied viaEvent<MyEvent>
, allowing us to run systems that add events of the same type at the same time.What alternative(s) have you considered?
Leaving these distinct allows us to diverge behavior further if needed. I think the basic design space of
Commands
has been sufficiently explored that it's clear that they should work the same way however. If there's other tweaks or APIs needed for commands down the road, it's likely that other types of events will want it too.We could also have Commands use events under the hood and leave the slightly shorter public API the same, but I think that's needlessly obfuscatory. The fact that we can handle Commands using a built-in events system is intuitive and cool, and makes them easier to extend for advanced users.
Additional context
Making events a system parameter in #1244 makes this even more natural, since event readers are now special-cased, rather than simply being resources.
The text was updated successfully, but these errors were encountered: