Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
cChunkDataSerializer Class Reference

Serializes one chunk's data to (possibly multiple) protocol versions. More...

#include <ChunkDataSerializer.h>

Collaboration diagram for cChunkDataSerializer:
Collaboration graph
[legend]

Classes

struct  ChunkDataCache
 A single cache entry containing the raw data, compressed data, and a validity flag. More...
 

Public Member Functions

 cChunkDataSerializer (eDimension a_Dimension)
 
void SendToClients (int a_ChunkX, int a_ChunkZ, const ChunkBlockData &a_BlockData, const ChunkLightData &a_LightData, const unsigned char *a_BiomeMap, const ClientHandles &a_SendTo)
 For each client, serializes the chunk into their protocol version and sends it. More...
 

Private Types

enum class  CacheVersion {
  v47 , v107 , v110 , v393 ,
  v401 , v477 , Last = CacheVersion::v477
}
 Enum to collapse protocol versions into a contiguous index. More...
 
using ClientHandles = std::vector< std::shared_ptr< cClientHandle > >
 

Private Member Functions

void CompressPacketInto (ChunkDataCache &a_Cache)
 Finalises the data, compresses it if required, and stores it into cache. More...
 
void Serialize (const ClientHandles::value_type &a_Client, int a_ChunkX, int a_ChunkZ, const ChunkBlockData &a_BlockData, const ChunkLightData &a_LightData, const unsigned char *a_BiomeMap, CacheVersion a_CacheVersion)
 Serialises the given chunk, storing the result into the given cache entry, and sends the data. More...
 
void Serialize107 (int a_ChunkX, int a_ChunkZ, const ChunkBlockData &a_BlockData, const ChunkLightData &a_LightData, const unsigned char *a_BiomeMap)
 
void Serialize110 (int a_ChunkX, int a_ChunkZ, const ChunkBlockData &a_BlockData, const ChunkLightData &a_LightData, const unsigned char *a_BiomeMap)
 
template<auto Palette>
void Serialize393 (int a_ChunkX, int a_ChunkZ, const ChunkBlockData &a_BlockData, const ChunkLightData &a_LightData, const unsigned char *a_BiomeMap)
 
void Serialize47 (int a_ChunkX, int a_ChunkZ, const ChunkBlockData &a_BlockData, const ChunkLightData &a_LightData, const unsigned char *a_BiomeMap)
 
void Serialize477 (int a_ChunkX, int a_ChunkZ, const ChunkBlockData &a_BlockData, const ChunkLightData &a_LightData, const unsigned char *a_BiomeMap)
 
template<auto Palette>
void WriteBlockSectionSeamless (const ChunkBlockData::BlockArray *a_Blocks, const ChunkBlockData::MetaArray *a_Metas, UInt8 a_BitsPerEntry)
 Writes all blocks in a chunk section into a series of Int64. More...
 
void WriteLightSectionGrouped (const ChunkLightData::LightArray *a_BlockLights, const ChunkLightData::LightArray *a_SkyLights)
 Copies all lights in a chunk section into the packet, block light followed immediately by sky light. More...
 

Private Attributes

std::array< ChunkDataCache, static_cast< size_t >CacheVersion::Last)+1 > m_Cache
 A cache, mapping protocol version to a fully serialised chunk. More...
 
CircularBufferCompressor m_Compressor
 A compressor used to compress the chunk data. More...
 
const eDimension m_Dimension
 The dimension for the World this Serializer is tied to. More...
 
cByteBuffer m_Packet
 A staging area used to construct the chunk packet, persistent to avoid reallocating. More...
 

Detailed Description

Serializes one chunk's data to (possibly multiple) protocol versions.

Caches the serialized data for as long as this object lives, so that the same data can be sent to other clients using the same protocol.

Definition at line 22 of file ChunkDataSerializer.h.

Member Typedef Documentation

◆ ClientHandles

using cChunkDataSerializer::ClientHandles = std::vector<std::shared_ptr<cClientHandle> >
private

Definition at line 24 of file ChunkDataSerializer.h.

Member Enumeration Documentation

◆ CacheVersion

Enum to collapse protocol versions into a contiguous index.

Enumerator
v47 
v107 
v110 
v393 
v401 
v477 
Last 

Definition at line 27 of file ChunkDataSerializer.h.

Constructor & Destructor Documentation

◆ cChunkDataSerializer()

cChunkDataSerializer::cChunkDataSerializer ( eDimension  a_Dimension)

Definition at line 61 of file ChunkDataSerializer.cpp.

Member Function Documentation

◆ CompressPacketInto()

void cChunkDataSerializer::CompressPacketInto ( ChunkDataCache a_Cache)
inlineprivate

Finalises the data, compresses it if required, and stores it into cache.

