Add a variant of Events::update that returns the removed events#9542
Add a variant of Events::update that returns the removed events#9542alice-i-cecile merged 6 commits intobevyengine:mainfrom
Events::update that returns the removed events#9542Conversation
alice-i-cecile
left a comment
There was a problem hiding this comment.
I'd like a bit of reassurance that this compiles down to the same code as a naive "duplicate the code" solution, but I won't block on it.
A doc test would be good too.
Calling I will add a test or two. |
|
@JoJoJet this needs to have merge conflicts resolved, then I'll merge :) |
…vyengine#9542) # Objective Every frame, `Events::update` gets called, which clears out any old events from the buffer. There should be a way of taking ownership of these old events instead of throwing them away. My use-case is dumping old events into a debug menu so they can be inspected later. One potential workaround is to just have a system that clones any incoming events and stores them in a list -- however, this requires the events to implement `Clone`. ## Solution Add `Events::update_drain`, which returns an iterator of the events that were removed from the buffer.
Objective
Every frame,
Events::updategets called, which clears out any old events from the buffer. There should be a way of taking ownership of these old events instead of throwing them away. My use-case is dumping old events into a debug menu so they can be inspected later.One potential workaround is to just have a system that clones any incoming events and stores them in a list -- however, this requires the events to implement
Clone.Solution
Add
Events::update_drain, which returns an iterator of the events that were removed from the buffer.