move get_insert_bundle_info (#2508)

I had to move this out in my relations PR and its causing a large diff so I figure I could just do this separately
This commit is contained in:
Boxy 2021-07-21 21:42:52 +00:00
parent 2c28331297
commit ba2916c45a

View file

@ -189,9 +189,9 @@ impl<'w> EntityMut<'w> {
}) })
} }
// TODO: move relevant methods to World (add/remove bundle) /// # Safety:
pub fn insert_bundle<T: Bundle>(&mut self, bundle: T) -> &mut Self { /// Partially moves the entity to a new archetype based on the provided bundle info
// Use a non-generic function to cut down on monomorphization /// You must handle the other part of moving the entity yourself
unsafe fn get_insert_bundle_info<'a>( unsafe fn get_insert_bundle_info<'a>(
entities: &mut Entities, entities: &mut Entities,
archetypes: &'a mut Archetypes, archetypes: &'a mut Archetypes,
@ -228,12 +228,10 @@ impl<'w> EntityMut<'w> {
let new_location = if old_table_id == new_table_id { let new_location = if old_table_id == new_table_id {
archetypes[new_archetype_id].allocate(entity, old_table_row) archetypes[new_archetype_id].allocate(entity, old_table_row)
} else { } else {
let (old_table, new_table) = let (old_table, new_table) = storages.tables.get_2_mut(old_table_id, new_table_id);
storages.tables.get_2_mut(old_table_id, new_table_id);
// PERF: store "non bundle" components in edge, then just move those to avoid // PERF: store "non bundle" components in edge, then just move those to avoid
// redundant copies // redundant copies
let move_result = let move_result = old_table.move_to_superset_unchecked(old_table_row, new_table);
old_table.move_to_superset_unchecked(old_table_row, new_table);
let new_location = let new_location =
archetypes[new_archetype_id].allocate(entity, move_result.new_row); archetypes[new_archetype_id].allocate(entity, move_result.new_row);
@ -259,6 +257,8 @@ impl<'w> EntityMut<'w> {
} }
} }
// TODO: move relevant methods to World (add/remove bundle)
pub fn insert_bundle<T: Bundle>(&mut self, bundle: T) -> &mut Self {
let change_tick = self.world.change_tick(); let change_tick = self.world.change_tick();
let bundle_info = self let bundle_info = self
.world .world
@ -266,7 +266,7 @@ impl<'w> EntityMut<'w> {
.init_info::<T>(&mut self.world.components); .init_info::<T>(&mut self.world.components);
let (archetype, bundle_status, new_location) = unsafe { let (archetype, bundle_status, new_location) = unsafe {
get_insert_bundle_info( Self::get_insert_bundle_info(
&mut self.world.entities, &mut self.world.entities,
&mut self.world.archetypes, &mut self.world.archetypes,
&mut self.world.components, &mut self.world.components,