-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I decided to implement remote triggers on top of events to reuse existing logic. Unlike events, we can't simply observe and re-trigger, as we need access to all targets. To address this, we provide a special `RemoteTrigger` and extension traits for sending these events internally. Both global and targeted triggers are supported. But we don't support component-based targets yet, only entity-based. To allow users to override serialization without manually writing it for for event targets, I replaced the bare serialization functions with an abstraction similar to component rules. Additionally, I updated how `ClientEvent` is created internally to cleanly reuse this logic for triggers. For API examples see documentation changes in `lib.rs`.
- Loading branch information
Showing
14 changed files
with
1,386 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
pub mod client_event; | ||
pub mod client_trigger; | ||
pub mod ctx; | ||
pub mod event_fns; | ||
pub(crate) mod event_registry; | ||
pub mod server_event; | ||
pub mod server_trigger; | ||
|
||
use bevy::prelude::*; | ||
|
||
/// An event that used under the hood for client and server triggers. | ||
/// | ||
/// We can't just observe for triggers like we do for events since we need access to all its targets | ||
/// and we need to buffer them. This is why we just emit this event instead and after receive drain it | ||
/// to trigger regular events. | ||
/// | ||
/// Traditional trigger interface is provided by [`ClientTriggerExt`](client_trigger::ClientTriggerExt) | ||
/// and [`ServerTriggerExt`](server_trigger::ServerTriggerExt). | ||
#[derive(Event)] | ||
struct RemoteTrigger<E> { | ||
event: E, | ||
targets: Vec<Entity>, | ||
} |
Oops, something went wrong.