fn update_player_chunk(&self) {
        let mut shared = self.shared.borrow_mut();
        let load_distance = shared.load_distance;
        let player_chunk = shared.player_chunk.0;
        let radius = load_distance as i32;

        let is_chunk_in_range = |chunk_pos: AxialPoint| {
            let chunk_center = chunk_pos * CHUNK_SIZE as i32
                + AxialVector::new(CHUNK_SIZE as i32 / 2, CHUNK_SIZE as i32 / 2);
            let player_center = player_chunk * CHUNK_SIZE as i32
                + AxialVector::new(CHUNK_SIZE as i32 / 2, CHUNK_SIZE as i32 / 2);
            (chunk_center - player_center)
                .to_real()
                .distance(Vector2f::zero())
                < load_distance * CHUNK_SIZE as f32
        };

        // Load new range
        for qd in -radius..radius + 1 {
            for rd in -radius..radius + 1 {
                let chunk_pos = AxialPoint::new(player_chunk.q + qd, player_chunk.r + rd);
                if is_chunk_in_range(chunk_pos) {
                    let chunk_index = ChunkIndex(chunk_pos);

                    if !shared.world.chunks.contains_key(&chunk_index) {
                        if !shared.sent_requests.contains(&chunk_index) {
                            self.chunk_requests.send(chunk_index).unwrap();
                            shared.sent_requests.insert(chunk_index);
                        }
                    }
                }
            }
        }

        // Drop unneeded chunks from world
        let chunks = replace(&mut shared.world.chunks, HashMap::new());
        let mut new_chunks = HashMap::new();
        for (index, chunk) in chunks {
            let chunk_pos = index.0;
            if is_chunk_in_range(chunk_pos) {
                // Still in range
                new_chunks.insert(index, chunk);
            } else {
                // Remove
                shared.world_view.remove_chunk(index);
            }
        }
        shared.world.chunks = new_chunks;
    }
/// Called when the player moves to a different chunk.
///
/// This unloads all currently loaded chunks that are too far away from the
/// player, and loads all chunks close enough to the player (if they aren't
/// already requested).
Called when the player moves to a different chunk.
This unloads all currently loaded chunks that are too far away from the
player, and loads all chunks close enough to the player (if they aren't
already requested).
Called when the player moves to a different chunk . This unloads all currently loaded chunks that are too far away from the player and loads all chunks close enough to the player ( if they aren ' t already requested ) .
fn update_player_chunk(&self) {
        let mut shared = self.shared.borrow_mut();
        let load_distance = shared.load_distance;
        let player_chunk = shared.player_chunk.0;
        let radius = load_distance as i32;
        let is_chunk_in_range = |chunk_pos: AxialPoint| {
            let chunk_center = chunk_pos * CHUNK_SIZE as i32
                + AxialVector::new(CHUNK_SIZE as i32 / 2, CHUNK_SIZE as i32 / 2);
            let player_center = player_chunk * CHUNK_SIZE as i32
                + AxialVector::new(CHUNK_SIZE as i32 / 2, CHUNK_SIZE as i32 / 2);
            (chunk_center - player_center)
                .to_real()
                .distance(Vector2f::zero())
                < load_distance * CHUNK_SIZE as f32
        };
        // Load new range
        for qd in -radius..radius + 1 {
            for rd in -radius..radius + 1 {
                let chunk_pos = AxialPoint::new(player_chunk.q + qd, player_chunk.r + rd);
                if is_chunk_in_range(chunk_pos) {
                    let chunk_index = ChunkIndex(chunk_pos);
                    if !shared.world.chunks.contains_key(&chunk_index) {
                        if !shared.sent_requests.contains(&chunk_index) {
                            self.chunk_requests.send(chunk_index).unwrap();
                            shared.sent_requests.insert(chunk_index);
                        }
                    }
                }
            }
        }
        // Drop unneeded chunks from world
        let chunks = replace(&mut shared.world.chunks, HashMap::new());
        let mut new_chunks = HashMap::new();
        for (index, chunk) in chunks {
            let chunk_pos = index.0;
            if is_chunk_in_range(chunk_pos) {
                // Still in range
                new_chunks.insert(index, chunk);
            } else {
                // Remove
                shared.world_view.remove_chunk(index);
            }
        }
        shared.world.chunks = new_chunks;
    }
fn update_player_chunk ( & self ) { let mut shared = self . shared . borrow_mut ( ) ; let load_distance = shared . load_distance ; let player_chunk = shared . player_chunk . 0 ; let radius = load_distance as i32 ; let is_chunk_in_range = | chunk_pos : AxialPoint | { let chunk_center = chunk_pos * CHUNK_SIZE as i32 + AxialVector :: new ( CHUNK_SIZE as i32 / 2 , CHUNK_SIZE as i32 / 2 ) ; let player_center = player_chunk * CHUNK_SIZE as i32 + AxialVector :: new ( CHUNK_SIZE as i32 / 2 , CHUNK_SIZE as i32 / 2 ) ; ( chunk_center - player_center ) . to_real ( ) . distance ( Vector2f :: zero ( ) ) < load_distance * CHUNK_SIZE as f32 } ; // Load new range for qd in - radius .. radius + 1 { for rd in - radius .. radius + 1 { let chunk_pos = AxialPoint :: new ( player_chunk . q + qd , player_chunk . r + rd ) ; if is_chunk_in_range ( chunk_pos ) { let chunk_index = ChunkIndex ( chunk_pos ) ; if ! shared . world . chunks . contains_key ( & chunk_index ) { if ! shared . sent_requests . contains ( & chunk_index ) { self . chunk_requests . send ( chunk_index ) . unwrap ( ) ; shared . sent_requests . insert ( chunk_index ) ; } } } } } // Drop unneeded chunks from world let chunks = replace ( & mut shared . world . chunks , HashMap :: new ( ) ) ; let mut new_chunks = HashMap :: new ( ) ; for ( index , chunk ) in chunks { let chunk_pos = index . 0 ; if is_chunk_in_range ( chunk_pos ) { // Still in range new_chunks . insert ( index , chunk ) ; } else { // Remove shared . world_view . remove_chunk ( index ) ; } } shared . world . chunks = new_chunks ; }
Called when the player moves to a different chunk.
Called when the player moves to a different chunk .
&self