Skip to content
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

Swap to using EventWriter and EventReader in internal engine code #3397

Closed
alice-i-cecile opened this issue Dec 20, 2021 · 1 comment
Closed
Labels
C-Code-Quality A section of code that is hard to understand or change D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@alice-i-cecile
Copy link
Member

Many of our internal systems were written before the advent of EventWriter and EventReader, and so work with either ResMut<Events<T>> or Res<Events<T>>.

These can (and probably should) generally be swapped to EventWriter and EventReader because:

  1. The intent is clearer, making the code easier to later modify and read.
  2. The API is smaller, making it harder for subtle bugs to be introduced.
  3. Any later optimizations we might perform will rely on EventReader and EventWriter, rather than the raw resource types.

You can see an example here:

pub fn gilrs_event_system(

Finding all of these should be easy, just search for Res<Events and ResMut<Events in the code base. Fixing them should be similarly straightforward, although please leave a comment in your PR if you found any usages that could not be trivially converted.

@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy C-Code-Quality A section of code that is hard to understand or change labels Dec 20, 2021
@PaperCow
Copy link
Contributor

PaperCow commented Dec 21, 2021

I wasn't actually able to find any other references to Res<Events or ResMut<Events in the code base outside of the given example. It appears they were mostly removed in #1244 and #1575 but the example in this issue was added after these PRs.

Assuming I'm not just missing some other references, I made a PR #3413 to clean up this one instance.

@bors bors bot closed this as completed in 004bbe9 Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Code-Quality A section of code that is hard to understand or change D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants