pub fn register_convert<
        Source: Component,
        Target: Component,
        F: FnMut(&Source) -> Target + 'static,
    >(
        &mut self,
        mut convert: F,
    ) {
        use crate::storage::ComponentStorage;

        let source_type = ComponentTypeId::of::<Source>();
        let dest_type = ComponentTypeId::of::<Target>();
        let constructor =
            || Box::new(Target::Storage::default()) as Box<dyn UnknownComponentStorage>;
        let convert = Box::new(
            move |src_entities: Range<usize>,
                  src_arch: &Archetype,
                  src: &dyn UnknownComponentStorage,
                  dst: &mut ArchetypeWriter<'_>| {
                let src = src.downcast_ref::<Source::Storage>().unwrap();
                let mut dst = dst.claim_components::<Target>();

                let src_slice = &src.get(src_arch.index()).unwrap().into_slice()[src_entities];
                dst.ensure_capacity(src_slice.len());
                for component in src_slice {
                    let component = convert(component);

                    unsafe {
                        dst.extend_memcopy(&component as *const Target, 1);
                        std::mem::forget(component);
                    }
                }
            },
        );

        self.duplicate_fns
            .insert(source_type, (dest_type, constructor, convert));
    }
/// Allows the merger to clone the given component into the destination world with a custom
/// clone function.
Allows the merger to clone the given component into the destination world with a custom
clone function.
Allows the merger to clone the given component into the destination world with a custom clone function .
pub fn register_convert<
        Source: Component,
        Target: Component,
        F: FnMut(&Source) -> Target + 'static,
    >(
        &mut self,
        mut convert: F,
    ) {
        use crate::storage::ComponentStorage;
        let source_type = ComponentTypeId::of::<Source>();
        let dest_type = ComponentTypeId::of::<Target>();
        let constructor =
            || Box::new(Target::Storage::default()) as Box<dyn UnknownComponentStorage>;
        let convert = Box::new(
            move |src_entities: Range<usize>,
                  src_arch: &Archetype,
                  src: &dyn UnknownComponentStorage,
                  dst: &mut ArchetypeWriter<'_>| {
                let src = src.downcast_ref::<Source::Storage>().unwrap();
                let mut dst = dst.claim_components::<Target>();
                let src_slice = &src.get(src_arch.index()).unwrap().into_slice()[src_entities];
                dst.ensure_capacity(src_slice.len());
                for component in src_slice {
                    let component = convert(component);
                    unsafe {
                        dst.extend_memcopy(&component as *const Target, 1);
                        std::mem::forget(component);
                    }
                }
            },
        );
        self.duplicate_fns
            .insert(source_type, (dest_type, constructor, convert));
    }
pub fn register_convert < Source : Component , Target : Component , F : FnMut ( & Source ) -> Target + ' static , > ( & mut self , mut convert : F , ) { use crate :: storage :: ComponentStorage ; let source_type = ComponentTypeId :: of :: < Source > ( ) ; let dest_type = ComponentTypeId :: of :: < Target > ( ) ; let constructor = | | Box :: new ( Target :: Storage :: default ( ) ) as Box < dyn UnknownComponentStorage > ; let convert = Box :: new ( move | src_entities : Range < usize > , src_arch : & Archetype , src : & dyn UnknownComponentStorage , dst : & mut ArchetypeWriter < ' _ > | { let src = src . downcast_ref :: < Source :: Storage > ( ) . unwrap ( ) ; let mut dst = dst . claim_components :: < Target > ( ) ; let src_slice = & src . get ( src_arch . index ( ) ) . unwrap ( ) . into_slice ( ) [ src_entities ] ; dst . ensure_capacity ( src_slice . len ( ) ) ; for component in src_slice { let component = convert ( component ) ; unsafe { dst . extend_memcopy ( & component as * const Target , 1 ) ; std :: mem :: forget ( component ) ; } } } , ) ; self . duplicate_fns . insert ( source_type , ( dest_type , constructor , convert ) ) ; }
Allows the merger to clone the given component into the destination world with a custom
clone function.
Allows the merger to clone the given component into the destination world with a custom clone function .
&mut self
convert
F
&mut self
convert
F