-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Event-component-system #2309
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
Comments
Would you mind clarifying how/why the current event system via |
I probably need to write a more complex example. Yes, you can now create your own event types, but you won't be able to make smart queries like With <> or Without <>. Now, if there are many types of events, it will be easy to get confused and difficult to control, or systems can be falsely triggered, wasting computer resources. |
You can put |
@simensgreen fn run_if_has_event<T>(events: EventReader<T>) -> ShouldRun {
if events.iter().next().is_some() {
ShouldRun::Yes
} else {
ShouldRun::No
}
} as the run criteria solve your use case? |
Have you seen my EventHandler pattern discussed in bevyengine/rfcs#25? If I understand what you're after, it aims to solve a very similar set of patterns in a more direct fashion. |
@simensgreen |
Yes, it seems bevyengine/rfcs#25 really looks like what I was thinking. Now I do not have much time to fully study the issue, but when the time comes, I will return to this. |
What problem does this solve or what need does it fill?
What solution would you like?
Each event has a set of components, systems waiting for events are transferred to the class of event handlers and are called only when there is an event with a suitable set of components.
For example, the event when the user pressed a key on the keyboard can have the components
KeyPress(usize)
,UserInput
, the cursor movement eventUserInput
,Cursor
,Position(usize, usize)
, and an event generated by some system, for example, the player "jumped" -PlayerEvent
,Jump{vector: Vec2}
Naturally, this can be connected to an existing ecs and the system will be called with a set of components from the world and a set of components from an event.
Here is an example of pseudocode (as I see it), I think those who read this perfectly understand the capabilities of
ecs
without this example, but stillWhat alternative(s) have you considered?
The current alternatives with signal and receiver systems look good, but
ecs
will give flexibility in my opinionI also considered two options for calling systems:
While I'm thinking about it, and it seems to me the option with the accumulation of events is safer and easier to implement.
Additional context
I wrote a small python example (as a prototype). You can see the link
The text was updated successfully, but these errors were encountered: