aboutsummaryrefslogtreecommitdiff
path: root/packet_reader/packet_reader.ha
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-04-22 01:21:38 +0100
committerubq323 <ubq323@ubq323.website>2024-04-22 01:21:38 +0100
commit4c7156d0b20447e29f354679acdcd28480df91bc (patch)
treefdcaca21c06781a8732e50c6081cbc8ea30c3fc8 /packet_reader/packet_reader.ha
parent11c8b134d7de3d7b2249d74b26a87bc9d6acc27d (diff)
rlerle
Diffstat (limited to 'packet_reader/packet_reader.ha')
-rw-r--r--packet_reader/packet_reader.ha19
1 files changed, 12 insertions, 7 deletions
diff --git a/packet_reader/packet_reader.ha b/packet_reader/packet_reader.ha
index a1b5b8f..d541a11 100644
--- a/packet_reader/packet_reader.ha
+++ b/packet_reader/packet_reader.ha
@@ -100,17 +100,20 @@ export fn next(pr: *packet_reader) (packet | done | error) = {
case drawing::deser_fail => return "deser fail": error;
};
case packet_type::SEND_CHUNK =>
- // return value is BORROWED from the BUFFER
+ // return value muste be FREED by CALLER
+ // (we don't really need a copy here. todo)
+ // ((the copy isn't here, it's wherever uses here))
const pos_bytes = payload[0..8];
- const chunk_data_bytes = payload[8..];
+ const compressed_data_bytes = payload[8..];
const pos = (
endian::legetu32(pos_bytes[0..4]): i32,
endian::legetu32(pos_bytes[4..8]): i32
): pos;
- const d = cast_u8s_to_u32s(chunk_data_bytes);
- if (len(d) != CHUNKSIZE*CHUNKSIZE)
+ const chunk_data_compressed = cast_u8s_to_u32s(compressed_data_bytes);
+ const chunk_data = rle_decode(chunk_data_compressed);
+ if (len(chunk_data) != CHUNKSIZE*CHUNKSIZE)
return "wrong chunk size??": error;
- return packet_sendchunk { world_pos = pos, chunk_data = d };
+ return packet_sendchunk { world_pos = pos, chunk_data = chunk_data };
case packet_type::POSITION =>
if (len(payload) != 8)
return "position packet wrong size": error;
@@ -155,8 +158,10 @@ export fn send(sock: io::file, packet: packet) (void | io::error) = {
const pos_buf: [8]u8 = [0...];
endian::leputu32(pos_buf[0..4],packet.world_pos.0: u32);
endian::leputu32(pos_buf[4..8],packet.world_pos.1: u32);
- const chunk_data_bytes = cast_u32s_to_u8s(packet.chunk_data);
- send_raw(sock, packet_type::SEND_CHUNK, pos_buf, chunk_data_bytes)?;
+ const chunk_data_compressed = rle_encode(packet.chunk_data);
+ defer free(chunk_data_compressed);
+ const compressed_data_bytes = cast_u32s_to_u8s(chunk_data_compressed);
+ send_raw(sock, packet_type::SEND_CHUNK, pos_buf, compressed_data_bytes)?;
case let pos: packet_position =>
const pos_buf: [8]u8 = [0...];
endian::leputu32(pos_buf[0..4], pos.0: u32);