pub fn build(self) -> EntityId {
        #[cold]
        #[inline(never)]
        fn assert_failed(id: u32) -> ! {
            panic!("archetype (id {}) not found", id);
        }

        #[cold]
        #[inline(never)]
        fn assert_failed2(c1: usize, c2: usize) -> ! {
            panic!(
                "entity component count ({}) != archetype component count ({})",
                c1, c2
            );
        }

        #[cold]
        #[inline(never)]
        fn assert_failed3(id: u32) -> ! {
            panic!("TypeId doesn't exist in archetype {}", id);
        }

        let temp_offsets = &mut self.container.temp_offsets;
        let temp_data = &self.container.temp_data;
        let archetype_id = self.archetype_id;

        let entity_id = if let Some(arch) = self
            .container
            .archetypes
            .get_mut(self.archetype_id as usize)
        {
            let entity_comp_count = temp_offsets.len();
            let arch_comp_count = arch.components.len();
            if entity_comp_count != arch_comp_count {
                assert_failed2(entity_comp_count, arch_comp_count);
            }

            let id = if let Some(free_slot) = arch.free_slots.iter().next() {
                arch.free_slots.remove(free_slot);
                free_slot
            } else {
                arch.total_slot_count += 1;
                arch.total_slot_count - 1
            };

            temp_offsets.drain().for_each(|(type_id, (offset, size))| {
                if let Some((_, data)) = arch.components.get_mut(&type_id) {
                    if id == (arch.total_slot_count - 1) {
                        data.extend(&temp_data[offset..(offset + size)]);
                    } else {
                        unsafe {
                            ptr::copy_nonoverlapping(
                                temp_data.as_ptr().add(offset),
                                data.as_mut_ptr().add(id * size),
                                size,
                            );
                        }
                    }
                } else {
                    assert_failed3(archetype_id);
                }
            });

            id as u32
        } else {
            assert_failed(archetype_id);
        };

        self.container.temp_data.clear();

        EntityId {
            archetype_id,
            id: entity_id,
        }
    }
/// Builds a new entity and returns its identifier.
///
/// # Panics
///
/// - if specified archetype is not found;
/// - if specified component types != archetype component types;
Builds a new entity and returns its identifier.
Builds a new entity and returns its identifier .
pub fn build(self) -> EntityId {
        #[cold]
        #[inline(never)]
        fn assert_failed(id: u32) -> ! {
            panic!("archetype (id {}) not found", id);
        }
        #[cold]
        #[inline(never)]
        fn assert_failed2(c1: usize, c2: usize) -> ! {
            panic!(
                "entity component count ({}) != archetype component count ({})",
                c1, c2
            );
        }
        #[cold]
        #[inline(never)]
        fn assert_failed3(id: u32) -> ! {
            panic!("TypeId doesn't exist in archetype {}", id);
        }
        let temp_offsets = &mut self.container.temp_offsets;
        let temp_data = &self.container.temp_data;
        let archetype_id = self.archetype_id;
        let entity_id = if let Some(arch) = self
            .container
            .archetypes
            .get_mut(self.archetype_id as usize)
        {
            let entity_comp_count = temp_offsets.len();
            let arch_comp_count = arch.components.len();
            if entity_comp_count != arch_comp_count {
                assert_failed2(entity_comp_count, arch_comp_count);
            }
            let id = if let Some(free_slot) = arch.free_slots.iter().next() {
                arch.free_slots.remove(free_slot);
                free_slot
            } else {
                arch.total_slot_count += 1;
                arch.total_slot_count - 1
            };
            temp_offsets.drain().for_each(|(type_id, (offset, size))| {
                if let Some((_, data)) = arch.components.get_mut(&type_id) {
                    if id == (arch.total_slot_count - 1) {
                        data.extend(&temp_data[offset..(offset + size)]);
                    } else {
                        unsafe {
                            ptr::copy_nonoverlapping(
                                temp_data.as_ptr().add(offset),
                                data.as_mut_ptr().add(id * size),
                                size,
                            );
                        }
                    }
                } else {
                    assert_failed3(archetype_id);
                }
            });
            id as u32
        } else {
            assert_failed(archetype_id);
        };
        self.container.temp_data.clear();
        EntityId {
            archetype_id,
            id: entity_id,
        }
    }
pub fn build ( self ) -> EntityId { # [ cold ] # [ inline ( never ) ] fn assert_failed ( id : u32 ) -> ! { panic ! ( " " id ) ; } # [ cold ] # [ inline ( never ) ] fn assert_failed2 ( c1 : usize , c2 : usize ) -> ! { panic ! ( " " c1 c2 ) ; } # [ cold ] # [ inline ( never ) ] fn assert_failed3 ( id : u32 ) -> ! { panic ! ( " " id ) ; } let temp_offsets = & mut self . container . temp_offsets ; let temp_data = & self . container . temp_data ; let archetype_id = self . archetype_id ; let entity_id = if let Some ( arch ) = self . container . archetypes . get_mut ( self . archetype_id as usize ) { let entity_comp_count = temp_offsets . len ( ) ; let arch_comp_count = arch . components . len ( ) ; if entity_comp_count != arch_comp_count { assert_failed2 ( entity_comp_count , arch_comp_count ) ; } let id = if let Some ( free_slot ) = arch . free_slots . iter ( ) . next ( ) { arch . free_slots . remove ( free_slot ) ; free_slot } else { arch . total_slot_count += 1 ; arch . total_slot_count - 1 } ; temp_offsets . drain ( ) . for_each ( | ( type_id , ( offset , size ) ) | { if let Some ( ( _ , data ) ) = arch . components . get_mut ( & type_id ) { if id == ( arch . total_slot_count - 1 ) { data . extend ( & temp_data [ offset .. ( offset + size ) ] ) ; } else { unsafe { ptr :: copy_nonoverlapping ( temp_data . as_ptr ( ) . add ( offset ) , data . as_mut_ptr ( ) . add ( id * size ) , size , ) ; } } } else { assert_failed3 ( archetype_id ) ; } } ) ; id as u32 } else { assert_failed ( archetype_id ) ; } ; self . container . temp_data . clear ( ) ; EntityId { archetype_id , id : entity_id , } }
Builds a new entity and returns its identifier.
Builds a new entity and returns its identifier .
self
self
panics
if specified archetype is not found;
if specified component types != archetype component types.
if specified archetype is not found ; if specified component types ! = archetype component types .