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

#include <LightingThread.h>

Inheritance diagram for cLightingThread:
Inheritance graph
[legend]
Collaboration diagram for cLightingThread:
Collaboration graph
[legend]

Classes

class  cLightingChunkStay
 

Public Member Functions

 cLightingThread (cWorld &a_World)
 
size_t GetQueueLength (void)
 
void QueueChunk (int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_CallbackAfter)
 Queues the entire chunk for lighting. More...
 
void Stop (void)
 
void WaitForQueueEmpty (void)
 Blocks until the queue is empty or the thread is terminated. More...
 
virtual ~cLightingThread () override
 
- Public Member Functions inherited from cIsThread
 cIsThread (AString &&a_ThreadName)
 
bool IsCurrentThread (void) const
 Returns true if the thread calling this function is the thread contained within this object. More...
 
void Start (void)
 Starts the thread; returns without waiting for the actual start. More...
 
void Stop (void)
 Signals the thread to terminate and waits until it's finished. More...
 
virtual ~cIsThread ()
 

Protected Types

typedef std::list< cChunkStay * > cChunkStays
 

Protected Member Functions

void CalcLight (NIBBLETYPE *a_Light)
 Calculates light in the light array specified, using stored seeds. More...
 
void CalcLightStep (NIBBLETYPE *a_Light, size_t a_NumSeedsIn, unsigned char *a_IsSeedIn, unsigned int *a_SeedIdxIn, size_t &a_NumSeedsOut, unsigned char *a_IsSeedOut, unsigned int *a_SeedIdxOut)
 Does one step in the light calculation - one seed propagation and seed recalculation. More...
 
void CompressLight (NIBBLETYPE *a_LightArray, NIBBLETYPE *a_ChunkLight)
 Compresses from 1-block-per-byte (faster calc) into 2-blocks-per-byte (MC storage): More...
 
virtual void Execute (void) override
 This function, overloaded by the descendants, is called in the new thread. More...
 
void LightChunk (cLightingChunkStay &a_Item)
 Lights the entire chunk. More...
 
void PrepareBlockLight (void)
 Uses m_BlockTypes to initialize the m_BlockLight[] data; fills in seeds for the blocklight. More...
 
void PrepareSkyLight (void)
 Uses m_HeightMap to initialize the m_SkyLight[] data; fills in seeds for the skylight. More...
 
void PropagateLight (NIBBLETYPE *a_Light, unsigned int a_SrcIdx, unsigned int a_DstIdx, size_t &a_NumSeedsOut, unsigned char *a_IsSeedOut, unsigned int *a_SeedIdxOut)
 
void QueueChunkStay (cLightingChunkStay &a_ChunkStay)
 Queues a chunkstay that has all of its chunks loaded. More...
 
void ReadChunks (int a_ChunkX, int a_ChunkZ)
 Prepares m_BlockTypes and m_HeightMap data; zeroes out the light arrays. More...
 

Protected Attributes

NIBBLETYPE m_BlockLight [BlocksPerYLayer *cChunkDef::Height]
 
BLOCKTYPE m_BlockTypes [BlocksPerYLayer *cChunkDef::Height]
 
cCriticalSection m_CS
 The mutex to protect m_Queue and m_PendingQueue. More...
 
cEvent m_evtItemAdded
 
cEvent m_evtQueueEmpty
 
HEIGHTTYPE m_HeightMap [BlocksPerYLayer]
 
unsigned char m_IsSeed1 [BlocksPerYLayer *cChunkDef::Height]
 
unsigned char m_IsSeed2 [BlocksPerYLayer *cChunkDef::Height]
 
HEIGHTTYPE m_MaxHeight
 The highest block in the current 3x3 chunk data. More...
 
size_t m_NumSeeds
 
cChunkStays m_PendingQueue
 The ChunkStays that are waiting for load. More...
 
cChunkStays m_Queue
 The ChunkStays that are loaded and are waiting to be lit. More...
 
unsigned int m_SeedIdx1 [BlocksPerYLayer *cChunkDef::Height]
 
