pub fn send_chunks_to_player(&mut self, player_chunk: ChunkPos, data: &mut super::PlayerData) -> Vec<(Arc<Chunk>, Arc<LightChunk>)>{
        const MAX_CHUNKS: usize = 20;
        let mut updates = Vec::new();
        for pos in data.close_chunks.get_close_chunks() {
            let pos = pos.offset_by_pos(player_chunk);
            if let Some(server_chunk) = self.chunks.get(&pos) {
                // Send the chunk to the player
                let loaded = data.loaded_chunks.insert(pos, server_chunk.version);
                if let Some(old_client_version) = loaded {
                    if old_client_version < server_chunk.version {
                        updates.push((server_chunk.chunk.clone(), server_chunk.light_chunk.clone()));
                    }
                } else {
                    updates.push((server_chunk.chunk.clone(), server_chunk.light_chunk.clone()));
                }
                if updates.len() == MAX_CHUNKS {
                    break
                }
            } else {
                // Generate the chunk
                let res = self.worldgen_worker.enqueue(pos);
                if res.is_ok() {
                    self.worldgen_queue.insert(pos);
                }
            }
        }
        updates
    }
/// Get chunks to send to a player this frame, and update the `PlayerData` accordingly. Start generating some chunks if necessary
Get chunks to send to a player this frame, and update the `PlayerData` accordingly. Start generating some chunks if necessary
Get chunks to send to a player this frame and update the ` PlayerData ` accordingly . Start generating some chunks if necessary
pub fn send_chunks_to_player(&mut self, player_chunk: ChunkPos, data: &mut super::PlayerData) -> Vec<(Arc<Chunk>, Arc<LightChunk>)>{
        const MAX_CHUNKS: usize = 20;
        let mut updates = Vec::new();
        for pos in data.close_chunks.get_close_chunks() {
            let pos = pos.offset_by_pos(player_chunk);
            if let Some(server_chunk) = self.chunks.get(&pos) {
                // Send the chunk to the player
                let loaded = data.loaded_chunks.insert(pos, server_chunk.version);
                if let Some(old_client_version) = loaded {
                    if old_client_version < server_chunk.version {
                        updates.push((server_chunk.chunk.clone(), server_chunk.light_chunk.clone()));
                    }
                } else {
                    updates.push((server_chunk.chunk.clone(), server_chunk.light_chunk.clone()));
                }
                if updates.len() == MAX_CHUNKS {
                    break
                }
            } else {
                // Generate the chunk
                let res = self.worldgen_worker.enqueue(pos);
                if res.is_ok() {
                    self.worldgen_queue.insert(pos);
                }
            }
        }
        updates
    }
pub fn send_chunks_to_player ( & mut self , player_chunk : ChunkPos , data : & mut super :: PlayerData ) -> Vec < ( Arc < Chunk > , Arc < LightChunk > ) > { const MAX_CHUNKS : usize = 20 ; let mut updates = Vec :: new ( ) ; for pos in data . close_chunks . get_close_chunks ( ) { let pos = pos . offset_by_pos ( player_chunk ) ; if let Some ( server_chunk ) = self . chunks . get ( & pos ) { // Send the chunk to the player let loaded = data . loaded_chunks . insert ( pos , server_chunk . version ) ; if let Some ( old_client_version ) = loaded { if old_client_version < server_chunk . version { updates . push ( ( server_chunk . chunk . clone ( ) , server_chunk . light_chunk . clone ( ) ) ) ; } } else { updates . push ( ( server_chunk . chunk . clone ( ) , server_chunk . light_chunk . clone ( ) ) ) ; } if updates . len ( ) == MAX_CHUNKS { break } } else { // Generate the chunk let res = self . worldgen_worker . enqueue ( pos ) ; if res . is_ok ( ) { self . worldgen_queue . insert ( pos ) ; } } } updates }
Get chunks to send to a player this frame, and update the `PlayerData` accordingly.
Get chunks to send to a player this frame and update the ` PlayerData ` accordingly .
&mut self
player_chunk
ChunkPos
data
&mut super::PlayerData
&mut self
player_chunk
ChunkPos
data
&mut super::PlayerData