Definition at line 605 of file ChunkDataSerializer.cpp.

◆ SendToClients()

void cChunkDataSerializer::SendToClients ( int  a_ChunkX,
int  a_ChunkZ,
const ChunkBlockData a_BlockData,
const ChunkLightData a_LightData,
const unsigned char *  a_BiomeMap,
const ClientHandles a_SendTo 
)

For each client, serializes the chunk into their protocol version and sends it.

Parameters are the coordinates of the chunk to serialise, and the data and biome data read from the chunk.

Definition at line 71 of file ChunkDataSerializer.cpp.

◆ Serialize()

void cChunkDataSerializer::Serialize ( const ClientHandles::value_type &  a_Client,
int  a_ChunkX,
int  a_ChunkZ,
const ChunkBlockData a_BlockData,
const ChunkLightData a_LightData,
const unsigned char *  a_BiomeMap,
CacheVersion  a_CacheVersion 
)
inlineprivate

Serialises the given chunk, storing the result into the given cache entry, and sends the data.

If the cache entry is already present, simply re-uses it.

Definition at line 135 of file ChunkDataSerializer.cpp.

◆ Serialize107()

void cChunkDataSerializer::Serialize107 ( int  a_ChunkX,
int  a_ChunkZ,
const ChunkBlockData a_BlockData,
const ChunkLightData a_LightData,
const unsigned char *  a_BiomeMap 
)
inlineprivate

Definition at line 278 of file ChunkDataSerializer.cpp.

◆ Serialize110()

void cChunkDataSerializer::Serialize110 ( int  a_ChunkX,
int  a_ChunkZ,
const ChunkBlockData a_BlockData,
const ChunkLightData a_LightData,
const unsigned char *  a_BiomeMap 
)
inlineprivate

Definition at line 336 of file ChunkDataSerializer.cpp.

◆ Serialize393()

template<auto Palette>
void cChunkDataSerializer::Serialize393 ( int  a_ChunkX,
int  a_ChunkZ,
const ChunkBlockData a_BlockData,
const ChunkLightData a_LightData,
const unsigned char *  a_BiomeMap 
)
inlineprivate

Definition at line 398 of file ChunkDataSerializer.cpp.

◆ Serialize47()

void cChunkDataSerializer::Serialize47 ( int  a_ChunkX,
int  a_ChunkZ,
const ChunkBlockData a_BlockData,
const ChunkLightData a_LightData,
const unsigned char *  a_BiomeMap 
)
inlineprivate

Definition at line 188 of file ChunkDataSerializer.cpp.

◆ Serialize477()

void cChunkDataSerializer::Serialize477 ( int  a_ChunkX,
int  a_ChunkZ,
const ChunkBlockData a_BlockData,
const ChunkLightData a_LightData,
const unsigned char *  a_BiomeMap 
)
inlineprivate

Definition at line 460 of file ChunkDataSerializer.cpp.

◆ WriteBlockSectionSeamless()

template<auto Palette>
void cChunkDataSerializer::WriteBlockSectionSeamless ( const ChunkBlockData::BlockArray a_Blocks,
const ChunkBlockData::MetaArray a_Metas,
UInt8  a_BitsPerEntry 
)
inlineprivate

Writes all blocks in a chunk section into a series of Int64.

Writes start from the bit directly subsequent to the previous write's end, possibly crossing over to the next Int64.

Definition at line 526 of file ChunkDataSerializer.cpp.

◆ WriteLightSectionGrouped()

void cChunkDataSerializer::WriteLightSectionGrouped ( const ChunkLightData::LightArray a_BlockLights,
const ChunkLightData::LightArray a_SkyLights 
)
inlineprivate

Copies all lights in a chunk section into the packet, block light followed immediately by sky light.

Definition at line 575 of file ChunkDataSerializer.cpp.

Member Data Documentation

◆ m_Cache

std::array<ChunkDataCache, static_cast<size_t>CacheVersion::Last) + 1> cChunkDataSerializer::m_Cache
private

A cache, mapping protocol version to a fully serialised chunk.

It is used during a single invocation of SendToClients with more than one client.

Definition at line 89 of file ChunkDataSerializer.h.

◆ m_Compressor

CircularBufferCompressor cChunkDataSerializer::m_Compressor
private

A compressor used to compress the chunk data.

Definition at line 82 of file ChunkDataSerializer.h.

◆ m_Dimension

const eDimension cChunkDataSerializer::m_Dimension
private

The dimension for the World this Serializer is tied to.

Definition at line 85 of file ChunkDataSerializer.h.

◆ m_Packet

cByteBuffer cChunkDataSerializer::m_Packet
private

A staging area used to construct the chunk packet, persistent to avoid reallocating.

Definition at line 79 of file ChunkDataSerializer.h.


The documentation for this class was generated from the following files: