From d7b162e68e3b7e44ff48d32dd81291947b1bbc85 Mon Sep 17 00:00:00 2001 From: Edvin Bryntesson Date: Sun, 20 Oct 2024 16:31:44 +0200 Subject: [PATCH] remove unnecessary cloning --- pumpkin-protocol/src/client/play/c_chunk_data.rs | 4 ++-- pumpkin-world/src/chunk/mod.rs | 2 -- pumpkin/src/world/mod.rs | 7 +++---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pumpkin-protocol/src/client/play/c_chunk_data.rs b/pumpkin-protocol/src/client/play/c_chunk_data.rs index 85c12effd..0a68eace2 100644 --- a/pumpkin-protocol/src/client/play/c_chunk_data.rs +++ b/pumpkin-protocol/src/client/play/c_chunk_data.rs @@ -6,9 +6,9 @@ use pumpkin_macros::packet; use pumpkin_world::{chunk::ChunkData, DIRECT_PALETTE_BITS}; #[packet(0x27)] -pub struct CChunkData(pub ChunkData); +pub struct CChunkData<'a>(pub &'a ChunkData); -impl ClientPacket for CChunkData { +impl<'a> ClientPacket for CChunkData<'a> { fn write(&self, buf: &mut crate::bytebuf::ByteBuffer) { // Chunk X buf.put_i32(self.0.position.x); diff --git a/pumpkin-world/src/chunk/mod.rs b/pumpkin-world/src/chunk/mod.rs index 9136de62b..f6c71604d 100644 --- a/pumpkin-world/src/chunk/mod.rs +++ b/pumpkin-world/src/chunk/mod.rs @@ -54,12 +54,10 @@ pub enum CompressionError { LZ4Error(std::io::Error), } -#[derive(Clone)] pub struct ChunkData { pub blocks: ChunkBlocks, pub position: Vector2, } -#[derive(Clone)] pub struct ChunkBlocks { // TODO make this a Vec that doesn't store the upper layers that only contain air diff --git a/pumpkin/src/world/mod.rs b/pumpkin/src/world/mod.rs index 607244cdd..2d303deda 100644 --- a/pumpkin/src/world/mod.rs +++ b/pumpkin/src/world/mod.rs @@ -1,4 +1,3 @@ -use std::ops::Deref; use std::{collections::HashMap, sync::Arc}; pub mod player_chunker; @@ -310,12 +309,13 @@ impl World { tokio::spawn(async move { log::debug!("Spawned chunk sender for {}", client_id); while let Some(chunk_data) = chunk_receiver.recv().await { - let chunk_data = chunk_data.read().await.deref().clone(); + let chunk_data = chunk_data.read().await; + let packet = CChunkData(&chunk_data); #[cfg(debug_assertions)] if chunk_data.position == (0, 0).into() { use pumpkin_protocol::bytebuf::ByteBuffer; let mut test = ByteBuffer::empty(); - CChunkData(chunk_data.clone()).write(&mut test); + packet.write(&mut test); let len = test.buf().len(); log::debug!( "Chunk packet size: {}B {}KB {}MB", @@ -324,7 +324,6 @@ impl World { len / (1024 * 1024) ); } - let packet = CChunkData(chunk_data); // TODO: Queue player packs in a queue so we don't need to check if its closed before // sending