-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[Merged by Bors] - Remove redundant table and sparse set component IDs from Archetype #4927
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
Closed
james7132
wants to merge
4
commits into
bevyengine:main
from
james7132:archetype-component-id-removal
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5c598c2
Remove table and sparse set component IDs from Archetype
james7132 c410d58
Merge branch 'main' into archetype-component-id-removal
james7132 c2cf143
Merge branch 'main' into archetype-component-id-removal
james7132 71262b2
Use the correct size_hint
james7132 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,40 +151,32 @@ pub struct Archetype { | |
| table_id: TableId, | ||
| edges: Edges, | ||
| entities: Vec<ArchetypeEntity>, | ||
| table_components: Box<[ComponentId]>, | ||
| sparse_set_components: Box<[ComponentId]>, | ||
| components: SparseSet<ComponentId, ArchetypeComponentInfo>, | ||
| } | ||
|
|
||
| impl Archetype { | ||
| pub fn new( | ||
| id: ArchetypeId, | ||
| table_id: TableId, | ||
| table_components: Box<[ComponentId]>, | ||
| sparse_set_components: Box<[ComponentId]>, | ||
| table_archetype_components: Vec<ArchetypeComponentId>, | ||
| sparse_set_archetype_components: Vec<ArchetypeComponentId>, | ||
| table_components: impl Iterator<Item = (ComponentId, ArchetypeComponentId)>, | ||
| sparse_set_components: impl Iterator<Item = (ComponentId, ArchetypeComponentId)>, | ||
| ) -> Self { | ||
| let mut components = | ||
| SparseSet::with_capacity(table_components.len() + sparse_set_components.len()); | ||
| for (component_id, archetype_component_id) in | ||
| table_components.iter().zip(table_archetype_components) | ||
| { | ||
| let (min_table, _) = table_components.size_hint(); | ||
| let (min_sparse, _) = table_components.size_hint(); | ||
| let mut components = SparseSet::with_capacity(min_table + min_sparse); | ||
| for (component_id, archetype_component_id) in table_components { | ||
| components.insert( | ||
| *component_id, | ||
| component_id, | ||
| ArchetypeComponentInfo { | ||
| storage_type: StorageType::Table, | ||
| archetype_component_id, | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| for (component_id, archetype_component_id) in sparse_set_components | ||
| .iter() | ||
| .zip(sparse_set_archetype_components) | ||
| { | ||
| for (component_id, archetype_component_id) in sparse_set_components { | ||
| components.insert( | ||
| *component_id, | ||
| component_id, | ||
| ArchetypeComponentInfo { | ||
| storage_type: StorageType::SparseSet, | ||
| archetype_component_id, | ||
|
|
@@ -194,10 +186,8 @@ impl Archetype { | |
| Self { | ||
| id, | ||
| table_id, | ||
| entities: Vec::new(), | ||
| components, | ||
| table_components, | ||
| sparse_set_components, | ||
| entities: Default::default(), | ||
| edges: Default::default(), | ||
| } | ||
| } | ||
|
|
@@ -218,13 +208,19 @@ impl Archetype { | |
| } | ||
|
|
||
| #[inline] | ||
| pub fn table_components(&self) -> &[ComponentId] { | ||
| &self.table_components | ||
| pub fn table_components(&self) -> impl Iterator<Item = ComponentId> + '_ { | ||
| self.components | ||
| .iter() | ||
| .filter(|(_, component)| component.storage_type == StorageType::Table) | ||
| .map(|(id, _)| *id) | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn sparse_set_components(&self) -> &[ComponentId] { | ||
| &self.sparse_set_components | ||
| pub fn sparse_set_components(&self) -> impl Iterator<Item = ComponentId> + '_ { | ||
| self.components | ||
| .iter() | ||
| .filter(|(_, component)| component.storage_type == StorageType::SparseSet) | ||
| .map(|(id, _)| *id) | ||
| } | ||
|
|
||
| #[inline] | ||
|
|
@@ -453,38 +449,33 @@ impl Archetypes { | |
| table_components: Vec<ComponentId>, | ||
| sparse_set_components: Vec<ComponentId>, | ||
| ) -> ArchetypeId { | ||
| let table_components = table_components.into_boxed_slice(); | ||
| let sparse_set_components = sparse_set_components.into_boxed_slice(); | ||
| let archetype_identity = ArchetypeIdentity { | ||
| sparse_set_components: sparse_set_components.clone(), | ||
| table_components: table_components.clone(), | ||
| sparse_set_components: sparse_set_components.clone().into_boxed_slice(), | ||
| table_components: table_components.clone().into_boxed_slice(), | ||
| }; | ||
|
|
||
| let archetypes = &mut self.archetypes; | ||
| let archetype_component_count = &mut self.archetype_component_count; | ||
| let mut next_archetype_component_id = move || { | ||
| let id = ArchetypeComponentId(*archetype_component_count); | ||
| *archetype_component_count += 1; | ||
| id | ||
| }; | ||
| *self | ||
| .archetype_ids | ||
| .entry(archetype_identity) | ||
|
Member
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. Not something that needs to be done here, but I think we can completely eliminate the redundant clones / allocations here related to ArchetypeIdentity:
|
||
| .or_insert_with(move || { | ||
| let id = ArchetypeId(archetypes.len()); | ||
| let table_archetype_components = (0..table_components.len()) | ||
| .map(|_| next_archetype_component_id()) | ||
| .collect(); | ||
| let sparse_set_archetype_components = (0..sparse_set_components.len()) | ||
| .map(|_| next_archetype_component_id()) | ||
| .collect(); | ||
| let table_start = *archetype_component_count; | ||
| *archetype_component_count += table_components.len(); | ||
| let table_archetype_components = | ||
| (table_start..*archetype_component_count).map(ArchetypeComponentId); | ||
| let sparse_start = *archetype_component_count; | ||
| *archetype_component_count += sparse_set_components.len(); | ||
| let sparse_set_archetype_components = | ||
| (sparse_start..*archetype_component_count).map(ArchetypeComponentId); | ||
| archetypes.push(Archetype::new( | ||
| id, | ||
| table_id, | ||
| table_components, | ||
| sparse_set_components, | ||
| table_archetype_components, | ||
| sparse_set_archetype_components, | ||
| table_components.into_iter().zip(table_archetype_components), | ||
| sparse_set_components | ||
| .into_iter() | ||
| .zip(sparse_set_archetype_components), | ||
| )); | ||
| id | ||
| }) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.