Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
suprohub committed Jan 6, 2025
1 parent 8c8fa1e commit 9b59198
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
20 changes: 17 additions & 3 deletions pumpkin-world/src/chunk/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fastnbt::LongArray;
use pumpkin_config::ADVANCED_CONFIG;
use pumpkin_core::{math::vector2::Vector2, rle_vec::RleVec};
use serde::{Deserialize, Serialize};
use std::cmp::max;
Expand Down Expand Up @@ -220,7 +221,7 @@ impl Subchunk {
match self {
Self::Single(block) => {
if *block != new_block {
if compressed {
if compressed && ADVANCED_CONFIG.chunk_optimization.rle_compression.is_some() {
let mut blocks = RleVec::new();
blocks.push_n(SUBCHUNK_VOLUME, *block);
blocks.set(convert_index(position), new_block);
Expand All @@ -246,7 +247,8 @@ impl Subchunk {

if blocks.iter().all(|b| *b == new_block) {
*self = Self::Single(new_block)
} else if compressed {
} else if compressed && ADVANCED_CONFIG.chunk_optimization.rle_compression.is_some()
{
*self = Self::Rle(RleVec::from_iter(blocks.into_iter()))
}
}
Expand All @@ -259,7 +261,7 @@ impl Subchunk {
Self::Multi(blocks) => {
if blocks.iter().all(|b| b == blocks.first().unwrap()) {
*self = Self::Single(*blocks.first().unwrap())
} else {
} else if ADVANCED_CONFIG.chunk_optimization.rle_compression.is_some() {
*self = Self::Rle(RleVec::from_iter(blocks.into_iter()))
}
}
Expand Down Expand Up @@ -342,6 +344,14 @@ impl Subchunks {
}
}

pub fn optimize(&mut self) {
if let Self::Multi(subchunks) = self {
for subchunk in subchunks.iter_mut() {
subchunk.optimize();
}
}
}

//TODO: Needs optimizations
pub fn array_iter(&self) -> Box<dyn Iterator<Item = Box<[u16; SUBCHUNK_VOLUME]>> + '_> {
match self {
Expand Down Expand Up @@ -387,6 +397,10 @@ impl ChunkData {
.set_block_no_heightmap_update(position, block, compressed);
}

pub fn optimize(&mut self) {
self.subchunks.optimize();
}

#[expect(dead_code)]
fn calculate_heightmap(&self) -> ChunkHeightmaps {
// figure out how LongArray is formatted
Expand Down
10 changes: 7 additions & 3 deletions pumpkin/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
server::Server,
};
use level_time::LevelTime;
use pumpkin_config::BasicConfiguration;
use pumpkin_config::{BasicConfiguration, ADVANCED_CONFIG};
use pumpkin_core::math::vector2::Vector2;
use pumpkin_core::math::{position::WorldPosition, vector3::Vector3};
use pumpkin_core::text::{color::NamedColor, TextComponent};
Expand Down Expand Up @@ -563,8 +563,8 @@ impl World {
let level = self.level.clone();

tokio::spawn(async move {
while let Some(chunk_data) = receiver.recv().await {
let chunk_data = chunk_data.read().await;
while let Some(chunk_data_ref) = receiver.recv().await {
let chunk_data = chunk_data_ref.read().await;
let packet = CChunkData(&chunk_data);
#[cfg(debug_assertions)]
if chunk_data.position == (0, 0).into() {
Expand Down Expand Up @@ -595,6 +595,10 @@ impl World {
{
player.client.send_packet(&packet).await;
}

if ADVANCED_CONFIG.chunk_optimization.rle_compression.is_some() {
chunk_data_ref.write().await.optimize();
}
}

#[cfg(debug_assertions)]
Expand Down

0 comments on commit 9b59198

Please sign in to comment.