-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
bevy_ecs: add untyped methods for inserting components and bundles #7204
Conversation
I like it! Needs more docs though. |
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.
Very nice, I'm happy with this now. Please feel free to resolve my previous comments to make reviewing easier.
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.
Very nice, I'm happy with this now. Please feel free to resolve my previous comments to make reviewing easier.
Controversial because we need to decide between this and #5602. |
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.
I left some comments.
What I would really like to see is a method for inserting a single component that doesn't require manual caching and unsafety (other than OwningPtr).
Thanks for the review @jakobhellermann @james7132! I made the following changes to address your review comments:
|
I like the new changes a lot; this is a much friendlier API now. |
Now that I think about it |
Worked like a charm, only The only drawback is I had to cache the storage types of bundle components, this seems relatively innocuous but can be relatively easily removed. |
0306cf5
to
504aec9
Compare
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 is going to be significantly slower than the typed API, but I don't think there's a solid way around that.
IMO we should clean up the HashMaps used in Bundles
, but that's strictly non-blocking and can be tackled in a follow-up PR.
bundle_ids: HashMap<TypeId, BundleId>, | ||
/// Cache dynamic [`BundleId`] with multiple components | ||
dynamic_bundle_ids: HashMap<Vec<ComponentId>, (BundleId, Vec<StorageType>)>, |
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.
Non-blocking: I feel like this could be better represented by putting StorageType
back into BundleInfo
and replacing the Vec<ComponentId>
with Vec<BundleComponent>
which contains both the ID and the storage type. The same for the 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.
Can definitely do this in a follow-up for removing dynamic components!
cf278f9
to
a2d9ddd
Compare
Rebased PR Renamed |
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.
Looks good to me. I think this is how we should do it. Minimally invasive, which I like.
This MR is a rebased and alternative proposal to #5602
Objective
Solution
add
EntityMut::insert_by_id
split
Bundle
intoDynamicBundle
withget_components
andBundle: DynamicBundle
. This allows theBundleInserter
machinery to be reused for bundles that can only be written, not read, and have no statically availableComponentIds
Compared to the original MR this approach exposes unsafe endpoints and requires the user to manage instantiated
BundleIds
. This is quite easy for the end user to do and does not incur the performance penalty of checking whether component input is correctly provided for theBundleId
.This MR does ensure that constructing
BundleId
itself is safeChangelog
world.entity_mut(entity).insert_by_id