-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Remove entity placeholder from observers #19440
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
Changes from all commits
3d1cc8c
c7f1c5a
8be2b37
300193e
f6f5cf4
11826e4
7cba938
402abd7
2639cf0
eb4a499
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ use super::{unsafe_world_cell::UnsafeWorldCell, Mut, World, ON_INSERT, ON_REPLAC | |
/// | ||
/// This means that in order to add entities, for example, you will need to use commands instead of the world directly. | ||
pub struct DeferredWorld<'w> { | ||
// SAFETY: Implementors must not use this reference to make structural changes | ||
// SAFETY: Implementers must not use this reference to make structural changes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL these are both valid ways of spelling it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My typos just picked it up lol; just fixing those red squiggly lines. I can revert if this is the spelling bevy would prefer. I believe these spellings are regional. IDK which region bevy is sticking to (or if there's a way to manually pick one on my end). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we stick to american english largely, but I couldn't care less either way |
||
world: UnsafeWorldCell<'w>, | ||
} | ||
|
||
|
@@ -157,7 +157,7 @@ impl<'w> DeferredWorld<'w> { | |
if archetype.has_replace_observer() { | ||
self.trigger_observers( | ||
ON_REPLACE, | ||
entity, | ||
Some(entity), | ||
[component_id].into_iter(), | ||
MaybeLocation::caller(), | ||
); | ||
|
@@ -197,7 +197,7 @@ impl<'w> DeferredWorld<'w> { | |
if archetype.has_insert_observer() { | ||
self.trigger_observers( | ||
ON_INSERT, | ||
entity, | ||
Some(entity), | ||
[component_id].into_iter(), | ||
MaybeLocation::caller(), | ||
); | ||
|
@@ -738,7 +738,7 @@ impl<'w> DeferredWorld<'w> { | |
pub(crate) unsafe fn trigger_observers( | ||
&mut self, | ||
event: ComponentId, | ||
target: Entity, | ||
target: Option<Entity>, | ||
components: impl Iterator<Item = ComponentId> + Clone, | ||
caller: MaybeLocation, | ||
) { | ||
|
@@ -761,26 +761,28 @@ impl<'w> DeferredWorld<'w> { | |
pub(crate) unsafe fn trigger_observers_with_data<E, T>( | ||
&mut self, | ||
event: ComponentId, | ||
mut target: Entity, | ||
target: Option<Entity>, | ||
components: impl Iterator<Item = ComponentId> + Clone, | ||
data: &mut E, | ||
mut propagate: bool, | ||
caller: MaybeLocation, | ||
) where | ||
T: Traversal<E>, | ||
{ | ||
Observers::invoke::<_>( | ||
self.reborrow(), | ||
event, | ||
target, | ||
components.clone(), | ||
data, | ||
&mut propagate, | ||
caller, | ||
); | ||
let Some(mut target) = target else { return }; | ||
|
||
loop { | ||
Observers::invoke::<_>( | ||
self.reborrow(), | ||
event, | ||
target, | ||
components.clone(), | ||
data, | ||
&mut propagate, | ||
caller, | ||
); | ||
if !propagate { | ||
break; | ||
return; | ||
Comment on lines
+772
to
+785
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all these changes here to avoid checking if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. It just saves checking for some. It is kinda annoying to have the second |
||
} | ||
if let Some(traverse_to) = self | ||
.get_entity(target) | ||
|
@@ -792,6 +794,15 @@ impl<'w> DeferredWorld<'w> { | |
} else { | ||
break; | ||
} | ||
Observers::invoke::<_>( | ||
self.reborrow(), | ||
event, | ||
Some(target), | ||
components.clone(), | ||
data, | ||
&mut propagate, | ||
caller, | ||
); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation still talks about
Entity::PLACEHOLDER
, this should probably be updated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed!