Replies: 4 comments 4 replies
-
Hmm, you might actually manage to make this work in a context where you have access to trait Event {
fn send(self, resources: &mut Resources) {
resources.get_mut::<Events<Self>>().unwrap().send(self).unwrap();
}
} (the actıal impl might need to be a bit different to comply with object safety rules) This way, you can send any event without knowing the actual type, but these events might arrive slightly delayed, as they can only be applied at a hard sync point. On a different note, I'm curious how you deserialize incoming events, and your overall architecture. With more info, perhaps a more efficient solution can be found. |
Beta Was this translation helpful? Give feedback.
-
I've seen this same sort of pattern come up in both UI prototyping and dispatching user inputs. I think this is worth pursuing a solution for, in some form or another. |
Beta Was this translation helpful? Give feedback.
-
I've put together a small macro to simplify sending multiple event types at once, called event_set that kind of does what I wanted (or at least is a sufficient workaround). It doesn't need an exclusive system or any special syntax, instead it uses It's very basic and there's probably some complexities & edge cases that I missed. I also don't think a macro like this would be the way to go if something like it was implemented in Bevy itself. But it might be useful as inspiration or a jumping-off point. |
Beta Was this translation helpful? Give feedback.
-
This problem seems quite similar to error management in Rust - as in, "why do we have a new library for error handling seemingly every month". Might be a good idea to look for inspiration in that space. |
Beta Was this translation helpful? Give feedback.
-
Situation
I'm currently experimenting with a netcode system. When a packet comes in, the receiver system process it and sends the corresponding event. Each of these events then needs to be interpreted by the system that's responsible for that event type (movement, inventory, ...).
Problem
Using multiple event queues this way works up to a point, but I'm up to 10 different events already and foreseeing more as I add features to the game. So this is not scalable and the function signatures of my systems are massive and difficult to parse with all these different event emitters.
The usual solution would be to use an enum. However, this means that each system that is responsible for processing one of the events would need to read and iterate through all events in the queue and filter out the events it's individually responsible for, rather than being able to use a scoped event queue based on the event type.
Solution
I would like to be able to send to any event queue based on the type passed in, rather than the generic type in
Events<T>
.Something like:
So I'd like to hear some thoughts/feedback on this idea. What problems are there with this approach that I didn't think of, would it be at all feasible to implement something like this in Bevy, are there any alternative approaches that would solve this problem as well that hadn't occurred to me, ...
Beta Was this translation helpful? Give feedback.
All reactions