@@ -455,9 +455,9 @@ impl Hash for Entity {
455
455
}
456
456
457
457
impl Entity {
458
- /// Constructs an [`Entity`] from a raw `row` value and a non-zero ` generation` value .
458
+ /// Creates a new instance with the given index and generation.
459
459
#[ inline( always) ]
460
- pub const fn from_raw_and_generation ( row : EntityRow , generation : EntityGeneration ) -> Entity {
460
+ pub const fn from_row_and_generation ( row : EntityRow , generation : EntityGeneration ) -> Entity {
461
461
Self { row, generation }
462
462
}
463
463
@@ -495,7 +495,7 @@ impl Entity {
495
495
/// }
496
496
/// }
497
497
/// ```
498
- pub const PLACEHOLDER : Self = Self :: from_raw ( EntityRow :: PLACEHOLDER ) ;
498
+ pub const PLACEHOLDER : Self = Self :: from_row ( EntityRow :: PLACEHOLDER ) ;
499
499
500
500
/// Creates a new entity ID with the specified `row` and a generation of 1.
501
501
///
@@ -510,17 +510,17 @@ impl Entity {
510
510
/// `Entity` lines up between instances, but instead insert a secondary identifier as
511
511
/// a component.
512
512
#[ inline( always) ]
513
- pub const fn from_raw ( row : EntityRow ) -> Entity {
514
- Self :: from_raw_and_generation ( row, EntityGeneration :: FIRST )
513
+ pub const fn from_row ( row : EntityRow ) -> Entity {
514
+ Self :: from_row_and_generation ( row, EntityGeneration :: FIRST )
515
515
}
516
516
517
- /// This is equivalent to [`from_raw `](Self::from_raw ) except that it takes a `u32` instead of an [`EntityRow`].
517
+ /// This is equivalent to [`from_row `](Self::from_row ) except that it takes a `u32` instead of an [`EntityRow`].
518
518
///
519
519
/// Returns `None` if the row is `u32::MAX`.
520
520
#[ inline( always) ]
521
521
pub const fn from_raw_u32 ( row : u32 ) -> Option < Entity > {
522
522
match NonMaxU32 :: new ( row) {
523
- Some ( row) => Some ( Self :: from_raw ( EntityRow :: new ( row) ) ) ,
523
+ Some ( row) => Some ( Self :: from_row ( EntityRow :: new ( row) ) ) ,
524
524
None => None ,
525
525
}
526
526
}
@@ -657,7 +657,7 @@ impl SparseSetIndex for Entity {
657
657
658
658
#[ inline]
659
659
fn get_sparse_set_index ( value : usize ) -> Self {
660
- Entity :: from_raw ( EntityRow :: get_sparse_set_index ( value) )
660
+ Entity :: from_row ( EntityRow :: get_sparse_set_index ( value) )
661
661
}
662
662
}
663
663
@@ -680,13 +680,13 @@ impl<'a> Iterator for ReserveEntitiesIterator<'a> {
680
680
self . freelist_indices
681
681
. next ( )
682
682
. map ( |& row| {
683
- Entity :: from_raw_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
683
+ Entity :: from_row_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
684
684
} )
685
685
. or_else ( || {
686
686
self . new_indices . next ( ) . map ( |index| {
687
687
// SAFETY: This came from an exclusive range so the max can't be hit.
688
688
let row = unsafe { EntityRow :: new ( NonMaxU32 :: new_unchecked ( index) ) } ;
689
- Entity :: from_raw ( row)
689
+ Entity :: from_row ( row)
690
690
} )
691
691
} )
692
692
}
@@ -833,7 +833,7 @@ impl Entities {
833
833
if n > 0 {
834
834
// Allocate from the freelist.
835
835
let row = self . pending [ ( n - 1 ) as usize ] ;
836
- Entity :: from_raw_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
836
+ Entity :: from_row_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
837
837
} else {
838
838
// Grab a new ID, outside the range of `meta.len()`. `flush()` must
839
839
// eventually be called to make it valid.
@@ -846,7 +846,7 @@ impl Entities {
846
846
}
847
847
// SAFETY: We just checked the bounds
848
848
let row = unsafe { EntityRow :: new ( NonMaxU32 :: new_unchecked ( raw as u32 ) ) } ;
849
- Entity :: from_raw ( row)
849
+ Entity :: from_row ( row)
850
850
}
851
851
}
852
852
@@ -864,14 +864,14 @@ impl Entities {
864
864
if let Some ( row) = self . pending . pop ( ) {
865
865
let new_free_cursor = self . pending . len ( ) as IdCursor ;
866
866
* self . free_cursor . get_mut ( ) = new_free_cursor;
867
- Entity :: from_raw_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
867
+ Entity :: from_row_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
868
868
} else {
869
869
let index = u32:: try_from ( self . meta . len ( ) )
870
870
. ok ( )
871
871
. and_then ( NonMaxU32 :: new)
872
872
. expect ( "too many entities" ) ;
873
873
self . meta . push ( EntityMeta :: EMPTY ) ;
874
- Entity :: from_raw ( EntityRow :: new ( index) )
874
+ Entity :: from_row ( EntityRow :: new ( index) )
875
875
}
876
876
}
877
877
@@ -1012,14 +1012,14 @@ impl Entities {
1012
1012
pub fn resolve_from_id ( & self , row : EntityRow ) -> Option < Entity > {
1013
1013
let idu = row. index ( ) as usize ;
1014
1014
if let Some ( & EntityMeta { generation, .. } ) = self . meta . get ( idu) {
1015
- Some ( Entity :: from_raw_and_generation ( row, generation) )
1015
+ Some ( Entity :: from_row_and_generation ( row, generation) )
1016
1016
} else {
1017
1017
// `id` is outside of the meta list - check whether it is reserved but not yet flushed.
1018
1018
let free_cursor = self . free_cursor . load ( Ordering :: Relaxed ) ;
1019
1019
// If this entity was manually created, then free_cursor might be positive
1020
1020
// Returning None handles that case correctly
1021
1021
let num_pending = usize:: try_from ( -free_cursor) . ok ( ) ?;
1022
- ( idu < self . meta . len ( ) + num_pending) . then_some ( Entity :: from_raw ( row) )
1022
+ ( idu < self . meta . len ( ) + num_pending) . then_some ( Entity :: from_row ( row) )
1023
1023
}
1024
1024
}
1025
1025
@@ -1058,7 +1058,7 @@ impl Entities {
1058
1058
// SAFETY: the index is less than the meta length, which can not exceeded u32::MAX
1059
1059
let row = EntityRow :: new ( unsafe { NonMaxU32 :: new_unchecked ( index as u32 ) } ) ;
1060
1060
init (
1061
- Entity :: from_raw_and_generation ( row, meta. generation ) ,
1061
+ Entity :: from_row_and_generation ( row, meta. generation ) ,
1062
1062
& mut meta. location ,
1063
1063
) ;
1064
1064
meta. spawned_or_despawned = SpawnedOrDespawned { by, tick } ;
@@ -1071,7 +1071,7 @@ impl Entities {
1071
1071
for row in self . pending . drain ( new_free_cursor..) {
1072
1072
let meta = & mut self . meta [ row. index ( ) as usize ] ;
1073
1073
init (
1074
- Entity :: from_raw_and_generation ( row, meta. generation ) ,
1074
+ Entity :: from_row_and_generation ( row, meta. generation ) ,
1075
1075
& mut meta. location ,
1076
1076
) ;
1077
1077
meta. spawned_or_despawned = SpawnedOrDespawned { by, tick } ;
@@ -1333,7 +1333,7 @@ mod tests {
1333
1333
let r = EntityRow :: from_raw_u32 ( 0xDEADBEEF ) . unwrap ( ) ;
1334
1334
assert_eq ! ( EntityRow :: from_bits( r. to_bits( ) ) , r) ;
1335
1335
1336
- let e = Entity :: from_raw_and_generation (
1336
+ let e = Entity :: from_row_and_generation (
1337
1337
EntityRow :: from_raw_u32 ( 0xDEADBEEF ) . unwrap ( ) ,
1338
1338
EntityGeneration :: from_bits ( 0x5AADF00D ) ,
1339
1339
) ;
@@ -1373,15 +1373,15 @@ mod tests {
1373
1373
1374
1374
#[ test]
1375
1375
fn entity_const ( ) {
1376
- const C1 : Entity = Entity :: from_raw ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
1376
+ const C1 : Entity = Entity :: from_row ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
1377
1377
assert_eq ! ( 42 , C1 . index( ) ) ;
1378
1378
assert_eq ! ( 0 , C1 . generation( ) . to_bits( ) ) ;
1379
1379
1380
1380
const C2 : Entity = Entity :: from_bits ( 0x0000_00ff_0000_00cc ) ;
1381
1381
assert_eq ! ( !0x0000_00cc , C2 . index( ) ) ;
1382
1382
assert_eq ! ( 0x0000_00ff , C2 . generation( ) . to_bits( ) ) ;
1383
1383
1384
- const C3 : u32 = Entity :: from_raw ( EntityRow :: from_raw_u32 ( 33 ) . unwrap ( ) ) . index ( ) ;
1384
+ const C3 : u32 = Entity :: from_row ( EntityRow :: from_raw_u32 ( 33 ) . unwrap ( ) ) . index ( ) ;
1385
1385
assert_eq ! ( 33 , C3 ) ;
1386
1386
1387
1387
const C4 : u32 = Entity :: from_bits ( 0x00dd_00ff_1111_1111 )
@@ -1425,41 +1425,41 @@ mod tests {
1425
1425
) ]
1426
1426
fn entity_comparison ( ) {
1427
1427
assert_eq ! (
1428
- Entity :: from_raw_and_generation (
1428
+ Entity :: from_row_and_generation (
1429
1429
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1430
1430
EntityGeneration :: from_bits( 456 )
1431
1431
) ,
1432
- Entity :: from_raw_and_generation (
1432
+ Entity :: from_row_and_generation (
1433
1433
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1434
1434
EntityGeneration :: from_bits( 456 )
1435
1435
)
1436
1436
) ;
1437
1437
assert_ne ! (
1438
- Entity :: from_raw_and_generation (
1438
+ Entity :: from_row_and_generation (
1439
1439
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1440
1440
EntityGeneration :: from_bits( 789 )
1441
1441
) ,
1442
- Entity :: from_raw_and_generation (
1442
+ Entity :: from_row_and_generation (
1443
1443
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1444
1444
EntityGeneration :: from_bits( 456 )
1445
1445
)
1446
1446
) ;
1447
1447
assert_ne ! (
1448
- Entity :: from_raw_and_generation (
1448
+ Entity :: from_row_and_generation (
1449
1449
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1450
1450
EntityGeneration :: from_bits( 456 )
1451
1451
) ,
1452
- Entity :: from_raw_and_generation (
1452
+ Entity :: from_row_and_generation (
1453
1453
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1454
1454
EntityGeneration :: from_bits( 789 )
1455
1455
)
1456
1456
) ;
1457
1457
assert_ne ! (
1458
- Entity :: from_raw_and_generation (
1458
+ Entity :: from_row_and_generation (
1459
1459
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1460
1460
EntityGeneration :: from_bits( 456 )
1461
1461
) ,
1462
- Entity :: from_raw_and_generation (
1462
+ Entity :: from_row_and_generation (
1463
1463
EntityRow :: from_raw_u32( 456 ) . unwrap( ) ,
1464
1464
EntityGeneration :: from_bits( 123 )
1465
1465
)
@@ -1468,93 +1468,93 @@ mod tests {
1468
1468
// ordering is by generation then by index
1469
1469
1470
1470
assert ! (
1471
- Entity :: from_raw_and_generation (
1471
+ Entity :: from_row_and_generation (
1472
1472
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1473
1473
EntityGeneration :: from_bits( 456 )
1474
- ) >= Entity :: from_raw_and_generation (
1474
+ ) >= Entity :: from_row_and_generation (
1475
1475
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1476
1476
EntityGeneration :: from_bits( 456 )
1477
1477
)
1478
1478
) ;
1479
1479
assert ! (
1480
- Entity :: from_raw_and_generation (
1480
+ Entity :: from_row_and_generation (
1481
1481
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1482
1482
EntityGeneration :: from_bits( 456 )
1483
- ) <= Entity :: from_raw_and_generation (
1483
+ ) <= Entity :: from_row_and_generation (
1484
1484
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1485
1485
EntityGeneration :: from_bits( 456 )
1486
1486
)
1487
1487
) ;
1488
1488
assert ! (
1489
- !( Entity :: from_raw_and_generation (
1489
+ !( Entity :: from_row_and_generation (
1490
1490
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1491
1491
EntityGeneration :: from_bits( 456 )
1492
- ) < Entity :: from_raw_and_generation (
1492
+ ) < Entity :: from_row_and_generation (
1493
1493
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1494
1494
EntityGeneration :: from_bits( 456 )
1495
1495
) )
1496
1496
) ;
1497
1497
assert ! (
1498
- !( Entity :: from_raw_and_generation (
1498
+ !( Entity :: from_row_and_generation (
1499
1499
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1500
1500
EntityGeneration :: from_bits( 456 )
1501
- ) > Entity :: from_raw_and_generation (
1501
+ ) > Entity :: from_row_and_generation (
1502
1502
EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
1503
1503
EntityGeneration :: from_bits( 456 )
1504
1504
) )
1505
1505
) ;
1506
1506
1507
1507
assert ! (
1508
- Entity :: from_raw_and_generation (
1508
+ Entity :: from_row_and_generation (
1509
1509
EntityRow :: from_raw_u32( 9 ) . unwrap( ) ,
1510
1510
EntityGeneration :: from_bits( 1 )
1511
- ) < Entity :: from_raw_and_generation (
1511
+ ) < Entity :: from_row_and_generation (
1512
1512
EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
1513
1513
EntityGeneration :: from_bits( 9 )
1514
1514
)
1515
1515
) ;
1516
1516
assert ! (
1517
- Entity :: from_raw_and_generation (
1517
+ Entity :: from_row_and_generation (
1518
1518
EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
1519
1519
EntityGeneration :: from_bits( 9 )
1520
- ) > Entity :: from_raw_and_generation (
1520
+ ) > Entity :: from_row_and_generation (
1521
1521
EntityRow :: from_raw_u32( 9 ) . unwrap( ) ,
1522
1522
EntityGeneration :: from_bits( 1 )
1523
1523
)
1524
1524
) ;
1525
1525
1526
1526
assert ! (
1527
- Entity :: from_raw_and_generation (
1527
+ Entity :: from_row_and_generation (
1528
1528
EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
1529
1529
EntityGeneration :: from_bits( 1 )
1530
- ) > Entity :: from_raw_and_generation (
1530
+ ) > Entity :: from_row_and_generation (
1531
1531
EntityRow :: from_raw_u32( 2 ) . unwrap( ) ,
1532
1532
EntityGeneration :: from_bits( 1 )
1533
1533
)
1534
1534
) ;
1535
1535
assert ! (
1536
- Entity :: from_raw_and_generation (
1536
+ Entity :: from_row_and_generation (
1537
1537
EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
1538
1538
EntityGeneration :: from_bits( 1 )
1539
- ) >= Entity :: from_raw_and_generation (
1539
+ ) >= Entity :: from_row_and_generation (
1540
1540
EntityRow :: from_raw_u32( 2 ) . unwrap( ) ,
1541
1541
EntityGeneration :: from_bits( 1 )
1542
1542
)
1543
1543
) ;
1544
1544
assert ! (
1545
- Entity :: from_raw_and_generation (
1545
+ Entity :: from_row_and_generation (
1546
1546
EntityRow :: from_raw_u32( 2 ) . unwrap( ) ,
1547
1547
EntityGeneration :: from_bits( 2 )
1548
- ) < Entity :: from_raw_and_generation (
1548
+ ) < Entity :: from_row_and_generation (
1549
1549
EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
1550
1550
EntityGeneration :: from_bits( 2 )
1551
1551
)
1552
1552
) ;
1553
1553
assert ! (
1554
- Entity :: from_raw_and_generation (
1554
+ Entity :: from_row_and_generation (
1555
1555
EntityRow :: from_raw_u32( 2 ) . unwrap( ) ,
1556
1556
EntityGeneration :: from_bits( 2 )
1557
- ) <= Entity :: from_raw_and_generation (
1557
+ ) <= Entity :: from_row_and_generation (
1558
1558
EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
1559
1559
EntityGeneration :: from_bits( 2 )
1560
1560
)
@@ -1570,11 +1570,11 @@ mod tests {
1570
1570
1571
1571
let first_id = 0xC0FFEE << 8 ;
1572
1572
let first_hash =
1573
- hash. hash_one ( Entity :: from_raw ( EntityRow :: from_raw_u32 ( first_id) . unwrap ( ) ) ) ;
1573
+ hash. hash_one ( Entity :: from_row ( EntityRow :: from_raw_u32 ( first_id) . unwrap ( ) ) ) ;
1574
1574
1575
1575
for i in 1 ..=255 {
1576
1576
let id = first_id + i;
1577
- let hash = hash. hash_one ( Entity :: from_raw ( EntityRow :: from_raw_u32 ( id) . unwrap ( ) ) ) ;
1577
+ let hash = hash. hash_one ( Entity :: from_row ( EntityRow :: from_raw_u32 ( id) . unwrap ( ) ) ) ;
1578
1578
assert_eq ! ( first_hash. wrapping_sub( hash) as u32 , i) ;
1579
1579
}
1580
1580
}
@@ -1587,11 +1587,11 @@ mod tests {
1587
1587
1588
1588
let first_id = 0xC0FFEE ;
1589
1589
let first_hash =
1590
- hash. hash_one ( Entity :: from_raw ( EntityRow :: from_raw_u32 ( first_id) . unwrap ( ) ) ) >> 57 ;
1590
+ hash. hash_one ( Entity :: from_row ( EntityRow :: from_raw_u32 ( first_id) . unwrap ( ) ) ) >> 57 ;
1591
1591
1592
1592
for bit in 0 ..u32:: BITS {
1593
1593
let id = first_id ^ ( 1 << bit) ;
1594
- let hash = hash. hash_one ( Entity :: from_raw ( EntityRow :: from_raw_u32 ( id) . unwrap ( ) ) ) >> 57 ;
1594
+ let hash = hash. hash_one ( Entity :: from_row ( EntityRow :: from_raw_u32 ( id) . unwrap ( ) ) ) >> 57 ;
1595
1595
assert_ne ! ( hash, first_hash) ;
1596
1596
}
1597
1597
}
@@ -1616,7 +1616,7 @@ mod tests {
1616
1616
1617
1617
#[ test]
1618
1618
fn entity_debug ( ) {
1619
- let entity = Entity :: from_raw ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
1619
+ let entity = Entity :: from_row ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
1620
1620
let string = format ! ( "{entity:?}" ) ;
1621
1621
assert_eq ! ( string, "42v0" ) ;
1622
1622
@@ -1627,7 +1627,7 @@ mod tests {
1627
1627
1628
1628
#[ test]
1629
1629
fn entity_display ( ) {
1630
- let entity = Entity :: from_raw ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
1630
+ let entity = Entity :: from_row ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
1631
1631
let string = format ! ( "{entity}" ) ;
1632
1632
assert_eq ! ( string, "42v0" ) ;
1633
1633
0 commit comments