From 9b59198effba1b4d06b36f8b4109c66aa0682328 Mon Sep 17 00:00:00 2001 From: suprohub Date: Mon, 6 Jan 2025 14:13:13 +0400 Subject: [PATCH] clippy --- pumpkin-world/src/chunk/mod.rs | 20 +++++++++++++++++--- pumpkin/src/world/mod.rs | 10 +++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pumpkin-world/src/chunk/mod.rs b/pumpkin-world/src/chunk/mod.rs index 8647922b..dd302956 100644 --- a/pumpkin-world/src/chunk/mod.rs +++ b/pumpkin-world/src/chunk/mod.rs @@ -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; @@ -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); @@ -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())) } } @@ -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())) } } @@ -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> + '_> { match self { @@ -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 diff --git a/pumpkin/src/world/mod.rs b/pumpkin/src/world/mod.rs index 54c521cf..d5338e1b 100644 --- a/pumpkin/src/world/mod.rs +++ b/pumpkin/src/world/mod.rs @@ -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}; @@ -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() { @@ -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)]