Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Takes requests for generating chunks and processes them in a separate thread one by one. More...
#include <ChunkGeneratorThread.h>
Classes | |
class | cChunkSink |
The interface through which the generated chunks are handed to the cWorld or whoever created us. More... | |
class | cPluginInterface |
The interface through which the plugins are called for their OnChunkGenerating / OnChunkGenerated hooks. More... | |
struct | QueueItem |
Public Member Functions | |
cChunkGeneratorThread (void) | |
void | GenerateBiomes (cChunkCoords a_Coords, cChunkDef::BiomeMap &a_BiomeMap) |
Generates the biomes for the specified chunk (directly, not in a separate thread). More... | |
EMCSBiome | GetBiomeAt (int a_BlockX, int a_BlockZ) |
Returns the biome at the specified coords. More... | |
size_t | GetQueueLength () const |
int | GetSeed () const |
bool | Initialize (cPluginInterface &a_PluginInterface, cChunkSink &a_ChunkSink, cIniFile &a_IniFile) |
Read settings from the ini file and initialize in preperation for being started. More... | |
void | QueueGenerateChunk (cChunkCoords a_Coords, bool a_ForceRegeneration, cChunkCoordCallback *a_Callback=nullptr) |
Queues the chunk for generation If a-ForceGenerate is set, the chunk is regenerated even if the data is already present in the chunksink. More... | |
void | Stop (void) |
void | WaitForQueueEmpty () |
virtual | ~cChunkGeneratorThread () 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 () |
Private Types | |
using | Queue = std::list< QueueItem > |
using | Super = cIsThread |
Private Member Functions | |
void | DoGenerate (cChunkCoords a_Coords) |
Generates the specified chunk and sets it into the chunksink. More... | |
virtual void | Execute (void) override |
This function, overloaded by the descendants, is called in the new thread. More... | |
Private Attributes | |
cChunkSink * | m_ChunkSink |
The destination where the generated chunks are sent. More... | |
cCriticalSection | m_CS |
CS protecting access to the queue. More... | |
cEvent | m_Event |
Set when an item is added to the queue or the thread should terminate. More... | |
cEvent | m_evtRemoved |
Set when an item is removed from the queue. More... | |
std::unique_ptr< cChunkGenerator > | m_Generator |
The actual chunk generator engine used. More... | |
cPluginInterface * | m_PluginInterface |
The plugin interface that may modify the generated chunks. More... | |
Queue | m_Queue |
Queue of the chunks to be generated. More... | |
Additional Inherited Members | |
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... | |
Takes requests for generating chunks and processes them in a separate thread one by one.
The requests are not added to the queue if there is already a request with the same coords. Before generating, the thread checks if the chunk hasn't been already generated. It is theoretically possible to have multiple generator threads by having multiple instances of this object, but then it MAY happen that the chunk is generated twice. If the generator queue is overloaded, the generator skips chunks with no clients in them.
Definition at line 24 of file ChunkGeneratorThread.h.
|
private |
Definition at line 125 of file ChunkGeneratorThread.h.
|
private |
Definition at line 27 of file ChunkGeneratorThread.h.
cChunkGeneratorThread::cChunkGeneratorThread | ( | void | ) |
Definition at line 20 of file ChunkGeneratorThread.cpp.
|
overridevirtual |
Definition at line 32 of file ChunkGeneratorThread.cpp.
|
private |
Generates the specified chunk and sets it into the chunksink.
Definition at line 243 of file ChunkGeneratorThread.cpp.
|
overrideprivatevirtual |
This function, overloaded by the descendants, is called in the new thread.
Implements cIsThread.
Definition at line 153 of file ChunkGeneratorThread.cpp.
void cChunkGeneratorThread::GenerateBiomes | ( | cChunkCoords | a_Coords, |
cChunkDef::BiomeMap & | a_BiomeMap | ||
) |
Generates the biomes for the specified chunk (directly, not in a separate thread).
Used by the world loader if biomes failed loading.
Definition at line 98 of file ChunkGeneratorThread.cpp.
EMCSBiome cChunkGeneratorThread::GetBiomeAt | ( | int | a_BlockX, |
int | a_BlockZ | ||
) |
Returns the biome at the specified coords.
Used by ChunkMap if an invalid chunk is queried for biome
Definition at line 143 of file ChunkGeneratorThread.cpp.
size_t cChunkGeneratorThread::GetQueueLength | ( | void | ) | const |
Definition at line 124 of file ChunkGeneratorThread.cpp.
int cChunkGeneratorThread::GetSeed | ( | ) | const |
Definition at line 134 of file ChunkGeneratorThread.cpp.
bool cChunkGeneratorThread::Initialize | ( | cPluginInterface & | a_PluginInterface, |
cChunkSink & | a_ChunkSink, | ||
cIniFile & | a_IniFile | ||
) |
Read settings from the ini file and initialize in preperation for being started.
Definition at line 41 of file ChunkGeneratorThread.cpp.
void cChunkGeneratorThread::QueueGenerateChunk | ( | cChunkCoords | a_Coords, |
bool | a_ForceRegeneration, | ||
cChunkCoordCallback * | a_Callback = nullptr |
||
) |
Queues the chunk for generation If a-ForceGenerate is set, the chunk is regenerated even if the data is already present in the chunksink.
a_Callback is called after the chunk is generated. If the chunk was already present, the callback is still called, even if not regenerating. It is legal to set the callback to nullptr, no callback is called then. If the generator becomes overloaded and skips this chunk, the callback is still called.
Definition at line 72 of file ChunkGeneratorThread.cpp.
void cChunkGeneratorThread::Stop | ( | void | ) |
Definition at line 59 of file ChunkGeneratorThread.cpp.
void cChunkGeneratorThread::WaitForQueueEmpty | ( | void | ) |
Definition at line 110 of file ChunkGeneratorThread.cpp.
|
private |
The destination where the generated chunks are sent.
Definition at line 147 of file ChunkGeneratorThread.h.
|
mutableprivate |
CS protecting access to the queue.
Definition at line 129 of file ChunkGeneratorThread.h.
|
private |
Set when an item is added to the queue or the thread should terminate.
Definition at line 135 of file ChunkGeneratorThread.h.
|
private |
Set when an item is removed from the queue.
Definition at line 138 of file ChunkGeneratorThread.h.
|
private |
The actual chunk generator engine used.
Definition at line 141 of file ChunkGeneratorThread.h.
|
private |
The plugin interface that may modify the generated chunks.
Definition at line 144 of file ChunkGeneratorThread.h.
|
private |
Queue of the chunks to be generated.
Protected against multithreaded access by m_CS.
Definition at line 132 of file ChunkGeneratorThread.h.