-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[Merged by Bors] - Extend EntityLocation with TableId and TableRow #6681
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
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4da38b0
Add TableId and ArchetypeId
james7132 2da3328
Cleanup
james7132 be7bf27
Shrink ArchetypeId
james7132 0b9c1d3
Use TableId from EntityLocation
james7132 a9d4be9
Add docs for TableId.
james7132 bf10fe8
Type level docs for TableId
james7132 58753f7
Add safety docs for EntityMeta and EntityLocation.
james7132 32873bb
Update safety docs for EntityRef functions
james7132 18b08b8
Formatting
james7132 b25800e
Fix backtick
james7132 cf5f87f
Merge branch 'main' into flatten-entity-location
james7132 ace0173
Merge branch 'main' into flatten-entity-location
james7132 ac7f1eb
Fix docs
james7132 2952556
Merge branch 'main' into flatten-entity-location
james7132 9b133d9
Fix build
james7132 38093e7
Merge branch 'main' into flatten-entity-location
james7132 1746ac0
Merge branch 'main' into flatten-entity-location
james7132 416cdbb
less verbose docs
james7132 d9c3389
Move safety comment
james7132 c603483
Simplify fetch_table
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 |
|---|---|---|
|
|
@@ -41,20 +41,20 @@ use std::{ | |
| /// [`Entities::get`]: crate::entity::Entities | ||
| #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
| #[repr(transparent)] | ||
| pub struct ArchetypeRow(usize); | ||
| pub struct ArchetypeRow(u32); | ||
|
|
||
| impl ArchetypeRow { | ||
| pub const INVALID: ArchetypeRow = ArchetypeRow(usize::MAX); | ||
| pub const INVALID: ArchetypeRow = ArchetypeRow(u32::MAX); | ||
|
|
||
| /// Creates a `ArchetypeRow`. | ||
| pub const fn new(index: usize) -> Self { | ||
| Self(index) | ||
| Self(index as u32) | ||
| } | ||
|
|
||
| /// Gets the index of the row. | ||
| #[inline] | ||
| pub const fn index(self) -> usize { | ||
| self.0 | ||
| self.0 as usize | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -69,24 +69,24 @@ impl ArchetypeRow { | |
| /// [`EMPTY`]: crate::archetype::ArchetypeId::EMPTY | ||
| #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | ||
| #[repr(transparent)] | ||
| pub struct ArchetypeId(usize); | ||
| pub struct ArchetypeId(u32); | ||
|
|
||
| impl ArchetypeId { | ||
| /// The ID for the [`Archetype`] without any components. | ||
| pub const EMPTY: ArchetypeId = ArchetypeId(0); | ||
| /// # Safety: | ||
| /// | ||
| /// This must always have an all-1s bit pattern to ensure soundness in fast entity id space allocation. | ||
| pub const INVALID: ArchetypeId = ArchetypeId(usize::MAX); | ||
| pub const INVALID: ArchetypeId = ArchetypeId(u32::MAX); | ||
|
|
||
| #[inline] | ||
| pub(crate) const fn new(index: usize) -> Self { | ||
| ArchetypeId(index) | ||
| ArchetypeId(index as u32) | ||
| } | ||
|
|
||
| #[inline] | ||
| pub(crate) fn index(self) -> usize { | ||
| self.0 | ||
| self.0 as usize | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -407,18 +407,18 @@ impl Archetype { | |
| /// Fetches the row in the [`Table`] where the components for the entity at `index` | ||
| /// is stored. | ||
| /// | ||
| /// An entity's archetype index can be fetched from [`EntityLocation::archetype_row`], which | ||
| /// An entity's archetype row can be fetched from [`EntityLocation::archetype_row`], which | ||
| /// can be retrieved from [`Entities::get`]. | ||
| /// | ||
| /// # Panics | ||
| /// This function will panic if `index >= self.len()`. | ||
| /// | ||
| /// [`Table`]: crate::storage::Table | ||
| /// [`EntityLocation`]: crate::entity::EntityLocation::archetype_row | ||
| /// [`EntityLocation::archetype_row`]: crate::entity::EntityLocation::archetype_row | ||
| /// [`Entities::get`]: crate::entity::Entities::get | ||
| #[inline] | ||
| pub fn entity_table_row(&self, index: ArchetypeRow) -> TableRow { | ||
| self.entities[index.0].table_row | ||
| pub fn entity_table_row(&self, row: ArchetypeRow) -> TableRow { | ||
| self.entities[row.index()].table_row | ||
|
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. Nice little cleanup here. |
||
| } | ||
|
|
||
| /// Updates if the components for the entity at `index` can be found | ||
|
|
@@ -427,8 +427,8 @@ impl Archetype { | |
| /// # Panics | ||
| /// This function will panic if `index >= self.len()`. | ||
| #[inline] | ||
| pub(crate) fn set_entity_table_row(&mut self, index: ArchetypeRow, table_row: TableRow) { | ||
| self.entities[index.0].table_row = table_row; | ||
| pub(crate) fn set_entity_table_row(&mut self, row: ArchetypeRow, table_row: TableRow) { | ||
| self.entities[row.index()].table_row = table_row; | ||
| } | ||
|
|
||
| /// Allocates an entity to the archetype. | ||
|
|
@@ -441,11 +441,14 @@ impl Archetype { | |
| entity: Entity, | ||
| table_row: TableRow, | ||
| ) -> EntityLocation { | ||
| let archetype_row = ArchetypeRow::new(self.entities.len()); | ||
| self.entities.push(ArchetypeEntity { entity, table_row }); | ||
|
|
||
| EntityLocation { | ||
| archetype_id: self.id, | ||
| archetype_row: ArchetypeRow(self.entities.len() - 1), | ||
| archetype_row, | ||
| table_id: self.table_id, | ||
| table_row, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -458,14 +461,14 @@ impl Archetype { | |
| /// | ||
| /// # Panics | ||
| /// This function will panic if `index >= self.len()` | ||
| pub(crate) fn swap_remove(&mut self, index: ArchetypeRow) -> ArchetypeSwapRemoveResult { | ||
| let is_last = index.0 == self.entities.len() - 1; | ||
| let entity = self.entities.swap_remove(index.0); | ||
| pub(crate) fn swap_remove(&mut self, row: ArchetypeRow) -> ArchetypeSwapRemoveResult { | ||
| let is_last = row.index() == self.entities.len() - 1; | ||
| let entity = self.entities.swap_remove(row.index()); | ||
| ArchetypeSwapRemoveResult { | ||
| swapped_entity: if is_last { | ||
| None | ||
| } else { | ||
| Some(self.entities[index.0].entity) | ||
| Some(self.entities[row.index()].entity) | ||
| }, | ||
| table_row: entity.table_row, | ||
| } | ||
|
|
@@ -691,7 +694,7 @@ impl Archetypes { | |
| .archetype_ids | ||
| .entry(archetype_identity) | ||
| .or_insert_with(move || { | ||
| let id = ArchetypeId(archetypes.len()); | ||
| let id = ArchetypeId::new(archetypes.len()); | ||
| let table_start = *archetype_component_count; | ||
| *archetype_component_count += table_components.len(); | ||
| let table_archetype_components = | ||
|
|
||
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
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
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
Oops, something went wrong.
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.