-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Simplify usage of EntityWorldMut::move_entity_from_remove
by making it a proper method
#17360
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
Conversation
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.
This broadly makes sense to me. Someone with more knowledge of our ECS internals to take a look tho.
self.location = unsafe { self.remove_bundle(bundle_info, caller) }; | ||
// SAFETY: the `BundleInfo` for this `bundle_id` is initialized above | ||
unsafe { | ||
self.remove_bundle(bundle_id, 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.
Not a big deal, but if you put the ;
outside the unsafe
block then rustfmt
might put it all on one line. (Here and below.)
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.
Slightly different semantics though; semicolon-outside is used to return something from the block to a variable.
I don't know how much we actually care about that, but we seem to follow it in this file at least.
/// Moves the entity to a new archetype, where the new archetype | ||
/// was a result of removing components from the entity's current archetype. | ||
/// | ||
/// When `DROP` is `true`, removed components will be dropped. |
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 notes about DROP
may have been in the "Safety" section because it would be unsound to drop the values if they've already been moved out.
On the other hand, having the component data be valid is the normal state. The fact that this doesn't drop when false
is just an extra behavior used to justify the safety requirements for the take_component
call.
So, yup, moving the notes on DROP
out of the "safety" section is an improvement! (Sorry for the noise; the safety logic here is a little subtle and I wanted to write down my train of thought when reviewing.)
@alice-i-cecile, think this is small enough to slip into 0.16? Also, I'd like to formally request the powers of labelling, if you wouldn't mind. |
The power of labelling has been bequeathed onto you (once you accept the invite) 👸🏽 As for 0.16 vs 0.17, I don't think this has any end user impact, so I'd like to leave this until 0.17 to avoid introducing unforeseen last-minute bugs <3 It'll get merged in my round-up once we start that though! |
This looks good to me, and I'm on board with the change, but if we plan to merge #18521, this would be a moot point. (That pr removes In other words, if we merge this, fixing merge conflicts with #18521 would just be undoing this. I'd be happy to do that if we're still undecided on that PR, but in the end, I think this is an either or situation. I don't think we can do both IIUC. Up to y'all which one you want to do. |
I prefer #18521, so I'm going to close this out :) |
Objective
Fixes #17345
The "probably more safety stuff" was probably referring to the
EntityLocation
needing to be valid for the givenEntity
or something like that, but that's not necessary if we just give it the actualEntityWorldMut
.Solution
&mut self
tomove_entity_from_remove
parameters.self
.location
field of theEntityWorldMut
, which wasn't necessarily the case before.EntityWorldMut::take
passed in a mutable reference to the field, so it already worked like that.EntityWorldMut::remove_bundle
passed in a mutable reference to a local variable, which it then returned so that its caller could use it to update thelocation
field. This seems unnecessarily convoluted.EntityWorldMut::remove_bundle
no longer returns the entity's location, as it is now updated internally.unsafe
blocks to some calls that had a safety note with no block.