pub fn save_chunks(
    chunk_map: &mut ChunkMap,
    chunk_entities: &ChunkEntities,
    lazy: &LazyUpdate,
) -> u32 {
    let count = AtomicUsize::new(0);
    chunk_map
        .chunks_mut()
        .par_iter_mut()
        .map(|(_, chunk)| {
            let (dirty, entities) = chunk_entities.entities_in_chunk_and_modified(chunk.position());
            (chunk, entities, dirty)
        })
        .for_each(|(chunk, entities, dirty)| {
            // If all of the following are true, don't save the chunk:
            // * The chunk has not been modified since the last save.
            // * The entities in the chunk are empty (if they weren't, it is likely they were modified)
            // * The entities in the chunk haven't changed.
            if !chunk.check_modified() && (entities.is_empty() && !dirty) {
                return;
            }

            // World access is required for entity serialization,
            // so we perform the saving itself asynchronously.
            let chunk = Arc::new(chunk.clone());
            let entities: Vec<Entity> = entities.to_vec();
            lazy.exec(move |world| {
                // Compute entity data.
                let entity_data = entities
                    .into_iter()
                    .filter_map(|entity| {
                        let serializers = world.read_component::<SerializerComponent>();
                        let serializer = match serializers.get(entity) {
                            Some(serializer) => serializer,
                            None => return None, // Entity not serialized
                        };

                        let serialize = serializer.0;
                        Some(serialize(world, entity))
                    })
                    .collect();

                let handle = world.fetch::<ChunkWorkerHandle>();
                chunk_logic::save_chunk(&handle, chunk, entity_data);
            });

            count.fetch_add(1, Ordering::Release);
        });

    let count = count.load(Ordering::Acquire);
    debug!("Saving {} chunks", count);
    count as u32
}
/// Saves all modified chunks.
///
/// The saves themselves are performed lazily and asynchronously.
///
/// Returns the number of chunks queued for saving.
Saves all modified chunks.
The saves themselves are performed lazily and asynchronously.

Returns the number of chunks queued for saving.
Saves all modified chunks . The saves themselves are performed lazily and asynchronously . Returns the number of chunks queued for saving .
pub fn save_chunks(
    chunk_map: &mut ChunkMap,
    chunk_entities: &ChunkEntities,
    lazy: &LazyUpdate,
) -> u32 {
    let count = AtomicUsize::new(0);
    chunk_map
        .chunks_mut()
        .par_iter_mut()
        .map(|(_, chunk)| {
            let (dirty, entities) = chunk_entities.entities_in_chunk_and_modified(chunk.position());
            (chunk, entities, dirty)
        })
        .for_each(|(chunk, entities, dirty)| {
            // If all of the following are true, don't save the chunk:
            // * The chunk has not been modified since the last save.
            // * The entities in the chunk are empty (if they weren't, it is likely they were modified)
            // * The entities in the chunk haven't changed.
            if !chunk.check_modified() && (entities.is_empty() && !dirty) {
                return;
            }
            // World access is required for entity serialization,
            // so we perform the saving itself asynchronously.
            let chunk = Arc::new(chunk.clone());
            let entities: Vec<Entity> = entities.to_vec();
            lazy.exec(move |world| {
                // Compute entity data.
                let entity_data = entities
                    .into_iter()
                    .filter_map(|entity| {
                        let serializers = world.read_component::<SerializerComponent>();
                        let serializer = match serializers.get(entity) {
                            Some(serializer) => serializer,
                            None => return None, // Entity not serialized
                        };
                        let serialize = serializer.0;
                        Some(serialize(world, entity))
                    })
                    .collect();
                let handle = world.fetch::<ChunkWorkerHandle>();
                chunk_logic::save_chunk(&handle, chunk, entity_data);
            });
            count.fetch_add(1, Ordering::Release);
        });
    let count = count.load(Ordering::Acquire);
    debug!("Saving {} chunks", count);
    count as u32
}
pub fn save_chunks ( chunk_map : & mut ChunkMap , chunk_entities : & ChunkEntities , lazy : & LazyUpdate , ) -> u32 { let count = AtomicUsize :: new ( 0 ) ; chunk_map . chunks_mut ( ) . par_iter_mut ( ) . map ( | ( _ , chunk ) | { let ( dirty , entities ) = chunk_entities . entities_in_chunk_and_modified ( chunk . position ( ) ) ; ( chunk , entities , dirty ) } ) . for_each ( | ( chunk , entities , dirty ) | { // If all of the following are true, don't save the chunk: // * The chunk has not been modified since the last save. // * The entities in the chunk are empty (if they weren't, it is likely they were modified) // * The entities in the chunk haven't changed. if ! chunk . check_modified ( ) && ( entities . is_empty ( ) && ! dirty ) { return ; } // World access is required for entity serialization, // so we perform the saving itself asynchronously. let chunk = Arc :: new ( chunk . clone ( ) ) ; let entities : Vec < Entity > = entities . to_vec ( ) ; lazy . exec ( move | world | { // Compute entity data. let entity_data = entities . into_iter ( ) . filter_map ( | entity | { let serializers = world . read_component :: < SerializerComponent > ( ) ; let serializer = match serializers . get ( entity ) { Some ( serializer ) => serializer , None => return None , // Entity not serialized } ; let serialize = serializer . 0 ; Some ( serialize ( world , entity ) ) } ) . collect ( ) ; let handle = world . fetch :: < ChunkWorkerHandle > ( ) ; chunk_logic :: save_chunk ( & handle , chunk , entity_data ) ; } ) ; count . fetch_add ( 1 , Ordering :: Release ) ; } ) ; let count = count . load ( Ordering :: Acquire ) ; debug ! ( " " count ) ; count as u32 }
Saves all modified chunks.
Saves all modified chunks .
chunk_map
&mut ChunkMap
chunk_entities
&ChunkEntities
lazy
&LazyUpdate
chunk_map
&mut ChunkMap
chunk_entities
&ChunkEntities
lazy
&LazyUpdate