remove unnecessary cloning
This commit is contained in:
parent
843a1d7519
commit
d7b162e68e
@ -6,9 +6,9 @@ use pumpkin_macros::packet;
|
|||||||
use pumpkin_world::{chunk::ChunkData, DIRECT_PALETTE_BITS};
|
use pumpkin_world::{chunk::ChunkData, DIRECT_PALETTE_BITS};
|
||||||
|
|
||||||
#[packet(0x27)]
|
#[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) {
|
fn write(&self, buf: &mut crate::bytebuf::ByteBuffer) {
|
||||||
// Chunk X
|
// Chunk X
|
||||||
buf.put_i32(self.0.position.x);
|
buf.put_i32(self.0.position.x);
|
||||||
|
|||||||
@ -54,12 +54,10 @@ pub enum CompressionError {
|
|||||||
LZ4Error(std::io::Error),
|
LZ4Error(std::io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ChunkData {
|
pub struct ChunkData {
|
||||||
pub blocks: ChunkBlocks,
|
pub blocks: ChunkBlocks,
|
||||||
pub position: Vector2<i32>,
|
pub position: Vector2<i32>,
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ChunkBlocks {
|
pub struct ChunkBlocks {
|
||||||
// TODO make this a Vec that doesn't store the upper layers that only contain air
|
// TODO make this a Vec that doesn't store the upper layers that only contain air
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
use std::ops::Deref;
|
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
pub mod player_chunker;
|
pub mod player_chunker;
|
||||||
@ -310,12 +309,13 @@ impl World {
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
log::debug!("Spawned chunk sender for {}", client_id);
|
log::debug!("Spawned chunk sender for {}", client_id);
|
||||||
while let Some(chunk_data) = chunk_receiver.recv().await {
|
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)]
|
#[cfg(debug_assertions)]
|
||||||
if chunk_data.position == (0, 0).into() {
|
if chunk_data.position == (0, 0).into() {
|
||||||
use pumpkin_protocol::bytebuf::ByteBuffer;
|
use pumpkin_protocol::bytebuf::ByteBuffer;
|
||||||
let mut test = ByteBuffer::empty();
|
let mut test = ByteBuffer::empty();
|
||||||
CChunkData(chunk_data.clone()).write(&mut test);
|
packet.write(&mut test);
|
||||||
let len = test.buf().len();
|
let len = test.buf().len();
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"Chunk packet size: {}B {}KB {}MB",
|
"Chunk packet size: {}B {}KB {}MB",
|
||||||
@ -324,7 +324,6 @@ impl World {
|
|||||||
len / (1024 * 1024)
|
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
|
// TODO: Queue player packs in a queue so we don't need to check if its closed before
|
||||||
// sending
|
// sending
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user