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