@@ -4,7 +4,7 @@ use bevy_utils::{tracing::warn, HashSet};
44
55use crate :: { component:: ComponentId , prelude:: Bundle , world:: World } ;
66
7- /// A rule about which [`Component`](crate::component::Component)s can coexist on entities
7+ /// A rule about which [`Component`](crate::component::Component)s can coexist on entities.
88///
99/// These rules must be true at all times for all entities in the [`World`].
1010/// The generic [`Bundle`] type `B1` is always used in the `predicate`,
@@ -18,9 +18,6 @@ use crate::{component::ComponentId, prelude::Bundle, world::World};
1818///
1919/// Archetypes are only modified when a novel archetype (set of components) is seen for the first time;
2020/// swapping between existing archetypes will not trigger these checks.
21- ///
22- /// Note that this is converted to an [`UntypedArchetypeInvariant`] when added to a [`World`].
23- /// This is to ensure compatibility between different invariants.
2421#[ derive( Clone , Debug , PartialEq ) ]
2522pub struct ArchetypeInvariant < B1 : Bundle , B2 : Bundle = B1 > {
2623 /// For all entities where the predicate is true
@@ -43,9 +40,9 @@ impl<B1: Bundle, B2: Bundle> ArchetypeInvariant<B1, B2> {
4340}
4441
4542impl < B : Bundle > ArchetypeInvariant < B , B > {
46- /// This is a helper function for constructing common invariants .
47- /// All components of the provided bundle require each other.
48- /// In other words, if any one component of this bundle is present, then all of them must be.
43+ /// Creates an archetype invariant where all components of `B` require each other .
44+ ///
45+ /// In other words, if any component of this bundle is present, then all of them must be.
4946 #[ inline]
5047 pub fn full_bundle ( ) -> Self {
5148 Self {
@@ -70,20 +67,20 @@ impl<B: Bundle> ArchetypeInvariant<B, B> {
7067/// This is to ensure compatibility between different invariants.
7168#[ derive( Clone , Debug , PartialEq ) ]
7269pub enum ArchetypeStatement < B : Bundle > {
73- /// Evaluates to true if and only if the entity has all of the components present in the bundle `B`
70+ /// Evaluates to true if and only if the entity has all of the components present in the bundle `B`.
7471 AllOf ( PhantomData < B > ) ,
75- /// The entity has at least one component in the bundle `B`, and may have all of them .
72+ /// The entity has at least one component in the bundle `B`.
7673 /// When using a single-component bundle, `AllOf` is preferred.
7774 AtLeastOneOf ( PhantomData < B > ) ,
7875 /// The entity has zero or one of the components in the bundle `B`, but no more.
79- /// When using a single-component bundle, this is a tautology .
76+ /// When using a single-component bundle, this will always be true .
8077 AtMostOneOf ( PhantomData < B > ) ,
81- /// The entity has none of the components in the bundle `B`
78+ /// The entity has none of the components in the bundle `B`.
8279 NoneOf ( PhantomData < B > ) ,
8380}
8481
8582impl < B : Bundle > ArchetypeStatement < B > {
86- /// Erases the type information of this archetype statment .
83+ /// Erases the type information of this archetype statement .
8784 ///
8885 /// Requires mutable world access, since the components might not have been added to the world yet.
8986 pub fn into_untyped ( self , world : & mut World ) -> UntypedArchetypeStatement {
@@ -105,25 +102,25 @@ impl<B: Bundle> ArchetypeStatement<B> {
105102 }
106103 }
107104
108- /// Constructs a new [`ArchetypeStatement::AllOf`] variant for all components stored in the bundle `B`
105+ /// Constructs a new [`ArchetypeStatement::AllOf`] variant for all components stored in the bundle `B`.
109106 #[ inline]
110107 pub const fn all_of ( ) -> Self {
111108 ArchetypeStatement :: AllOf ( PhantomData )
112109 }
113110
114- /// Constructs a new [`ArchetypeStatement::AtLeastOneOf`] variant for all components stored in the bundle `B`
111+ /// Constructs a new [`ArchetypeStatement::AtLeastOneOf`] variant for all components stored in the bundle `B`.
115112 #[ inline]
116113 pub const fn at_least_one_of ( ) -> Self {
117114 ArchetypeStatement :: AtLeastOneOf ( PhantomData )
118115 }
119116
120- /// Constructs a new [`ArchetypeStatement::AtMostOneOf`] variant for all components stored in the bundle `B`
117+ /// Constructs a new [`ArchetypeStatement::AtMostOneOf`] variant for all components stored in the bundle `B`.
121118 #[ inline]
122119 pub const fn at_most_one_of ( ) -> Self {
123120 ArchetypeStatement :: AtMostOneOf ( PhantomData )
124121 }
125122
126- /// Constructs a new [`ArchetypeStatement::NoneOf`] variant for all components stored in the bundle `B`
123+ /// Constructs a new [`ArchetypeStatement::NoneOf`] variant for all components stored in the bundle `B`.
127124 #[ inline]
128125 pub const fn none_of ( ) -> Self {
129126 ArchetypeStatement :: NoneOf ( PhantomData )
@@ -143,14 +140,14 @@ pub struct UntypedArchetypeInvariant {
143140}
144141
145142impl UntypedArchetypeInvariant {
146- /// Assert that the provided iterator of [`ComponentId`]s obeys this archetype invariant
143+ /// Asserts that the provided iterator of [`ComponentId`]s obeys this archetype invariant.
147144 ///
148145 /// `component_ids` is generally provided via the `components` field on [`Archetype`](crate::archetype::Archetype).
149146 /// When testing against multiple archetypes, [`ArchetypeInvariants::test_archetype`] is preferred,
150147 /// as it can more efficiently cache checks between archetypes.
151148 ///
152149 /// # Panics
153- /// Panics if the archetype invariant is violated
150+ /// Panics if the archetype invariant is violated.
154151 pub fn test_archetype ( & self , component_ids_of_archetype : impl Iterator < Item = ComponentId > ) {
155152 let component_ids_of_archetype: HashSet < ComponentId > = component_ids_of_archetype. collect ( ) ;
156153
@@ -165,20 +162,21 @@ impl UntypedArchetypeInvariant {
165162 }
166163}
167164
168- /// A type-erased version of [`ArchetypeStatement`]
165+ /// A type-erased version of [`ArchetypeStatement`].
166+ ///
169167/// Intended to be used with dynamic components that cannot be represented with Rust types.
170168/// Prefer [`ArchetypeStatement`] when possible.
171169#[ derive( Clone , Debug , PartialEq ) ]
172170pub enum UntypedArchetypeStatement {
173- /// Evaluates to true if and only if the entity has all of the components present in the set
171+ /// Evaluates to true if and only if the entity has all of the components present in the set.
174172 AllOf ( HashSet < ComponentId > ) ,
175173 /// The entity has at least one component in the set, and may have all of them.
176- /// When using a single-component set, `AllOf` is preferred
174+ /// When using a single-component set, `AllOf` is preferred.
177175 AtLeastOneOf ( HashSet < ComponentId > ) ,
178176 /// The entity has zero or one of the components in the set, but no more.
179177 /// When using a single-component set, this is a tautology.
180178 AtMostOneOf ( HashSet < ComponentId > ) ,
181- /// The entity has none of the components in the set
179+ /// The entity has none of the components in the set.
182180 NoneOf ( HashSet < ComponentId > ) ,
183181}
184182
@@ -193,7 +191,7 @@ impl UntypedArchetypeStatement {
193191 }
194192 }
195193
196- /// Test if this statement is true for the provided set of [`ComponentId`]s
194+ /// Test if this statement is true for the provided set of [`ComponentId`]s.
197195 pub fn test ( & self , component_ids : & HashSet < ComponentId > ) -> bool {
198196 match self {
199197 UntypedArchetypeStatement :: AllOf ( required_ids) => {
@@ -238,26 +236,27 @@ impl UntypedArchetypeStatement {
238236
239237#[ derive( Default ) ]
240238pub struct ArchetypeInvariants {
241- /// The list of invariants that must be upheld
239+ /// The list of invariants that must be upheld.
242240 raw_list : Vec < UntypedArchetypeInvariant > ,
243241}
244242
245243impl ArchetypeInvariants {
246244 /// Adds a new [`ArchetypeInvariant`] to this set of archetype invariants.
247245 ///
248246 /// Whenever a new archetype invariant is added, all existing archetypes are re-checked.
249- /// This may include empty archetypes- archetypes that contain no entities.
247+ /// This may include empty archetypes: archetypes that contain no entities.
250248 #[ inline]
251249 pub fn add ( & mut self , archetype_invariant : UntypedArchetypeInvariant ) {
252250 self . raw_list . push ( archetype_invariant) ;
253251 }
254252
255- /// Assert that the provided iterator of [`ComponentId`]s obeys all archetype invariants
253+ /// Asserts that the provided iterator of [`ComponentId`]s obeys all archetype invariants.
256254 ///
257255 /// `component_ids` is generally provided via the `components` field on [`Archetype`](crate::archetype::Archetype).
258256 ///
259257 /// # Panics
260- /// Panics if any archetype invariant is violated
258+ ///
259+ /// Panics if any archetype invariant is violated.
261260 pub fn test_archetype ( & self , component_ids_of_archetype : impl Iterator < Item = ComponentId > ) {
262261 let component_ids_of_archetype: HashSet < ComponentId > = component_ids_of_archetype. collect ( ) ;
263262
0 commit comments