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. |
|
@ItsDoot this has some conflicts, could you resolve them? |
|
needs a few fixes for CI |
alice-i-cecile
left a comment
There was a problem hiding this comment.
From my merge train notes:
Oh ho-ho: a beefy one! Getting rid of the bundle generic in observers is something I've wanted to do for years now.
Moving it to the lifecycle events makes perfect sense, and it's great to see that we could actually get something that compiles here.Let's pull this down for a more complete review: this is literally my job as an SME-ECS.
Okay, I see: we're extending the class of things that can be used in observers toEventPattern, as a superset ofEvents.
Makes sense.
EventPatternis not my favorite name, but I can live with it since I don't have a better suggestion.Solid docs for some genuinely complex machinery. The cross-links are incredibly important for putting together an understanding of what's going on.
Migration guide is good, and has the added benefit of verifying that the dynamic component case was not lost.
This has my approval.
@cart self-requested a review a few days ago though.
I'm going to ping him before merging this; there's no immediate rush, as badly as I want this.
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
|
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 hidden away for the cases where it is not needed.
Solution
Introduce a thin 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.