@@ -6,10 +6,10 @@ use crate::{
6
6
Component , ComponentId , ComponentStorage , ComponentTicks , Components , StorageType ,
7
7
} ,
8
8
entity:: { Entities , Entity , EntityLocation } ,
9
- storage:: { SparseSet , Storages } ,
9
+ storage:: Storages ,
10
10
world:: { Mut , World } ,
11
11
} ;
12
- use bevy_ptr:: { OwningPtr , Ptr } ;
12
+ use bevy_ptr:: Ptr ;
13
13
use bevy_utils:: tracing:: debug;
14
14
use std:: any:: TypeId ;
15
15
@@ -437,10 +437,12 @@ impl<'w> EntityMut<'w> {
437
437
let result = unsafe {
438
438
T :: from_components ( storages, & mut |storages| {
439
439
let component_id = bundle_components. next ( ) . unwrap ( ) ;
440
- // SAFETY: entity location is valid and table row is removed below
441
- take_component (
440
+ // SAFETY:
441
+ // - entity location is valid
442
+ // - table row is removed below
443
+ // - `components` comes from the same world as `storages`
444
+ storages. take_component (
442
445
components,
443
- storages,
444
446
removed_components,
445
447
component_id,
446
448
entity,
@@ -718,49 +720,6 @@ impl<'w> EntityMut<'w> {
718
720
}
719
721
}
720
722
721
- // TODO: move to Storages?
722
- /// Moves component data out of storage.
723
- ///
724
- /// This function leaves the underlying memory unchanged, but the component behind
725
- /// returned pointer is semantically owned by the caller and will not be dropped in its original location.
726
- /// Caller is responsible to drop component data behind returned pointer.
727
- ///
728
- /// # Safety
729
- /// - `location` must be within bounds of the given archetype and table and `entity` must exist inside the archetype
730
- /// and table.
731
- /// - `component_id` must be valid
732
- /// - The relevant table row **must be removed** by the caller once all components are taken
733
- #[ inline]
734
- unsafe fn take_component < ' a > (
735
- components : & Components ,
736
- storages : & ' a mut Storages ,
737
- removed_components : & mut SparseSet < ComponentId , Vec < Entity > > ,
738
- component_id : ComponentId ,
739
- entity : Entity ,
740
- location : EntityLocation ,
741
- ) -> OwningPtr < ' a > {
742
- let component_info = components. get_info_unchecked ( component_id) ;
743
- let removed_components = removed_components. get_or_insert_with ( component_id, Vec :: new) ;
744
- removed_components. push ( entity) ;
745
- match component_info. storage_type ( ) {
746
- StorageType :: Table => {
747
- let table = & mut storages. tables [ location. table_id ] ;
748
- // SAFETY: archetypes will always point to valid columns
749
- let components = table. get_column_mut ( component_id) . unwrap ( ) ;
750
- // SAFETY: archetypes only store valid table_rows and the stored component type is T
751
- components
752
- . get_data_unchecked_mut ( location. table_row )
753
- . promote ( )
754
- }
755
- StorageType :: SparseSet => storages
756
- . sparse_sets
757
- . get_mut ( component_id)
758
- . unwrap ( )
759
- . remove_and_forget ( entity)
760
- . unwrap ( ) ,
761
- }
762
- }
763
-
764
723
fn contains_component_with_type ( world : & World , type_id : TypeId , location : EntityLocation ) -> bool {
765
724
if let Some ( component_id) = world. components . get_id ( type_id) {
766
725
contains_component_with_id ( world, component_id, location)
0 commit comments