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

Minimal Bubbling Observers #13991

Merged
merged 21 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/bevy_ecs/macros/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub fn derive_event(input: TokenStream) -> TokenStream {

TokenStream::from(quote! {
impl #impl_generics #bevy_ecs_path::event::Event for #struct_name #type_generics #where_clause {
type Traverse = #bevy_ecs_path::traversal::TraverseNone;
const SHOULD_BUBBLE: bool = false;
}

impl #impl_generics #bevy_ecs_path::component::Component for #struct_name #type_generics #where_clause {
Expand Down
10 changes: 8 additions & 2 deletions crates/bevy_ecs/src/event/base.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::component::Component;
use crate::{component::Component, traversal::Traversal};
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
use std::{
Expand Down Expand Up @@ -31,7 +31,13 @@ use std::{
label = "invalid `Event`",
note = "consider annotating `{Self}` with `#[derive(Event)]`"
)]
pub trait Event: Component {}
pub trait Event: Component {
/// A system param that describes a traversal through the ECS.
NthTensor marked this conversation as resolved.
Show resolved Hide resolved
type Traverse: Traversal;

/// Sets the default bubling state of the entity when used with observers.
NthTensor marked this conversation as resolved.
Show resolved Hide resolved
const SHOULD_BUBBLE: bool;
NthTensor marked this conversation as resolved.
Show resolved Hide resolved
}

/// An `EventId` uniquely identifies an event stored in a specific [`World`].
///
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub mod removal_detection;
pub mod schedule;
pub mod storage;
pub mod system;
pub mod traversal;
pub mod world;

pub use bevy_ptr as ptr;
Expand Down
Loading