Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
EamonHeffernan committed Oct 30, 2024
1 parent f0cf217 commit f0eed67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
39 changes: 19 additions & 20 deletions pumpkin-world/src/lighting/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::{collections::VecDeque, sync::Arc};
use tokio::sync::RwLock;

use crate::{
block::{
block_registry::{get_state, State},
BlockId,
},
block::{block_registry::get_state, BlockId},
chunk::{ChunkBlocks, ChunkData},
};

Expand Down Expand Up @@ -130,9 +127,7 @@ pub enum SubChunkLighting {

impl SubChunkLighting {
fn initialized() -> Self {
Self::Initialized(SubChunkLightData {
0: Box::new([0; SUBCHUNK_VOLUME / 2]),
})
Self::Initialized(SubChunkLightData(Box::new([0; SUBCHUNK_VOLUME / 2])))
}
}

Expand Down Expand Up @@ -265,6 +260,12 @@ impl ChunkRelativeCoordinates {
}
}

impl Default for ChunkLightData {
fn default() -> Self {
Self::new()
}
}

impl ChunkLightData {
pub fn new() -> Self {
Self {
Expand All @@ -284,7 +285,7 @@ impl ChunkLightData {
}

fn subchunk_empty(blocks: &ChunkBlocks, i: i32) -> bool {
if i < MIN_BLOCK_SUBCHUNK || i > MAX_BLOCK_SUBCHUNK {
if !(MIN_BLOCK_SUBCHUNK..=MAX_BLOCK_SUBCHUNK).contains(&i) {
return true;
}

Expand Down Expand Up @@ -511,8 +512,8 @@ impl ChunkLightData {
for value in blocks.heightmap.world_surface.iter() {
for i in 0..ENTRIES_PER_LONG {
// Get last 9 bits
let foo = (value >> (BITS_PER_ENTRY * i)) & 0b111111111;
column_heights.push(foo as i32);
let value = (value >> (BITS_PER_ENTRY * i)) & 0b111111111;
column_heights.push(value as i32);
}
}

Expand Down Expand Up @@ -568,8 +569,8 @@ impl ChunkLightData {

let next_block_y = (subchunk_y * 16) + (y as i32) - 1;

let light_reduction = if next_block_y < MAX_BLOCK_SUBCHUNK * 16
&& next_block_y >= MIN_BLOCK_SUBCHUNK * 16
let light_reduction = if (MIN_BLOCK_SUBCHUNK * 16..MAX_BLOCK_SUBCHUNK * 16)
.contains(&next_block_y)
{
let next_block = blocks.get_block(
crate::coordinates::ChunkRelativeBlockCoordinates {
Expand Down Expand Up @@ -597,17 +598,15 @@ impl ChunkLightData {
},
});

light_level = light_level - light_reduction;
light_level -= light_reduction;
}
}
}
}

self.edge_lighting(blocks, surrounding_chunks).await;

let neighbor_chunk_propagations = self.propagate_increase(&blocks);

neighbor_chunk_propagations
self.propagate_increase(blocks)
}

pub async fn increase_light_levels(
Expand All @@ -632,10 +631,10 @@ impl ChunkLightData {
(light_changed, self.propagate_increase(blocks))
}

pub fn packet_data(&self) -> (i64, i64, Vec<&Box<[u8; 2048]>>) {
pub fn packet_data(&self) -> (i64, i64, Vec<&[u8; 2048]>) {
let mut empty_mask = 0;
let mut set_mask = 0;
let mut things = Vec::new();
let mut subchunks = Vec::new();

for (i, subchunk) in self.subchunks.iter().enumerate() {
match subchunk {
Expand All @@ -645,7 +644,7 @@ impl ChunkLightData {
empty_mask |= 1 << i;
for level in light_data.0.iter() {
if *level != 0 {
things.push(&light_data.0);
subchunks.push(&*light_data.0);
set_mask |= 1 << i;
// Remove from empty
empty_mask ^= 1 << i;
Expand All @@ -656,7 +655,7 @@ impl ChunkLightData {
}
}

(set_mask, empty_mask, things)
(set_mask, empty_mask, subchunks)
}
}

Expand Down
9 changes: 4 additions & 5 deletions pumpkin-world/src/lighting/manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::{HashMap, HashSet},
collections::HashMap,
sync::Arc,
};

Expand All @@ -9,7 +9,6 @@ use pumpkin_core::math::vector2::Vector2;
use tokio::sync::RwLock;

use crate::{
block::{block_registry::State, BlockId},
chunk::ChunkData,
lighting::chunk::ChunkLightData,
};
Expand Down Expand Up @@ -73,7 +72,7 @@ impl LevelLightManager {
let modified_chunks: Vec<_> = self
.modified_chunks
.iter()
.map(|value| value.key().clone())
.map(|value| *value.key())
.collect();
self.modified_chunks.clear();

Expand Down Expand Up @@ -142,7 +141,7 @@ impl LevelLightManager {
.into_group_map();

for (dir, increases) in changes {
let to_chunk_coordinates = dir.apply(&chunk_coordinates);
let to_chunk_coordinates = dir.apply(chunk_coordinates);
Box::pin(self.increase_light_levels(
&to_chunk_coordinates,
chunk_coordinates,
Expand All @@ -159,7 +158,7 @@ impl LevelLightManager {
) {
let neighbor_changes = {
let surrounding_chunks =
Self::surrounding_chunk_coordinates(&chunk_coordinates).map(|coordinates| {
Self::surrounding_chunk_coordinates(chunk_coordinates).map(|coordinates| {
self.loaded_chunks
.get(&coordinates)
.map(|chunk| chunk.clone())
Expand Down
1 change: 0 additions & 1 deletion pumpkin-world/src/world_gen/generic_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use pumpkin_core::math::vector2::Vector2;
use crate::{
chunk::{ChunkBlocks, ChunkData},
coordinates::{ChunkRelativeBlockCoordinates, ChunkRelativeXZBlockCoordinates},
lighting::chunk::ChunkLightData,
WORLD_LOWEST_Y,
};

Expand Down

0 comments on commit f0eed67

Please sign in to comment.