pub fn defrag(&mut self, budget: Option<usize>) {
        let span = span!(
            Level::INFO,
            "Defragmenting",
            world = self.id().0,
            start_archetype = self.defrag_progress
        );
        let _guard = span.enter();

        let archetypes = unsafe { &mut *self.storage.get() }.archetypes_mut();
        let mut budget = budget.unwrap_or(std::usize::MAX);
        let start = self.defrag_progress;
        while self.defrag_progress < archetypes.len() {
            // defragment the next archetype
            let complete =
                (&mut archetypes[self.defrag_progress]).defrag(&mut budget, |e, location| {
                    self.entity_locations.set(e, location);
                });
            if complete {
                // increment the index, looping it once we get to the end
                self.defrag_progress = (self.defrag_progress + 1) % archetypes.len();
            }

            // stop once we run out of budget or reach back to where we started
            if budget == 0 || self.defrag_progress == start {
                break;
            }
        }
    }
/// Iteratively defragments the world's internal memory.
///
/// This compacts entities into fewer more continuous chunks.
///
/// `budget` describes the maximum number of entities that can be moved
/// in one call. Subsequent calls to `defrag` will resume progress from the
/// previous call.
Iteratively defragments the world's internal memory.
This compacts entities into fewer more continuous chunks.

`budget` describes the maximum number of entities that can be moved
in one call. Subsequent calls to `defrag` will resume progress from the
previous call.
Iteratively defragments the world ' s internal memory . This compacts entities into fewer more continuous chunks . ` budget ` describes the maximum number of entities that can be moved in one call . Subsequent calls to ` defrag ` will resume progress from the previous call .
pub fn defrag(&mut self, budget: Option<usize>) {
        let span = span!(
            Level::INFO,
            "Defragmenting",
            world = self.id().0,
            start_archetype = self.defrag_progress
        );
        let _guard = span.enter();
        let archetypes = unsafe { &mut *self.storage.get() }.archetypes_mut();
        let mut budget = budget.unwrap_or(std::usize::MAX);
        let start = self.defrag_progress;
        while self.defrag_progress < archetypes.len() {
            // defragment the next archetype
            let complete =
                (&mut archetypes[self.defrag_progress]).defrag(&mut budget, |e, location| {
                    self.entity_locations.set(e, location);
                });
            if complete {
                // increment the index, looping it once we get to the end
                self.defrag_progress = (self.defrag_progress + 1) % archetypes.len();
            }
            // stop once we run out of budget or reach back to where we started
            if budget == 0 || self.defrag_progress == start {
                break;
            }
        }
    }
pub fn defrag ( & mut self , budget : Option < usize > ) { let span = span ! ( Level INFO " " world self id ( ) 0 start_archetype self defrag_progress ) ; let _guard = span . enter ( ) ; let archetypes = unsafe { & mut * self . storage . get ( ) } . archetypes_mut ( ) ; let mut budget = budget . unwrap_or ( std :: usize :: MAX ) ; let start = self . defrag_progress ; while self . defrag_progress < archetypes . len ( ) { // defragment the next archetype let complete = ( & mut archetypes [ self . defrag_progress ] ) . defrag ( & mut budget , | e , location | { self . entity_locations . set ( e , location ) ; } ) ; if complete { // increment the index, looping it once we get to the end self . defrag_progress = ( self . defrag_progress + 1 ) % archetypes . len ( ) ; } // stop once we run out of budget or reach back to where we started if budget == 0 || self . defrag_progress == start { break ; } } }
Iteratively defragments the world's internal memory.
Iteratively defragments the world ' s internal memory .
&mut self
budget
Option<usize>
&mut self
budget
Option<usize>