@@ -4,10 +4,10 @@ use crate::{
4
4
change_detection:: { MutUntyped , Ticks } ,
5
5
component:: { Component , ComponentId , ComponentTicks , Components , StorageType } ,
6
6
entity:: { Entities , Entity , EntityLocation } ,
7
- storage:: { SparseSet , Storages } ,
7
+ storage:: Storages ,
8
8
world:: { Mut , World } ,
9
9
} ;
10
- use bevy_ptr:: { OwningPtr , Ptr , UnsafeCellDeref } ;
10
+ use bevy_ptr:: { Ptr , UnsafeCellDeref } ;
11
11
use std:: any:: TypeId ;
12
12
13
13
/// A read-only reference to a particular [`Entity`] and all of its components
@@ -389,10 +389,12 @@ impl<'w> EntityMut<'w> {
389
389
let result = unsafe {
390
390
T :: from_components ( storages, & mut |storages| {
391
391
let component_id = bundle_components. next ( ) . unwrap ( ) ;
392
- // SAFETY: entity location is valid and table row is removed below
393
- take_component (
392
+ // SAFETY:
393
+ // - entity location is valid
394
+ // - table row is removed below
395
+ // - `components` comes from the same world as `storages`
396
+ storages. take_component (
394
397
components,
395
- storages,
396
398
old_archetype,
397
399
removed_components,
398
400
component_id,
@@ -663,48 +665,6 @@ impl<'w> EntityMut<'w> {
663
665
}
664
666
}
665
667
666
- // TODO: move to Storages?
667
- /// Moves component data out of storage.
668
- ///
669
- /// This function leaves the underlying memory unchanged, but the component behind
670
- /// returned pointer is semantically owned by the caller and will not be dropped in its original location.
671
- /// Caller is responsible to drop component data behind returned pointer.
672
- ///
673
- /// # Safety
674
- /// - `entity_location` must be within bounds of the given archetype and `entity` must exist inside the archetype
675
- /// - `component_id` must be valid
676
- /// - The relevant table row **must be removed** by the caller once all components are taken
677
- #[ inline]
678
- unsafe fn take_component < ' a > (
679
- components : & Components ,
680
- storages : & ' a mut Storages ,
681
- archetype : & Archetype ,
682
- removed_components : & mut SparseSet < ComponentId , Vec < Entity > > ,
683
- component_id : ComponentId ,
684
- entity : Entity ,
685
- location : EntityLocation ,
686
- ) -> OwningPtr < ' a > {
687
- let component_info = components. get_info_unchecked ( component_id) ;
688
- let removed_components = removed_components. get_or_insert_with ( component_id, Vec :: new) ;
689
- removed_components. push ( entity) ;
690
- match component_info. storage_type ( ) {
691
- StorageType :: Table => {
692
- let table = & mut storages. tables [ archetype. table_id ( ) ] ;
693
- // SAFETY: archetypes will always point to valid columns
694
- let components = table. get_column_mut ( component_id) . unwrap ( ) ;
695
- let table_row = archetype. entity_table_row ( location. index ) ;
696
- // SAFETY: archetypes only store valid table_rows and the stored component type is T
697
- components. get_data_unchecked_mut ( table_row) . promote ( )
698
- }
699
- StorageType :: SparseSet => storages
700
- . sparse_sets
701
- . get_mut ( component_id)
702
- . unwrap ( )
703
- . remove_and_forget ( entity)
704
- . unwrap ( ) ,
705
- }
706
- }
707
-
708
668
fn contains_component_with_type ( world : & World , type_id : TypeId , location : EntityLocation ) -> bool {
709
669
if let Some ( component_id) = world. components . get_id ( type_id) {
710
670
contains_component_with_id ( world, component_id, location)
0 commit comments