remove unnecessary cloning

This commit is contained in:
Edvin Bryntesson 2024-10-20 16:31:44 +02:00
parent 843a1d7519
commit d7b162e68e
No known key found for this signature in database
3 changed files with 5 additions and 8 deletions

View File

@ -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);

View File

@ -54,12 +54,10 @@ pub enum CompressionError {
LZ4Error(std::io::Error),
}
#[derive(Clone)]
pub struct ChunkData {
pub blocks: ChunkBlocks,
pub position: Vector2<i32>,
}
#[derive(Clone)]
pub struct ChunkBlocks {
// TODO make this a Vec that doesn't store the upper layers that only contain air

View File

@ -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