Observer EventPatterns#24013
Conversation
james-j-obrien
left a comment
There was a problem hiding this comment.
Cool approach! Looks good.
Diddykonga
left a comment
There was a problem hiding this comment.
LGTM
Abstracts the E: Event and B: Bundle from On<E, B> into On<E> where E: EventMatcher
This allows the syntax to be like Add<C>, while the actual semantics use the Event and Components associated types on the EventMatcher. Similiar-ish to an custom WorldQuery.
chescock
left a comment
There was a problem hiding this comment.
Nice, this is an elegant way to solve this! I like how a bunch of B generics disappeared from places that don't care about them.
|
I'm curious about the answers to @chescock's questions :) FYI, I'm planning to hold off merging this until after we cut the 0.19-rc, so we can land this together with a F: QueryFilter generic in 0.20. |
| //! This is particularly useful in combination with immutable components, | ||
| //! to avoid any lifecycle-bypassing mutations. | ||
| //! | ||
| //! ## Lifecycle events and component types |
There was a problem hiding this comment.
I think this section needs to be updated slightly?
Objective
On<E, B>'sBtype parameter is the single most commonly confusing construct inbevy_ecs. The predominate use case is for filtering lifecycle event observers:For most other use cases, like picking or custom user events, this type parameter is wholly unnecessary.
Therefore, it should be removed from view for the cases where it is not needed.
Solution
Introduce a tiny layer above
EventcalledEventPattern, and updateOn's bounds:This allows us to lift the
Btype parameter inOn<E, B>into theEtype parameter. To ensure other events like picking continue to work, we introduce a blanket implementation for allEvents:To facilitate lifecycle events, we first rename them as follows:
Add->AddEventInsert->InsertEventDiscard->DiscardEventRemove->RemoveEventDespawn->DespawnEventThen, we introduce new generic types in place of those old identifiers that are
EventPatterns:This results in a slightly modified observer setup:
Testing
No new tests have been added, we have decent coverage of observer tests as is.