pub fn clone_from_single<M: Merger>(
        &mut self,
        source: &World,
        entity: Entity,
        merger: &mut M,
    ) -> Entity {
        // determine the destination ID
        let mut allocator = EntityAllocator::new();
        let dst_entity = merger.assign_id(entity, &mut allocator);

        // find conflicts, and remove the existing entity, to be replaced with that defined in the
        // source
        self.remove(dst_entity);

        // find the source
        let src_location = source
            .entities
            .get(entity)
            .expect("entity not found in source world");
        let src_arch = &source.archetypes[src_location.archetype()];

        // construct the destination entity layout
        let layout = merger.convert_layout((**src_arch.layout()).clone());

        // find or construct the destination archetype
        let dst_arch_index = self.insert_archetype(layout);
        let dst_arch = &mut self.archetypes[dst_arch_index.0 as usize];

        // build a writer for the destination archetype
        let mut writer =
            ArchetypeWriter::new(dst_arch_index, dst_arch, self.components.get_multi_mut());

        // push the entity ID into the archetype
        writer.push(dst_entity);

        let mut mappings = match merger.entity_map() {
            EntityRewrite::Auto(Some(mut overrides)) => {
                overrides.entry(entity).or_insert(dst_entity);
                overrides
            }
            EntityRewrite::Auto(None) => {
                let mut map = HashMap::default();
                map.insert(entity, dst_entity);
                map
            }
            EntityRewrite::Explicit(overrides) => overrides,
        };

        // set the entity mappings as context for Entity::clone
        ID_CLONE_MAPPINGS.with(|cell| {
            std::mem::swap(&mut *cell.borrow_mut(), &mut mappings);
        });

        // merge components into the archetype
        let index = src_location.component().0;
        merger.merge_archetype(
            index..(index + 1),
            src_arch,
            &source.components,
            &mut writer,
        );

        // record entity location
        let (base, entities) = writer.inserted();
        self.entities.insert(entities, dst_arch_index, base);

        ID_CLONE_MAPPINGS.with(|cell| {
            cell.borrow_mut().clear();
        });

        dst_entity
    }
/// Clones a single entity from the source world into the destination world.
Clones a single entity from the source world into the destination world.
Clones a single entity from the source world into the destination world .
pub fn clone_from_single<M: Merger>(
        &mut self,
        source: &World,
        entity: Entity,
        merger: &mut M,
    ) -> Entity {
        // determine the destination ID
        let mut allocator = EntityAllocator::new();
        let dst_entity = merger.assign_id(entity, &mut allocator);
        // find conflicts, and remove the existing entity, to be replaced with that defined in the
        // source
        self.remove(dst_entity);
        // find the source
        let src_location = source
            .entities
            .get(entity)
            .expect("entity not found in source world");
        let src_arch = &source.archetypes[src_location.archetype()];
        // construct the destination entity layout
        let layout = merger.convert_layout((**src_arch.layout()).clone());
        // find or construct the destination archetype
        let dst_arch_index = self.insert_archetype(layout);
        let dst_arch = &mut self.archetypes[dst_arch_index.0 as usize];
        // build a writer for the destination archetype
        let mut writer =
            ArchetypeWriter::new(dst_arch_index, dst_arch, self.components.get_multi_mut());
        // push the entity ID into the archetype
        writer.push(dst_entity);
        let mut mappings = match merger.entity_map() {
            EntityRewrite::Auto(Some(mut overrides)) => {
                overrides.entry(entity).or_insert(dst_entity);
                overrides
            }
            EntityRewrite::Auto(None) => {
                let mut map = HashMap::default();
                map.insert(entity, dst_entity);
                map
            }
            EntityRewrite::Explicit(overrides) => overrides,
        };
        // set the entity mappings as context for Entity::clone
        ID_CLONE_MAPPINGS.with(|cell| {
            std::mem::swap(&mut *cell.borrow_mut(), &mut mappings);
        });
        // merge components into the archetype
        let index = src_location.component().0;
        merger.merge_archetype(
            index..(index + 1),
            src_arch,
            &source.components,
            &mut writer,
        );
        // record entity location
        let (base, entities) = writer.inserted();
        self.entities.insert(entities, dst_arch_index, base);
        ID_CLONE_MAPPINGS.with(|cell| {
            cell.borrow_mut().clear();
        });
        dst_entity
    }
pub fn clone_from_single < M : Merger > ( & mut self , source : & World , entity : Entity , merger : & mut M , ) -> Entity { // determine the destination ID let mut allocator = EntityAllocator :: new ( ) ; let dst_entity = merger . assign_id ( entity , & mut allocator ) ; // find conflicts, and remove the existing entity, to be replaced with that defined in the // source self . remove ( dst_entity ) ; // find the source let src_location = source . entities . get ( entity ) . expect ( " " ) ; let src_arch = & source . archetypes [ src_location . archetype ( ) ] ; // construct the destination entity layout let layout = merger . convert_layout ( ( * * src_arch . layout ( ) ) . clone ( ) ) ; // find or construct the destination archetype let dst_arch_index = self . insert_archetype ( layout ) ; let dst_arch = & mut self . archetypes [ dst_arch_index . 0 as usize ] ; // build a writer for the destination archetype let mut writer = ArchetypeWriter :: new ( dst_arch_index , dst_arch , self . components . get_multi_mut ( ) ) ; // push the entity ID into the archetype writer . push ( dst_entity ) ; let mut mappings = match merger . entity_map ( ) { EntityRewrite :: Auto ( Some ( mut overrides ) ) => { overrides . entry ( entity ) . or_insert ( dst_entity ) ; overrides } EntityRewrite :: Auto ( None ) => { let mut map = HashMap :: default ( ) ; map . insert ( entity , dst_entity ) ; map } EntityRewrite :: Explicit ( overrides ) => overrides , } ; // set the entity mappings as context for Entity::clone ID_CLONE_MAPPINGS . with ( | cell | { std :: mem :: swap ( & mut * cell . borrow_mut ( ) , & mut mappings ) ; } ) ; // merge components into the archetype let index = src_location . component ( ) . 0 ; merger . merge_archetype ( index .. ( index + 1 ) , src_arch , & source . components , & mut writer , ) ; // record entity location let ( base , entities ) = writer . inserted ( ) ; self . entities . insert ( entities , dst_arch_index , base ) ; ID_CLONE_MAPPINGS . with ( | cell | { cell . borrow_mut ( ) . clear ( ) ; } ) ; dst_entity }
Clones a single entity from the source world into the destination world.
Clones a single entity from the source world into the destination world .
&mut self
source
&World
entity
Entity
merger
&mut M
&mut self
source
&World
entity
Entity
merger
&mut M