Implement methods to list all components and all resources (Rebase of PR #3012)#4955
Implement methods to list all components and all resources (Rebase of PR #3012)#4955KevinKeyser wants to merge 10 commits intobevyengine:mainfrom
Conversation
This allows iteration over all `Component`s registered in a world by implementing `IntoIterator` for the `Components` type.
the Components struct was not just storing metadata on components, but also on resources. WorldData is a new umbrella term for components and resources. also rename the following: `ComponentId` -> `DataId` `ComponentInfo` -> `DataInfo` `ComponentDescriptor` -> `DataDescriptor`
These can be used in systems to get an overview over all available Components and Resources.
Co-authored-by: MinerSebas <66798382+MinerSebas@users.noreply.github.com>
|
My instinct is that we should merge #4809 first, which should simplify the implementation here significantly. @james7132, are you in agreement? |
|
For what it's worth you can iterate over all component infos already: bevy/crates/bevy_ecs/src/component.rs Line 401 in 7317473 To find all resource component IDs you can just the components in the resource archetype, something like |
|
@KevinKeyser Is this a dead PR at this point? |
| fn iterate_resources() { | ||
| let mut world = World::default(); | ||
| world.insert_resource(Vec::<String>::new()); | ||
| world.insert_resource(42usize); |
There was a problem hiding this comment.
These will have to be redone to account for the opt-in Resource trait.
| } | ||
|
|
||
| #[test] | ||
| fn remove_tracking() { |
There was a problem hiding this comment.
| fn remove_tracking() { | |
| fn removal_tracking() { |
Just to reduce diff noise.
alice-i-cecile
left a comment
There was a problem hiding this comment.
This is quite nice: I really like how much clearer DataId and WorldData are. If you rebase this and get CI passing I'd be happy to see this merged basically as is.
|
@KevinKeyser I still really like this work, but at this point it's going to be easier to remake this PR than to solve merge conflicts. I'm going to |
|
I'd like to pick this up soon. |
|
|
||
| // SAFE: no component value access | ||
| unsafe impl SystemParamState for ComponentsState { | ||
| unsafe impl<'a> SystemParamState for ComponentsState { |
There was a problem hiding this comment.
Probably trivial, but is this explicit lifetime required?
| }; | ||
| let component_id = if let Some(component_id) = self.data.get_resource_id(TypeId::of::<R>()) | ||
| { | ||
| component_id |
There was a problem hiding this comment.
Should this be resource_id or data_id (as well as in other related functions)?
|
I'm hoping that this PR will help permit me to more easily serialize specific components (when I only have the name) of an entity as well as overwrite the state of a component by deserializing a previous state's Edit: I can get a |
|
@matiqo15, this seems really useful for bevyengine/rfcs#77. Perhaps we should re-adopt it and get the basic form merged? |
Agree, this could help a lot |
# Objective - Closes #12019 - Related to #4955 - Useful for dev_tools and networking ## Solution - Create `World::iter_resources()` and `World::iter_resources_mut()` --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: James Liu <contact@jamessliu.com> Co-authored-by: Pablo Reinhardt <126117294+pablo-lua@users.noreply.github.com>
# Objective - Closes bevyengine#12019 - Related to bevyengine#4955 - Useful for dev_tools and networking ## Solution - Create `World::iter_resources()` and `World::iter_resources_mut()` --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: James Liu <contact@jamessliu.com> Co-authored-by: Pablo Reinhardt <126117294+pablo-lua@users.noreply.github.com>
|
@alice-i-cecile Now that #12829 has been merged, is this PR still necessary? |
|
It would still be nice to have something like this for components, but I'm going to close this out regardless. |
Objective
Solution
Changelog
struct ComponentId->struct DataIdstruct Components->struct WorldDataComponents::components->WorldData::datastruct ComponentInfo->struct DataInfostruct ComponentDescriptor->struct DataDescriptor