-
-
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
Make EventReader a SystemParam #1244
Conversation
Very cool. For most things I don't want to encourage special-cased SystemParams as they increase api surface, but events are "core" enough that I think its worth investing in ergonomics.
Brilliant. Very glad to have that back. I punted it when adding lifetimes to SystemParams because I had no clue how to filter the generics. I'll add the pattern you used here to my repertoire 😄
I'm sold on that! |
Before merging, I'd suggest changing or extending the documentation. I'd do it, but I don't know what to add, I just have a feeling the docs emphasize the |
I've read over the changes, and like this PR a lot. The reduced API surface in particular is a good direction: I like being able to rely on core functionality more.
|
I would also like to see In the rare cases where you want full read or write access (like when processing raw events), you can use |
I love this change. The boilerplate was difficult to write from scratch from memory without looking at a reference implementation each time. This feels really intuitive (and cuts down on a lot of boilerplate). |
Hmm, |
|
The |
I changed it back since it was a minor change, though I don't think its necessary since we're only checking if an event occured, so its probably fine to use either. I originally chose next since it made simpler code. |
Changing next() to latest() (or next_back()) isn't a frivolous no-op. Calling next() in the context above results in:
This would result in dropping newer events if we queue up multiple in the same frame. If someone called |
Hmm, I thought it wouldn't matter since all events are erased at the end of the frame, do they last longer? Also, since we aren't looking at the state in the events, wouldn't A and B be identical |
Bawhaha you are absolutely right. I totally missed that we are just calling Thanks for keeping me honest 😄 |
(it really is a frivolous no-op) |
* Add generic support for `#[derive(SystemParam)]` * Make EventReader a SystemParam
This commit makes
EventReader
aSystemParam
to significantly cut down on boilerplate, and creates a simplifiedManualEventReader
to allow for use cases with direct access to Resources. As a necessary side effect, this commit also adds generic type support to#[derive(SystemParam)]
. Before a merge, I'd also suggest cutting theEventReader
API down to onlyiter()
anditer_with_id()
, since rust iterators provide more idiomatic solutions to the rest of the functions.