@@ -11,28 +11,28 @@ use std::{
11
11
sync:: atomic:: { AtomicI64 , Ordering } ,
12
12
} ;
13
13
14
- /// Lightweight unique ID of an entity
14
+ /// Lightweight unique ID of an entity.
15
15
///
16
- /// Obtained from [World::spawn](crate::world::World::spawn), typically via
17
- /// [Commands::spawn](crate::system::Commands::spawn). Can be stored to refer to an entity in the
16
+ /// Obtained from [` World::spawn` ](crate::world::World::spawn), typically via
17
+ /// [` Commands::spawn` ](crate::system::Commands::spawn). Can be stored to refer to an entity in the
18
18
/// future.
19
19
///
20
20
/// `Entity` can be a part of a query, e.g. `Query<(Entity, &MyComponent)>`.
21
21
/// Components of a specific entity can be accessed using
22
- /// [Query::get](crate::system::Query::get) and related methods.
22
+ /// [` Query::get` ](crate::system::Query::get) and related methods.
23
23
#[ derive( Clone , Copy , Hash , Eq , Ord , PartialEq , PartialOrd ) ]
24
24
pub struct Entity {
25
25
pub ( crate ) generation : u32 ,
26
26
pub ( crate ) id : u32 ,
27
27
}
28
28
29
29
impl Entity {
30
- /// Creates a new entity reference with a generation of 0
30
+ /// Creates a new entity reference with a generation of 0.
31
31
pub fn new ( id : u32 ) -> Entity {
32
32
Entity { id, generation : 0 }
33
33
}
34
34
35
- /// Convert to a form convenient for passing outside of rust
35
+ /// Convert to a form convenient for passing outside of rust.
36
36
///
37
37
/// Only useful for identifying entities within the same instance of an application. Do not use
38
38
/// for serialization between runs.
@@ -42,7 +42,7 @@ impl Entity {
42
42
u64:: from ( self . generation ) << 32 | u64:: from ( self . id )
43
43
}
44
44
45
- /// Reconstruct an `Entity` previously destructured with ` to_bits`
45
+ /// Reconstruct an `Entity` previously destructured with [`Entity:: to_bits`].
46
46
///
47
47
/// Only useful when applied to results from `to_bits` in the same instance of an application.
48
48
pub fn from_bits ( bits : u64 ) -> Self {
@@ -52,7 +52,7 @@ impl Entity {
52
52
}
53
53
}
54
54
55
- /// Return a transiently unique identifier
55
+ /// Return a transiently unique identifier.
56
56
///
57
57
/// No two simultaneously-live entities share the same ID, but dead entities' IDs may collide
58
58
/// with both live and dead entities. Useful for compactly representing entities within a
@@ -87,7 +87,8 @@ impl SparseSetIndex for Entity {
87
87
}
88
88
}
89
89
90
- /// An iterator returning a sequence of Entity values from `Entities::reserve_entities`.
90
+ /// An [`Iterator`] returning a sequence of [`Entity`] values from
91
+ /// [`Entities::reserve_entities`](crate::entity::Entities::reserve_entities).
91
92
pub struct ReserveEntitiesIterator < ' a > {
92
93
// Metas, so we can recover the current generation for anything in the freelist.
93
94
meta : & ' a [ EntityMeta ] ,
@@ -165,7 +166,7 @@ pub struct Entities {
165
166
}
166
167
167
168
impl Entities {
168
- /// Reserve entity IDs concurrently
169
+ /// Reserve entity IDs concurrently.
169
170
///
170
171
/// Storage for entity generation and location is lazily allocated by calling `flush`.
171
172
pub fn reserve_entities ( & self , count : u32 ) -> ReserveEntitiesIterator {
@@ -207,7 +208,7 @@ impl Entities {
207
208
}
208
209
}
209
210
210
- /// Reserve one entity ID concurrently
211
+ /// Reserve one entity ID concurrently.
211
212
///
212
213
/// Equivalent to `self.reserve_entities(1).next().unwrap()`, but more efficient.
213
214
pub fn reserve_entity ( & self ) -> Entity {
@@ -240,7 +241,7 @@ impl Entities {
240
241
) ;
241
242
}
242
243
243
- /// Allocate an entity ID directly
244
+ /// Allocate an entity ID directly.
244
245
///
245
246
/// Location should be written immediately.
246
247
pub fn alloc ( & mut self ) -> Entity {
@@ -261,7 +262,7 @@ impl Entities {
261
262
}
262
263
}
263
264
264
- /// Allocate a specific entity ID, overwriting its generation
265
+ /// Allocate a specific entity ID, overwriting its generation.
265
266
///
266
267
/// Returns the location of the entity currently using the given ID, if any. Location should be
267
268
/// written immediately.
@@ -293,7 +294,7 @@ impl Entities {
293
294
loc
294
295
}
295
296
296
- /// Destroy an entity, allowing it to be reused
297
+ /// Destroy an entity, allowing it to be reused.
297
298
///
298
299
/// Must not be called while reserved entities are awaiting `flush()`.
299
300
pub fn free ( & mut self , entity : Entity ) -> Option < EntityLocation > {
@@ -315,7 +316,7 @@ impl Entities {
315
316
Some ( loc)
316
317
}
317
318
318
- /// Ensure at least `n` allocations can succeed without reallocating
319
+ /// Ensure at least `n` allocations can succeed without reallocating.
319
320
pub fn reserve ( & mut self , additional : u32 ) {
320
321
self . verify_flushed ( ) ;
321
322
@@ -340,7 +341,7 @@ impl Entities {
340
341
* self . free_cursor . get_mut ( ) = 0 ;
341
342
}
342
343
343
- /// Access the location storage of an entity
344
+ /// Access the location storage of an entity.
344
345
///
345
346
/// Must not be called on pending entities.
346
347
pub fn get_mut ( & mut self , entity : Entity ) -> Option < & mut EntityLocation > {
@@ -352,7 +353,7 @@ impl Entities {
352
353
}
353
354
}
354
355
355
- /// Returns `Ok(Location { archetype: 0, index: undefined })` for pending entities
356
+ /// Returns `Ok(Location { archetype: 0, index: undefined })` for pending entities.
356
357
pub fn get ( & self , entity : Entity ) -> Option < EntityLocation > {
357
358
if ( entity. id as usize ) < self . meta . len ( ) {
358
359
let meta = & self . meta [ entity. id as usize ] ;
@@ -368,6 +369,7 @@ impl Entities {
368
369
/// Panics if the given id would represent an index outside of `meta`.
369
370
///
370
371
/// # Safety
372
+ ///
371
373
/// Must only be called for currently allocated `id`s.
372
374
pub unsafe fn resolve_unknown_gen ( & self , id : u32 ) -> Entity {
373
375
let meta_len = self . meta . len ( ) ;
@@ -463,7 +465,7 @@ impl EntityMeta {
463
465
} ;
464
466
}
465
467
466
- /// A location of an entity in an archetype
468
+ /// A location of an entity in an archetype.
467
469
#[ derive( Copy , Clone , Debug ) ]
468
470
pub struct EntityLocation {
469
471
/// The archetype index
0 commit comments