From 04f02a675de1b788f5e5ed6e681828ea3e358df7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 6 Jun 2021 17:22:42 +0100 Subject: Protocol: use dedicated packet for 1 block change It's six bytes smaller. --- src/Protocol/Protocol_1_13.cpp | 3 ++- src/Protocol/Protocol_1_8.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp index 336f3c339..5662fc45e 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -92,12 +92,13 @@ void cProtocol_1_13::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBloc Pkt.WriteBEInt32(a_ChunkX); Pkt.WriteBEInt32(a_ChunkZ); Pkt.WriteVarInt32(static_cast(a_Changes.size())); + for (const auto & Change : a_Changes) { Int16 Coords = static_cast(Change.m_RelY | (Change.m_RelZ << 8) | (Change.m_RelX << 12)); Pkt.WriteBEInt16(Coords); Pkt.WriteVarInt32(GetProtocolBlockType(Change.m_BlockType, Change.m_BlockMeta)); - } // for itr - a_Changes[] + } } diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index 980348887..5c8ffd5df 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -252,12 +252,13 @@ void cProtocol_1_8_0::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlo Pkt.WriteBEInt32(a_ChunkX); Pkt.WriteBEInt32(a_ChunkZ); Pkt.WriteVarInt32(static_cast(a_Changes.size())); - for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr) + + for (const auto & Change : a_Changes) { - Int16 Coords = static_cast(itr->m_RelY | (itr->m_RelZ << 8) | (itr->m_RelX << 12)); + Int16 Coords = static_cast(Change.m_RelY | (Change.m_RelZ << 8) | (Change.m_RelX << 12)); Pkt.WriteBEInt16(Coords); - Pkt.WriteVarInt32(static_cast(itr->m_BlockType & 0xFFF) << 4 | (itr->m_BlockMeta & 0xF)); - } // for itr - a_Changes[] + Pkt.WriteVarInt32(static_cast(Change.m_BlockType & 0xFFF) << 4 | (Change.m_BlockMeta & 0xF)); + } } -- cgit v1.2.3