pub fn add_component<T: Component>(&mut self, component: T) {
        if let Ok(comp) = self.get_component_mut::<T>() {
            *comp = component;
            return;
        }

        let target_arch = {
            let mut source = DynamicArchetype {
                base: self.world.archetypes()[self.location.archetype()]
                    .layout()
                    .clone(),
                add: &[ComponentTypeId::of::<T>()],
                add_constructors: &[|| Box::new(T::Storage::default())],
                remove: &[],
            };
            self.world.get_archetype_for_components(&mut source)
        };
        unsafe {
            let idx = self.world.transfer_archetype(
                self.location.archetype(),
                target_arch,
                self.location.component(),
            );
            self.world
                .components_mut()
                .get_downcast_mut::<T>()
                .unwrap()
                .extend_memcopy(target_arch, &component as *const T, 1);
            std::mem::forget(component);
            self.location = EntityLocation::new(target_arch, idx);
        };
    }
/// Adds a new component to the entity.
/// If the component already exists, its value will be replaced.
Adds a new component to the entity.
If the component already exists, its value will be replaced.
Adds a new component to the entity . If the component already exists its value will be replaced .
pub fn add_component<T: Component>(&mut self, component: T) {
        if let Ok(comp) = self.get_component_mut::<T>() {
            *comp = component;
            return;
        }
        let target_arch = {
            let mut source = DynamicArchetype {
                base: self.world.archetypes()[self.location.archetype()]
                    .layout()
                    .clone(),
                add: &[ComponentTypeId::of::<T>()],
                add_constructors: &[|| Box::new(T::Storage::default())],
                remove: &[],
            };
            self.world.get_archetype_for_components(&mut source)
        };
        unsafe {
            let idx = self.world.transfer_archetype(
                self.location.archetype(),
                target_arch,
                self.location.component(),
            );
            self.world
                .components_mut()
                .get_downcast_mut::<T>()
                .unwrap()
                .extend_memcopy(target_arch, &component as *const T, 1);
            std::mem::forget(component);
            self.location = EntityLocation::new(target_arch, idx);
        };
    }
pub fn add_component < T : Component > ( & mut self , component : T ) { if let Ok ( comp ) = self . get_component_mut :: < T > ( ) { * comp = component ; return ; } let target_arch = { let mut source = DynamicArchetype { base : self . world . archetypes ( ) [ self . location . archetype ( ) ] . layout ( ) . clone ( ) , add : & [ ComponentTypeId :: of :: < T > ( ) ] , add_constructors : & [ | | Box :: new ( T :: Storage :: default ( ) ) ] , remove : & [ ] , } ; self . world . get_archetype_for_components ( & mut source ) } ; unsafe { let idx = self . world . transfer_archetype ( self . location . archetype ( ) , target_arch , self . location . component ( ) , ) ; self . world . components_mut ( ) . get_downcast_mut :: < T > ( ) . unwrap ( ) . extend_memcopy ( target_arch , & component as * const T , 1 ) ; std :: mem :: forget ( component ) ; self . location = EntityLocation :: new ( target_arch , idx ) ; } ; }
Adds a new component to the entity.
Adds a new component to the entity .
&mut self
component
T
&mut self
component
T