summaryrefslogtreecommitdiffstats
path: root/source/packets
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-26 23:01:07 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-26 23:01:07 +0200
commitd97ad781b4ea1998b9819f139c7ab7806161042e (patch)
tree84f8b2e37bb141b7ef57e34385ab0be7b7dc60d2 /source/packets
parentTurned a common assert into a warning log (diff)
downloadcuberite-d97ad781b4ea1998b9819f139c7ab7806161042e.tar
cuberite-d97ad781b4ea1998b9819f139c7ab7806161042e.tar.gz
cuberite-d97ad781b4ea1998b9819f139c7ab7806161042e.tar.bz2
cuberite-d97ad781b4ea1998b9819f139c7ab7806161042e.tar.lz
cuberite-d97ad781b4ea1998b9819f139c7ab7806161042e.tar.xz
cuberite-d97ad781b4ea1998b9819f139c7ab7806161042e.tar.zst
cuberite-d97ad781b4ea1998b9819f139c7ab7806161042e.zip
Diffstat (limited to 'source/packets')
-rw-r--r--source/packets/cPacket_MapChunk.cpp130
-rw-r--r--source/packets/cPacket_MapChunk.h25
2 files changed, 12 insertions, 143 deletions
diff --git a/source/packets/cPacket_MapChunk.cpp b/source/packets/cPacket_MapChunk.cpp
index 21c62da45..17fbdba24 100644
--- a/source/packets/cPacket_MapChunk.cpp
+++ b/source/packets/cPacket_MapChunk.cpp
@@ -4,131 +4,16 @@
#include "cPacket_MapChunk.h"
#include "../ChunkDef.h"
-#include "zlib.h"
-
-cPacket_MapChunk::~cPacket_MapChunk()
-{
- delete [] m_CompressedData;
-}
-
-
-
-
-
-cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const BLOCKTYPE * a_BlockData, const unsigned char * a_BiomeData)
+cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkZ, const AString & a_SerializedData) :
+ m_PosX(a_ChunkX),
+ m_PosZ(a_ChunkZ),
+ m_SerializedData(a_SerializedData)
{
m_PacketID = E_MAP_CHUNK;
-
- m_PosX = a_ChunkX; // Chunk coordinates now, instead of block coordinates
- m_PosZ = a_ChunkZ;
-
- m_bContiguous = true; // false = no biome data, true = with biome data
- m_BitMap1 = 0;
- m_BitMap2 = 0;
-
- m_UnusedInt = 0;
-
-
- const int BlockDataSize = (cChunkDef::Height / 16) * (4096 + 2048 + 2048 + 2048);
- const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width;
- char AllData [ BlockDataSize + BiomeDataSize ];
-
-#if AXIS_ORDER == AXIS_ORDER_YZX
- memset( AllData, 0, BlockDataSize );
-
- unsigned int iterator = 0;
- for ( int i = 0; i < (cChunkDef::Height / 16); ++i )
- {
- m_BitMap1 |= (1 << i); // This tells what chunks are sent. Use this to NOT send air only chunks (right now everything is sent)
- for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) for( int x = 0; x < 16; ++x )
- {
- int idx = cChunk::MakeIndex(x, y + i * 16, z);
- AllData[iterator] = a_BlockData[idx];
- ++iterator;
- } // for y, z, x
- }
-
- // Send block metadata:
- char * Meta = a_BlockData + cChunkDef::NumBlocks;
- for ( int i = 0; i < (cChunkDef::Height / 16); ++i )
- {
- for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z )
- {
- for ( int x = 0; x < 8; ++x )
- {
- AllData[iterator] = cChunk::GetNibble(Meta, x * 2 + 0, y + i * 16, z) | (cChunk::GetNibble(Meta, x * 2 + 1, y + i * 16, z ) << 4);
- ++iterator;
- } // for x
- } // for y, z
- }
-
- // Send block light:
- char * Light = Meta + cChunkDef::NumBlocks / 2;
- for ( int i = 0; i < (cChunkDef::Height / 16); ++i )
- {
- for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z )
- {
- for ( int x = 0; x < 8; ++x )
- {
- AllData[iterator] = cChunk::GetNibble(Light, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(Light, x * 2 + 1, y + i * 16, z ) << 4);
- ++iterator;
- }
- }
- }
-
- // Send sky light:
- char * SkyLight = Light + cChunkDef::NumBlocks / 2;
- for( int i = 0; i < (cChunkDef::Height/16); ++i )
- {
- for( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z )
- {
- for( int x = 0; x < 8; ++x )
- {
- AllData[iterator] = cChunk::GetNibble(SkyLight, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(SkyLight, x * 2 + 1, y + i * 16, z ) << 4);
- ++iterator;
- }
- }
- }
- memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize);
-#elif AXIS_ORDER == AXIS_ORDER_XZY
- for ( int i = 0; i < 16; ++i )
- {
- m_BitMap1 |= (1 << i);
- }
- memcpy(AllData, a_BlockData, BlockDataSize);
- memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize);
-#endif // AXIS_ORDER
-
- uLongf CompressedSize = compressBound( sizeof(AllData) );
- char * CompressedBlockData = new char[CompressedSize];
-
- compress2( (Bytef*)CompressedBlockData, &CompressedSize, (const Bytef*)AllData, sizeof(AllData), Z_DEFAULT_COMPRESSION);
-
- m_CompressedData = CompressedBlockData;
- m_CompressedSize = CompressedSize;
-}
-
-
-
-
-
-cPacket_MapChunk::cPacket_MapChunk( const cPacket_MapChunk & a_Copy )
-{
- m_PacketID = E_MAP_CHUNK;
-
- m_PosX = a_Copy.m_PosX;
- m_PosZ = a_Copy.m_PosZ;
- m_bContiguous = a_Copy.m_bContiguous;
- m_BitMap1 = a_Copy.m_BitMap1;
- m_BitMap2 = a_Copy.m_BitMap2;
-
- m_CompressedSize = a_Copy.m_CompressedSize;
- m_CompressedData = new char[m_CompressedSize];
- memcpy( m_CompressedData, a_Copy.m_CompressedData, m_CompressedSize );
}
@@ -141,12 +26,7 @@ void cPacket_MapChunk::Serialize(AString & a_Data) const
AppendInteger(a_Data, m_PosX);
AppendInteger(a_Data, m_PosZ);
- AppendBool (a_Data, m_bContiguous);
- AppendShort (a_Data, m_BitMap1);
- AppendShort (a_Data, m_BitMap2);
- AppendInteger(a_Data, m_CompressedSize);
- AppendInteger(a_Data, m_UnusedInt);
- AppendData (a_Data, m_CompressedData, m_CompressedSize);
+ a_Data.append(m_SerializedData);
}
diff --git a/source/packets/cPacket_MapChunk.h b/source/packets/cPacket_MapChunk.h
index ec2f68632..35b5de08f 100644
--- a/source/packets/cPacket_MapChunk.h
+++ b/source/packets/cPacket_MapChunk.h
@@ -15,29 +15,18 @@ public:
cPacket_MapChunk()
: m_PosX( 0 )
, m_PosZ( 0 )
- , m_bContiguous( false )
- , m_BitMap1( 0 )
- , m_BitMap2( 0 )
- , m_CompressedSize( 0 )
- , m_UnusedInt( 0 )
- , m_CompressedData( NULL )
- { m_PacketID = E_MAP_CHUNK; }
+ {
+ m_PacketID = E_MAP_CHUNK;
+ }
- cPacket_MapChunk( const cPacket_MapChunk & a_Copy );
- cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const BLOCKTYPE * a_BlockData, const unsigned char * a_BiomeData);
- ~cPacket_MapChunk();
+ cPacket_MapChunk(int a_ChunkX, int a_ChunkZ, const AString & a_SerializedData);
virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); }
virtual void Serialize(AString & a_Data) const override;
- int m_PosX;
- int m_PosZ;
- bool m_bContiguous;
- short m_BitMap1;
- short m_BitMap2;
- int m_CompressedSize;
- int m_UnusedInt;
- char * m_CompressedData;
+ int m_PosX;
+ int m_PosZ;
+ AString m_SerializedData;
};