@@ -24,7 +24,7 @@ use crate::{
24
24
component:: { ComponentId , Components , RequiredComponentConstructor , StorageType } ,
25
25
entity:: { Entity , EntityLocation } ,
26
26
observer:: Observers ,
27
- storage:: { ImmutableSparseSet , SparseArray , SparseSet , SparseSetIndex , TableId , TableRow } ,
27
+ storage:: { ImmutableSparseSet , SparseArray , SparseSet , TableId , TableRow } ,
28
28
} ;
29
29
use alloc:: { boxed:: Box , vec:: Vec } ;
30
30
use bevy_platform:: collections:: HashMap ;
@@ -349,7 +349,6 @@ pub(crate) struct ArchetypeSwapRemoveResult {
349
349
/// [`Component`]: crate::component::Component
350
350
struct ArchetypeComponentInfo {
351
351
storage_type : StorageType ,
352
- archetype_component_id : ArchetypeComponentId ,
353
352
}
354
353
355
354
bitflags:: bitflags! {
@@ -394,14 +393,14 @@ impl Archetype {
394
393
observers : & Observers ,
395
394
id : ArchetypeId ,
396
395
table_id : TableId ,
397
- table_components : impl Iterator < Item = ( ComponentId , ArchetypeComponentId ) > ,
398
- sparse_set_components : impl Iterator < Item = ( ComponentId , ArchetypeComponentId ) > ,
396
+ table_components : impl Iterator < Item = ComponentId > ,
397
+ sparse_set_components : impl Iterator < Item = ComponentId > ,
399
398
) -> Self {
400
399
let ( min_table, _) = table_components. size_hint ( ) ;
401
400
let ( min_sparse, _) = sparse_set_components. size_hint ( ) ;
402
401
let mut flags = ArchetypeFlags :: empty ( ) ;
403
402
let mut archetype_components = SparseSet :: with_capacity ( min_table + min_sparse) ;
404
- for ( idx, ( component_id, archetype_component_id ) ) in table_components. enumerate ( ) {
403
+ for ( idx, component_id) in table_components. enumerate ( ) {
405
404
// SAFETY: We are creating an archetype that includes this component so it must exist
406
405
let info = unsafe { components. get_info_unchecked ( component_id) } ;
407
406
info. update_archetype_flags ( & mut flags) ;
@@ -410,7 +409,6 @@ impl Archetype {
410
409
component_id,
411
410
ArchetypeComponentInfo {
412
411
storage_type : StorageType :: Table ,
413
- archetype_component_id,
414
412
} ,
415
413
) ;
416
414
// NOTE: the `table_components` are sorted AND they were inserted in the `Table` in the same
@@ -422,7 +420,7 @@ impl Archetype {
422
420
. insert ( id, ArchetypeRecord { column : Some ( idx) } ) ;
423
421
}
424
422
425
- for ( component_id, archetype_component_id ) in sparse_set_components {
423
+ for component_id in sparse_set_components {
426
424
// SAFETY: We are creating an archetype that includes this component so it must exist
427
425
let info = unsafe { components. get_info_unchecked ( component_id) } ;
428
426
info. update_archetype_flags ( & mut flags) ;
@@ -431,7 +429,6 @@ impl Archetype {
431
429
component_id,
432
430
ArchetypeComponentInfo {
433
431
storage_type : StorageType :: SparseSet ,
434
- archetype_component_id,
435
432
} ,
436
433
) ;
437
434
component_index
@@ -536,16 +533,6 @@ impl Archetype {
536
533
self . components . len ( )
537
534
}
538
535
539
- /// Gets an iterator of all of the components in the archetype, along with
540
- /// their archetype component ID.
541
- pub ( crate ) fn components_with_archetype_component_id (
542
- & self ,
543
- ) -> impl Iterator < Item = ( ComponentId , ArchetypeComponentId ) > + ' _ {
544
- self . components
545
- . iter ( )
546
- . map ( |( component_id, info) | ( * component_id, info. archetype_component_id ) )
547
- }
548
-
549
536
/// Fetches an immutable reference to the archetype's [`Edges`], a cache of
550
537
/// archetypal relationships.
551
538
#[ inline]
@@ -664,19 +651,6 @@ impl Archetype {
664
651
. map ( |info| info. storage_type )
665
652
}
666
653
667
- /// Fetches the corresponding [`ArchetypeComponentId`] for a component in the archetype.
668
- /// Returns `None` if the component is not part of the archetype.
669
- /// This runs in `O(1)` time.
670
- #[ inline]
671
- pub fn get_archetype_component_id (
672
- & self ,
673
- component_id : ComponentId ,
674
- ) -> Option < ArchetypeComponentId > {
675
- self . components
676
- . get ( component_id)
677
- . map ( |info| info. archetype_component_id )
678
- }
679
-
680
654
/// Clears all entities from the archetype.
681
655
pub ( crate ) fn clear_entities ( & mut self ) {
682
656
self . entities . clear ( ) ;
@@ -774,46 +748,6 @@ struct ArchetypeComponents {
774
748
sparse_set_components : Box < [ ComponentId ] > ,
775
749
}
776
750
777
- /// An opaque unique joint ID for a [`Component`] in an [`Archetype`] within a [`World`].
778
- ///
779
- /// A component may be present within multiple archetypes, but each component within
780
- /// each archetype has its own unique `ArchetypeComponentId`. This is leveraged by the system
781
- /// schedulers to opportunistically run multiple systems in parallel that would otherwise
782
- /// conflict. For example, `Query<&mut A, With<B>>` and `Query<&mut A, Without<B>>` can run in
783
- /// parallel as the matched `ArchetypeComponentId` sets for both queries are disjoint, even
784
- /// though `&mut A` on both queries point to the same [`ComponentId`].
785
- ///
786
- /// In SQL terms, these IDs are composite keys on a [many-to-many relationship] between archetypes
787
- /// and components. Each component type will have only one [`ComponentId`], but may have many
788
- /// [`ArchetypeComponentId`]s, one for every archetype the component is present in. Likewise, each
789
- /// archetype will have only one [`ArchetypeId`] but may have many [`ArchetypeComponentId`]s, one
790
- /// for each component that belongs to the archetype.
791
- ///
792
- /// Every [`Resource`] is also assigned one of these IDs. As resources do not belong to any
793
- /// particular archetype, a resource's ID uniquely identifies it.
794
- ///
795
- /// These IDs are only valid within a given World, and are not globally unique.
796
- /// Attempting to use an ID on a world that it wasn't sourced from will
797
- /// not point to the same archetype nor the same component.
798
- ///
799
- /// [`Component`]: crate::component::Component
800
- /// [`World`]: crate::world::World
801
- /// [`Resource`]: crate::resource::Resource
802
- /// [many-to-many relationship]: https://en.wikipedia.org/wiki/Many-to-many_(data_model)
803
- #[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
804
- pub struct ArchetypeComponentId ( usize ) ;
805
-
806
- impl SparseSetIndex for ArchetypeComponentId {
807
- #[ inline]
808
- fn sparse_set_index ( & self ) -> usize {
809
- self . 0
810
- }
811
-
812
- fn get_sparse_set_index ( value : usize ) -> Self {
813
- Self ( value)
814
- }
815
- }
816
-
817
751
/// Maps a [`ComponentId`] to the list of [`Archetypes`]([`Archetype`]) that contain the [`Component`](crate::component::Component),
818
752
/// along with an [`ArchetypeRecord`] which contains some metadata about how the component is stored in the archetype.
819
753
pub type ComponentIndex = HashMap < ComponentId , HashMap < ArchetypeId , ArchetypeRecord > > ;
@@ -826,7 +760,6 @@ pub type ComponentIndex = HashMap<ComponentId, HashMap<ArchetypeId, ArchetypeRec
826
760
/// [module level documentation]: crate::archetype
827
761
pub struct Archetypes {
828
762
pub ( crate ) archetypes : Vec < Archetype > ,
829
- archetype_component_count : usize ,
830
763
/// find the archetype id by the archetype's components
831
764
by_components : HashMap < ArchetypeComponents , ArchetypeId > ,
832
765
/// find all the archetypes that contain a component
@@ -850,7 +783,6 @@ impl Archetypes {
850
783
archetypes : Vec :: new ( ) ,
851
784
by_components : Default :: default ( ) ,
852
785
by_component : Default :: default ( ) ,
853
- archetype_component_count : 0 ,
854
786
} ;
855
787
// SAFETY: Empty archetype has no components
856
788
unsafe {
@@ -905,22 +837,6 @@ impl Archetypes {
905
837
}
906
838
}
907
839
908
- /// Generate and store a new [`ArchetypeComponentId`].
909
- ///
910
- /// This simply increment the counter and return the new value.
911
- ///
912
- /// # Panics
913
- ///
914
- /// On archetype component id overflow.
915
- pub ( crate ) fn new_archetype_component_id ( & mut self ) -> ArchetypeComponentId {
916
- let id = ArchetypeComponentId ( self . archetype_component_count ) ;
917
- self . archetype_component_count = self
918
- . archetype_component_count
919
- . checked_add ( 1 )
920
- . expect ( "archetype_component_count overflow" ) ;
921
- id
922
- }
923
-
924
840
/// Fetches an immutable reference to an [`Archetype`] using its
925
841
/// ID. Returns `None` if no corresponding archetype exists.
926
842
#[ inline]
@@ -972,7 +888,6 @@ impl Archetypes {
972
888
} ;
973
889
974
890
let archetypes = & mut self . archetypes ;
975
- let archetype_component_count = & mut self . archetype_component_count ;
976
891
let component_index = & mut self . by_component ;
977
892
* self
978
893
. by_components
@@ -983,40 +898,19 @@ impl Archetypes {
983
898
sparse_set_components,
984
899
} = identity;
985
900
let id = ArchetypeId :: new ( archetypes. len ( ) ) ;
986
- let table_start = * archetype_component_count;
987
- * archetype_component_count += table_components. len ( ) ;
988
- let table_archetype_components =
989
- ( table_start..* archetype_component_count) . map ( ArchetypeComponentId ) ;
990
- let sparse_start = * archetype_component_count;
991
- * archetype_component_count += sparse_set_components. len ( ) ;
992
- let sparse_set_archetype_components =
993
- ( sparse_start..* archetype_component_count) . map ( ArchetypeComponentId ) ;
994
901
archetypes. push ( Archetype :: new (
995
902
components,
996
903
component_index,
997
904
observers,
998
905
id,
999
906
table_id,
1000
- table_components
1001
- . iter ( )
1002
- . copied ( )
1003
- . zip ( table_archetype_components) ,
1004
- sparse_set_components
1005
- . iter ( )
1006
- . copied ( )
1007
- . zip ( sparse_set_archetype_components) ,
907
+ table_components. iter ( ) . copied ( ) ,
908
+ sparse_set_components. iter ( ) . copied ( ) ,
1008
909
) ) ;
1009
910
id
1010
911
} )
1011
912
}
1012
913
1013
- /// Returns the number of components that are stored in archetypes.
1014
- /// Note that if some component `T` is stored in more than one archetype, it will be counted once for each archetype it's present in.
1015
- #[ inline]
1016
- pub fn archetype_components_len ( & self ) -> usize {
1017
- self . archetype_component_count
1018
- }
1019
-
1020
914
/// Clears all entities from all archetypes.
1021
915
pub ( crate ) fn clear_entities ( & mut self ) {
1022
916
for archetype in & mut self . archetypes {
0 commit comments