18 public cChunkDataCallback
26 const auto Section = a_BlockData.
GetSection(i);
27 if (Section ==
nullptr)
55 const ROW * InputRows =
reinterpret_cast<const ROW *
>(a_Heightmap);
56 ROW * OutputRows =
reinterpret_cast<ROW *
>(
m_HeightMap);
61 OutputRows[OutputIdx] = InputRows[InputIdx++];
67 for (
size_t i = 0; i <
ARRAYCOUNT(a_Heightmap); i++)
69 if (a_Heightmap[i] > MaxHeight)
71 MaxHeight = a_Heightmap[i];
103 Super(
"Lighting Executor"),
133 for (cChunkStays::iterator itr =
m_Queue.begin(), end =
m_Queue.end(); itr != end; ++itr)
334 for (
int z = 0; z < 3; z++)
337 for (
int x = 0; x < 3; x++)
389 int MaxNeighbor = std::max(std::max(Neighbor1, Neighbor2), std::max(Neighbor3, Neighbor4));
450 size_t NumSeeds2 = 0;
475 size_t a_NumSeedsIn,
unsigned char * a_IsSeedIn,
unsigned int * a_SeedIdxIn,
476 size_t & a_NumSeedsOut,
unsigned char * a_IsSeedOut,
unsigned int * a_SeedIdxOut
480 size_t NumSeedsOut = 0;
481 for (
size_t i = 0; i < a_NumSeedsIn; i++)
490 PropagateLight(a_Light, SeedIdx, SeedIdx + 1, NumSeedsOut, a_IsSeedOut, a_SeedIdxOut);
494 PropagateLight(a_Light, SeedIdx, SeedIdx - 1, NumSeedsOut, a_IsSeedOut, a_SeedIdxOut);
513 a_NumSeedsOut = NumSeedsOut;
530 a_ChunkLight[OutIdx++] =
static_cast<NIBBLETYPE>(a_LightArray[InIdx + 1] << 4) | a_LightArray[InIdx];
547 unsigned int a_SrcIdx,
unsigned int a_DstIdx,
548 size_t & a_NumSeedsOut,
unsigned char * a_IsSeedOut,
unsigned int * a_SeedIdxOut
561 if (!a_IsSeedOut[a_DstIdx])
563 a_IsSeedOut[a_DstIdx] =
true;
564 a_SeedIdxOut[a_NumSeedsOut++] = a_DstIdx;
578 m_Queue.push_back(&a_ChunkStay);
591 m_LightingThread(a_LightingThread),
594 m_CallbackAfter(
std::move(a_CallbackAfter))
596 Add(a_ChunkX + 1, a_ChunkZ + 1);
597 Add(a_ChunkX + 1, a_ChunkZ);
598 Add(a_ChunkX + 1, a_ChunkZ - 1);
599 Add(a_ChunkX, a_ChunkZ + 1);
600 Add(a_ChunkX, a_ChunkZ);
601 Add(a_ChunkX, a_ChunkZ - 1);
602 Add(a_ChunkX - 1, a_ChunkZ + 1);
603 Add(a_ChunkX - 1, a_ChunkZ);
604 Add(a_ChunkX - 1, a_ChunkZ - 1);
613 m_LightingThread.QueueChunkStay(*
this);
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char HEIGHTTYPE
The type used by the heightmap.
unsigned char BLOCKTYPE
The datatype used by blockdata.
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
static NIBBLETYPE GetSpreadLightFalloff(BLOCKTYPE Block)
How much light do the blocks consume?
static NIBBLETYPE GetLightValue(BLOCKTYPE Block)
How much light do the blocks emit on their own?
static bool IsTransparent(BLOCKTYPE Block)
Is a block transparent? (https://minecraft.wiki/w/Opacity)
static bool IsSkylightDispersant(BLOCKTYPE Block)
Does this block disperse sky light? (only relevant for transparent blocks)
BlockArray * GetSection(size_t a_Y) const
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
static const size_t NumSections
static const int SectionHeight
static const int NumBlocks
Makes chunks stay loaded until this object is cleared or destroyed Works by setting internal flags in...
void Add(int a_ChunkX, int a_ChunkZ)
Adds a chunk to be locked from unloading.
void Enable(cChunkMap &a_ChunkMap)
Enables the ChunkStay on the specified chunkmap, causing it to load and generate chunks.
Chunk data callback that takes the chunk data and puts them into cLightingThread's m_BlockTypes[] / m...
virtual void ChunkData(const ChunkBlockData &a_BlockData, const ChunkLightData &) override
cReader(BLOCKTYPE *a_BlockTypes, HEIGHTTYPE *a_HeightMap)
virtual void HeightMap(const cChunkDef::HeightMap &a_Heightmap) override
HEIGHTTYPE m_MaxHeight
The highest block in the current 3x3 chunk data.
void CalcLight(NIBBLETYPE *a_Light)
Calculates light in the light array specified, using stored seeds.
void ReadChunks(int a_ChunkX, int a_ChunkZ)
Prepares m_BlockTypes and m_HeightMap data; zeroes out the light arrays.
virtual ~cLightingThread() override
virtual void Execute(void) override
This function, overloaded by the descendants, is called in the new thread.
cChunkStays m_Queue
The ChunkStays that are loaded and are waiting to be lit.
unsigned int m_SeedIdx2[BlocksPerYLayer *cChunkDef::Height]
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)
unsigned char m_IsSeed1[BlocksPerYLayer *cChunkDef::Height]
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.
unsigned int m_SeedIdx1[BlocksPerYLayer *cChunkDef::Height]
cChunkStays m_PendingQueue
The ChunkStays that are waiting for load.
void LightChunk(cLightingChunkStay &a_Item)
Lights the entire chunk.
void PrepareSkyLight(void)
Uses m_HeightMap to initialize the m_SkyLight[] data; fills in seeds for the skylight.
NIBBLETYPE m_SkyLight[BlocksPerYLayer *cChunkDef::Height]
void CompressLight(NIBBLETYPE *a_LightArray, NIBBLETYPE *a_ChunkLight)
Compresses from 1-block-per-byte (faster calc) into 2-blocks-per-byte (MC storage):
void WaitForQueueEmpty(void)
Blocks until the queue is empty or the thread is terminated.
size_t GetQueueLength(void)
void QueueChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_CallbackAfter)
Queues the entire chunk for lighting.
cCriticalSection m_CS
The mutex to protect m_Queue and m_PendingQueue.
NIBBLETYPE m_BlockLight[BlocksPerYLayer *cChunkDef::Height]
HEIGHTTYPE m_HeightMap[BlocksPerYLayer]
unsigned char m_IsSeed2[BlocksPerYLayer *cChunkDef::Height]
BLOCKTYPE m_BlockTypes[BlocksPerYLayer *cChunkDef::Height]
void QueueChunkStay(cLightingChunkStay &a_ChunkStay)
Queues a chunkstay that has all of its chunks loaded.
cLightingThread(cWorld &a_World)
static const int BlocksPerYLayer
void PrepareBlockLight(void)
Uses m_BlockTypes to initialize the m_BlockLight[] data; fills in seeds for the blocklight.
virtual void OnDisabled(void) override
Called by the ChunkMap when the ChunkStay is disabled.
cLightingChunkStay(cLightingThread &a_LightingThread, int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_CallbackAfter)
virtual bool OnAllChunksAvailable(void) override
Called once all of the contained chunks are available.
std::unique_ptr< cChunkCoordCallback > m_CallbackAfter
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
Temporary RAII unlock for a cCSLock.
void Wait(void)
Waits until the event has been set.
void Set(void)
Sets the event - releases one thread that has been waiting in Wait().
std::atomic< bool > m_ShouldTerminate
The overriden Execute() method should check this value periodically and terminate if this is true.
void Stop(void)
Signals the thread to terminate and waits until it's finished.
bool GetChunkData(cChunkCoords a_Coords, cChunkDataCallback &a_Callback) const
Calls the callback with the chunk's data, if available (with ChunkCS locked).
void ChunkLighted(int a_ChunkX, int a_ChunkZ, const cChunkDef::BlockNibbles &a_BlockLight, const cChunkDef::BlockNibbles &a_SkyLight)
cChunkMap * GetChunkMap(void)
bool IsChunkLighted(int a_ChunkX, int a_ChunkZ)