unsigned int m_SeedIdx2 [BlocksPerYLayer *cChunkDef::Height]
 
NIBBLETYPE m_SkyLight [BlocksPerYLayer *cChunkDef::Height]
 
cWorldm_World
 
- Protected Attributes inherited from cIsThread
std::atomic< bool > m_ShouldTerminate
 The overriden Execute() method should check this value periodically and terminate if this is true. More...
 

Static Protected Attributes

static const int BlocksPerYLayer = cChunkDef::Width * cChunkDef::Width * 3 * 3
 

Private Types

using Super = cIsThread
 

Detailed Description

Definition at line 48 of file LightingThread.h.

Member Typedef Documentation

◆ cChunkStays

typedef std::list<cChunkStay *> cLightingThread::cChunkStays
protected

Definition at line 92 of file LightingThread.h.

◆ Super

Definition at line 51 of file LightingThread.h.

Constructor & Destructor Documentation

◆ cLightingThread()

cLightingThread::cLightingThread ( cWorld a_World)

Definition at line 102 of file LightingThread.cpp.

◆ ~cLightingThread()

cLightingThread::~cLightingThread ( )
overridevirtual

Definition at line 114 of file LightingThread.cpp.

Member Function Documentation

◆ CalcLight()

void cLightingThread::CalcLight ( NIBBLETYPE a_Light)
protected

Calculates light in the light array specified, using stored seeds.

Definition at line 448 of file LightingThread.cpp.

◆ CalcLightStep()

void cLightingThread::CalcLightStep ( NIBBLETYPE a_Light,
size_t  a_NumSeedsIn,
unsigned char *  a_IsSeedIn,
unsigned int *  a_SeedIdxIn,
size_t &  a_NumSeedsOut,
unsigned char *  a_IsSeedOut,
unsigned int *  a_SeedIdxOut 
)
protected

Does one step in the light calculation - one seed propagation and seed recalculation.

Definition at line 473 of file LightingThread.cpp.

◆ CompressLight()

void cLightingThread::CompressLight ( NIBBLETYPE a_LightArray,
NIBBLETYPE a_ChunkLight 
)
protected

Compresses from 1-block-per-byte (faster calc) into 2-blocks-per-byte (MC storage):

Definition at line 520 of file LightingThread.cpp.

◆ Execute()

void cLightingThread::Execute ( void  )
overrideprotectedvirtual

This function, overloaded by the descendants, is called in the new thread.

Implements cIsThread.

Definition at line 190 of file LightingThread.cpp.

◆ GetQueueLength()

size_t cLightingThread::GetQueueLength ( void  )

Definition at line 180 of file LightingThread.cpp.

◆ LightChunk()

void cLightingThread::LightChunk ( cLightingChunkStay a_Item)
protected

Lights the entire chunk.

If neighbor chunks don't exist, touches them and re-queues the chunk

Definition at line 234 of file LightingThread.cpp.

◆ PrepareBlockLight()

void cLightingThread::PrepareBlockLight ( void  )
protected

Uses m_BlockTypes to initialize the m_BlockLight[] data; fills in seeds for the blocklight.

Definition at line 419 of file LightingThread.cpp.

◆ PrepareSkyLight()

void cLightingThread::PrepareSkyLight ( void  )
protected

Uses m_HeightMap to initialize the m_SkyLight[] data; fills in seeds for the skylight.

Definition at line 353 of file LightingThread.cpp.

◆ PropagateLight()

void cLightingThread::PropagateLight ( NIBBLETYPE a_Light,
unsigned int  a_SrcIdx,
unsigned int  a_DstIdx,
size_t &  a_NumSeedsOut,
unsigned char *  a_IsSeedOut,
unsigned int *  a_SeedIdxOut 
)
protected

Definition at line 545 of file LightingThread.cpp.

◆ QueueChunk()

void cLightingThread::QueueChunk ( int  a_ChunkX,
int  a_ChunkZ,
std::unique_ptr< cChunkCoordCallback a_CallbackAfter 
)

Queues the entire chunk for lighting.

The callback, if specified, is called after the lighting has been processed.

