2012-01-29 14:28:19 -05:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
#include "cPacket_MapChunk.h"
|
2012-03-14 16:56:09 -04:00
|
|
|
#include "../ChunkDef.h"
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
#include "zlib.h"
|
|
|
|
|
2012-01-29 14:28:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
cPacket_MapChunk::~cPacket_MapChunk()
|
|
|
|
{
|
2012-02-07 15:49:52 -05:00
|
|
|
delete [] m_CompressedData;
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-07 15:49:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-05-25 03:18:52 -04:00
|
|
|
cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const BLOCKTYPE * a_BlockData, const unsigned char * a_BiomeData)
|
2011-10-03 14:41:19 -04:00
|
|
|
{
|
|
|
|
m_PacketID = E_MAP_CHUNK;
|
|
|
|
|
2012-03-05 11:41:57 -05:00
|
|
|
m_PosX = a_ChunkX; // Chunk coordinates now, instead of block coordinates
|
|
|
|
m_PosZ = a_ChunkZ;
|
2012-03-01 13:08:53 -05:00
|
|
|
|
2012-03-12 15:29:31 -04:00
|
|
|
m_bContiguous = true; // false = no biome data, true = with biome data
|
2012-03-01 13:08:53 -05:00
|
|
|
m_BitMap1 = 0;
|
|
|
|
m_BitMap2 = 0;
|
|
|
|
|
|
|
|
m_UnusedInt = 0;
|
|
|
|
|
2012-03-03 15:55:16 -05:00
|
|
|
|
2012-03-14 16:56:09 -04:00
|
|
|
const int BlockDataSize = (cChunkDef::Height / 16) * (4096 + 2048 + 2048 + 2048);
|
|
|
|
const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width;
|
2012-03-12 15:29:31 -04:00
|
|
|
char AllData [ BlockDataSize + BiomeDataSize ];
|
2012-03-09 21:39:36 -05:00
|
|
|
|
|
|
|
#if AXIS_ORDER == AXIS_ORDER_YZX
|
2012-03-12 15:29:31 -04:00
|
|
|
memset( AllData, 0, BlockDataSize );
|
2012-03-01 13:08:53 -05:00
|
|
|
|
2012-03-01 13:56:56 -05:00
|
|
|
unsigned int iterator = 0;
|
2012-03-14 16:56:09 -04:00
|
|
|
for ( int i = 0; i < (cChunkDef::Height / 16); ++i )
|
2012-03-01 13:56:56 -05:00
|
|
|
{
|
2012-03-02 08:58:31 -05:00
|
|
|
m_BitMap1 |= (1 << i); // This tells what chunks are sent. Use this to NOT send air only chunks (right now everything is sent)
|
2012-03-05 11:41:57 -05:00
|
|
|
for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) for( int x = 0; x < 16; ++x )
|
2012-03-01 13:56:56 -05:00
|
|
|
{
|
2012-03-05 11:41:57 -05:00
|
|
|
int idx = cChunk::MakeIndex(x, y + i * 16, z);
|
2012-03-12 15:29:31 -04:00
|
|
|
AllData[iterator] = a_BlockData[idx];
|
2012-03-01 13:56:56 -05:00
|
|
|
++iterator;
|
2012-03-05 11:41:57 -05:00
|
|
|
} // for y, z, x
|
2012-03-01 13:56:56 -05:00
|
|
|
}
|
2012-03-05 11:41:57 -05:00
|
|
|
|
|
|
|
// Send block metadata:
|
2012-03-14 16:56:09 -04:00
|
|
|
char * Meta = a_BlockData + cChunkDef::NumBlocks;
|
|
|
|
for ( int i = 0; i < (cChunkDef::Height / 16); ++i )
|
2012-03-02 08:58:31 -05:00
|
|
|
{
|
2012-03-05 11:41:57 -05:00
|
|
|
for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z )
|
2012-03-02 08:58:31 -05:00
|
|
|
{
|
2012-03-05 11:41:57 -05:00
|
|
|
for ( int x = 0; x < 8; ++x )
|
2012-03-02 08:58:31 -05:00
|
|
|
{
|
2012-03-12 15:29:31 -04:00
|
|
|
AllData[iterator] = cChunk::GetNibble(Meta, x * 2 + 0, y + i * 16, z) | (cChunk::GetNibble(Meta, x * 2 + 1, y + i * 16, z ) << 4);
|
2012-03-02 08:58:31 -05:00
|
|
|
++iterator;
|
2012-03-05 11:41:57 -05:00
|
|
|
} // for x
|
|
|
|
} // for y, z
|
2012-03-02 08:58:31 -05:00
|
|
|
}
|
2012-03-05 11:41:57 -05:00
|
|
|
|
|
|
|
// Send block light:
|
2012-03-14 16:56:09 -04:00
|
|
|
char * Light = Meta + cChunkDef::NumBlocks / 2;
|
|
|
|
for ( int i = 0; i < (cChunkDef::Height / 16); ++i )
|
2012-03-02 08:58:31 -05:00
|
|
|
{
|
2012-03-05 11:41:57 -05:00
|
|
|
for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z )
|
2012-03-02 08:58:31 -05:00
|
|
|
{
|
2012-03-05 11:41:57 -05:00
|
|
|
for ( int x = 0; x < 8; ++x )
|
2012-03-02 08:58:31 -05:00
|
|
|
{
|
2012-03-12 15:29:31 -04:00
|
|
|
AllData[iterator] = cChunk::GetNibble(Light, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(Light, x * 2 + 1, y + i * 16, z ) << 4);
|
2012-03-02 08:58:31 -05:00
|
|
|
++iterator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-05 11:41:57 -05:00
|
|
|
|
|
|
|
// Send sky light:
|
2012-03-14 16:56:09 -04:00
|
|
|
char * SkyLight = Light + cChunkDef::NumBlocks / 2;
|
|
|
|
for( int i = 0; i < (cChunkDef::Height/16); ++i )
|
2012-03-02 08:58:31 -05:00
|
|
|
{
|
|
|
|
for( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z )
|
|
|
|
{
|
|
|
|
for( int x = 0; x < 8; ++x )
|
|
|
|
{
|
2012-03-12 15:29:31 -04:00
|
|
|
AllData[iterator] = cChunk::GetNibble(SkyLight, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(SkyLight, x * 2 + 1, y + i * 16, z ) << 4);
|
2012-03-02 08:58:31 -05:00
|
|
|
++iterator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-12 15:29:31 -04:00
|
|
|
memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize);
|
2012-03-10 08:49:40 -05:00
|
|
|
#elif AXIS_ORDER == AXIS_ORDER_XZY
|
2012-03-09 21:39:36 -05:00
|
|
|
for ( int i = 0; i < 16; ++i )
|
|
|
|
{
|
|
|
|
m_BitMap1 |= (1 << i);
|
|
|
|
}
|
2012-03-12 15:29:31 -04:00
|
|
|
memcpy(AllData, a_BlockData, BlockDataSize);
|
|
|
|
memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize);
|
|
|
|
#endif // AXIS_ORDER
|
2012-03-01 13:56:56 -05:00
|
|
|
|
2012-03-12 15:29:31 -04:00
|
|
|
uLongf CompressedSize = compressBound( sizeof(AllData) );
|
2012-03-01 13:08:53 -05:00
|
|
|
char * CompressedBlockData = new char[CompressedSize];
|
|
|
|
|
2012-03-12 15:29:31 -04:00
|
|
|
compress2( (Bytef*)CompressedBlockData, &CompressedSize, (const Bytef*)AllData, sizeof(AllData), Z_DEFAULT_COMPRESSION);
|
2012-03-01 13:08:53 -05:00
|
|
|
|
|
|
|
m_CompressedData = CompressedBlockData;
|
|
|
|
m_CompressedSize = CompressedSize;
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-07 15:49:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
cPacket_MapChunk::cPacket_MapChunk( const cPacket_MapChunk & a_Copy )
|
|
|
|
{
|
|
|
|
m_PacketID = E_MAP_CHUNK;
|
2012-03-01 13:08:53 -05:00
|
|
|
|
|
|
|
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 );
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-07 15:49:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPacket_MapChunk::Serialize(AString & a_Data) const
|
2011-10-03 14:41:19 -04:00
|
|
|
{
|
2012-02-07 15:49:52 -05:00
|
|
|
AppendByte (a_Data, m_PacketID);
|
2012-03-01 13:08:53 -05:00
|
|
|
|
|
|
|
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);
|
2012-02-07 15:49:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|