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 (const AString &a_ThreadName)
 
bool IsCurrentThread (void) const
 Returns true if the thread calling this function is the thread contained within this object. More...
 
bool 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...
 
bool Wait (void)
 Waits for the thread to finish. 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 is the main thread entrypoint. 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

typedef cIsThread super
 

Detailed Description

Definition at line 48 of file LightingThread.h.

Member Typedef Documentation

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

Definition at line 92 of file LightingThread.h.

Definition at line 51 of file LightingThread.h.

Constructor & Destructor Documentation

cLightingThread::cLightingThread ( cWorld a_World)

Definition at line 101 of file LightingThread.cpp.

cLightingThread::~cLightingThread ( )
overridevirtual

Definition at line 113 of file LightingThread.cpp.

Member Function Documentation

void cLightingThread::CalcLight ( NIBBLETYPE a_Light)
protected

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

Definition at line 447 of file LightingThread.cpp.

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 472 of file LightingThread.cpp.

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 519 of file LightingThread.cpp.

void cLightingThread::Execute ( void  )
overrideprotectedvirtual

This is the main thread entrypoint.

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

Implements cIsThread.

Definition at line 189 of file LightingThread.cpp.

size_t cLightingThread::GetQueueLength ( void  )

Definition at line 179 of file LightingThread.cpp.

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 233 of file LightingThread.cpp.

void cLightingThread::PrepareBlockLight ( void  )
protected

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

Definition at line 418 of file LightingThread.cpp.

void cLightingThread::PrepareSkyLight ( void  )
protected

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

Definition at line 352 of file LightingThread.cpp.

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 
)
inlineprotected

Definition at line 162 of file LightingThread.h.

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 149 of file LightingThread.cpp.

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 544 of file LightingThread.cpp.

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 329 of file LightingThread.cpp.

void cLightingThread::Stop ( void  )

Definition at line 122 of file LightingThread.cpp.

void cLightingThread::WaitForQueueEmpty ( void  )

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

Definition at line 165 of file LightingThread.cpp.

Member Data Documentation

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

Definition at line 118 of file LightingThread.h.

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

Definition at line 120 of file LightingThread.h.

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

Definition at line 119 of file LightingThread.h.

cCriticalSection cLightingThread::m_CS
protected

The mutex to protect m_Queue and m_PendingQueue.

Definition at line 98 of file LightingThread.h.

cEvent cLightingThread::m_evtItemAdded
protected

Definition at line 106 of file LightingThread.h.

cEvent cLightingThread::m_evtQueueEmpty
protected

Definition at line 107 of file LightingThread.h.

HEIGHTTYPE cLightingThread::m_HeightMap[BlocksPerYLayer]
protected

Definition at line 122 of file LightingThread.h.

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

Definition at line 129 of file LightingThread.h.

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

Definition at line 131 of file LightingThread.h.

HEIGHTTYPE cLightingThread::m_MaxHeight
protected

The highest block in the current 3x3 chunk data.

Definition at line 110 of file LightingThread.h.

size_t cLightingThread::m_NumSeeds
protected

Definition at line 133 of file LightingThread.h.

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.

cChunkStays cLightingThread::m_Queue
protected

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

Definition at line 101 of file LightingThread.h.

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

Definition at line 130 of file LightingThread.h.

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

Definition at line 132 of file LightingThread.h.

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

Definition at line 121 of file LightingThread.h.

cWorld& cLightingThread::m_World
protected

Definition at line 95 of file LightingThread.h.


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