Definition at line 150 of file LightingThread.cpp.

◆ QueueChunkStay()

void cLightingThread::QueueChunkStay ( cLightingChunkStay a_ChunkStay)
protected

Queues a chunkstay that has all of its chunks loaded.

Called by cLightingChunkStay when all of its chunks are loaded.

Definition at line 572 of file LightingThread.cpp.

◆ ReadChunks()

void cLightingThread::ReadChunks ( int  a_ChunkX,
int  a_ChunkZ 
)
protected

Prepares m_BlockTypes and m_HeightMap data; zeroes out the light arrays.

Definition at line 330 of file LightingThread.cpp.

◆ Stop()

void cLightingThread::Stop ( void  )

Definition at line 123 of file LightingThread.cpp.

◆ WaitForQueueEmpty()

void cLightingThread::WaitForQueueEmpty ( void  )

Blocks until the queue is empty or the thread is terminated.

Definition at line 166 of file LightingThread.cpp.

Member Data Documentation

◆ BlocksPerYLayer

const int cLightingThread::BlocksPerYLayer = cChunkDef::Width * cChunkDef::Width * 3 * 3
staticprotected

Definition at line 118 of file LightingThread.h.

◆ m_BlockLight

NIBBLETYPE cLightingThread::m_BlockLight[BlocksPerYLayer *cChunkDef::Height]
protected

Definition at line 120 of file LightingThread.h.

◆ m_BlockTypes

BLOCKTYPE cLightingThread::m_BlockTypes[BlocksPerYLayer *cChunkDef::Height]
protected

Definition at line 119 of file LightingThread.h.

◆ m_CS

cCriticalSection cLightingThread::m_CS
protected

The mutex to protect m_Queue and m_PendingQueue.

Definition at line 98 of file LightingThread.h.

◆ m_evtItemAdded

cEvent cLightingThread::m_evtItemAdded
protected

Definition at line 106 of file LightingThread.h.

◆ m_evtQueueEmpty

cEvent cLightingThread::m_evtQueueEmpty
protected

Definition at line 107 of file LightingThread.h.

◆ m_HeightMap

HEIGHTTYPE cLightingThread::m_HeightMap[BlocksPerYLayer]
protected

Definition at line 122 of file LightingThread.h.

◆ m_IsSeed1

unsigned char cLightingThread::m_IsSeed1[BlocksPerYLayer *cChunkDef::Height]
protected

Definition at line 129 of file LightingThread.h.

◆ m_IsSeed2

unsigned char cLightingThread::m_IsSeed2[BlocksPerYLayer *cChunkDef::Height]
protected

Definition at line 131 of file LightingThread.h.

◆ m_MaxHeight

HEIGHTTYPE cLightingThread::m_MaxHeight
protected

The highest block in the current 3x3 chunk data.

Definition at line 110 of file LightingThread.h.

◆ m_NumSeeds

size_t cLightingThread::m_NumSeeds
protected

Definition at line 133 of file LightingThread.h.

◆ m_PendingQueue

cChunkStays cLightingThread::m_PendingQueue
protected

The ChunkStays that are waiting for load.

Used for stopping the thread.

Definition at line 104 of file LightingThread.h.

◆ m_Queue

cChunkStays cLightingThread::m_Queue
protected

The ChunkStays that are loaded and are waiting to be lit.

Definition at line 101 of file LightingThread.h.

◆ m_SeedIdx1

unsigned int cLightingThread::m_SeedIdx1[BlocksPerYLayer *cChunkDef::Height]
protected

Definition at line 130 of file LightingThread.h.

◆ m_SeedIdx2

unsigned int cLightingThread::m_SeedIdx2[BlocksPerYLayer *cChunkDef::Height]
protected

Definition at line 132 of file LightingThread.h.

◆ m_SkyLight

NIBBLETYPE cLightingThread::m_SkyLight[BlocksPerYLayer *cChunkDef::Height]
protected

Definition at line 121 of file LightingThread.h.

◆ m_World

cWorld& cLightingThread::m_World
protected

Definition at line 95 of file LightingThread.h.


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