21 Super(
"Chunk Generator"),
23 m_PluginInterface(nullptr),
49 LOGERROR(
"Generator could not start, aborting the server");
74 bool a_ForceRegeneration,
86 LOGWARN(
"WARNING: Adding chunk %s to generation queue; Queue is too big! (%zu)", a_Coords.
ToString().c_str(),
m_Queue.size());
88 m_Queue.emplace_back(a_Coords, a_ForceRegeneration, a_Callback);
146 return m_Generator->GetBiomeAt(a_BlockX, a_BlockZ);
157 int NumChunksGenerated = 0;
158 clock_t GenerationStart = clock();
159 clock_t LastReportTick = clock();
166 if ((NumChunksGenerated > 16) && (clock() - LastReportTick > CLOCKS_PER_SEC))
179 NumChunksGenerated = 0;
180 GenerationStart = clock();
181 LastReportTick = clock();
198 if ((NumChunksGenerated > 512) && (clock() - LastReportTick > 2 * CLOCKS_PER_SEC))
200 LOG(
"Chunk generator performance: %.2f ch / sec (%d ch total)",
201 static_cast<double>(NumChunksGenerated) * CLOCKS_PER_SEC / (clock() - GenerationStart),
204 LastReportTick = clock();
210 LOGD(
"Chunk %s already generated, skipping generation", item.m_Coords.ToString().c_str());
211 if (item.m_Callback !=
nullptr)
213 item.m_Callback->Call(item.m_Coords,
true);
221 LOGWARNING(
"Chunk generator overloaded, skipping chunk %s", item.m_Coords.ToString().c_str());
222 if (item.m_Callback !=
nullptr)
224 item.m_Callback->Call(item.m_Coords,
false);
231 if (item.m_Callback !=
nullptr)
233 item.m_Callback->Call(item.m_Coords,
true);
235 NumChunksGenerated++;
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
const size_t QUEUE_WARNING_LIMIT
If the generation queue size exceeds this number, a warning will be output.
const size_t QUEUE_SKIP_LIMIT
If the generation queue size exceeds this number, chunks with no clients will be skipped.
void LOGERROR(std::string_view a_Format, const Args &... args)
void LOGWARNING(std::string_view a_Format, const Args &... args)
void LOG(std::string_view a_Format, const Args &... args)
Wraps the chunk coords into a single structure.
AString ToString() const
Returns a string that describes the chunk coords, suitable for logging.
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Interface class used as a callback for operations that involve chunk coords.
cEvent m_evtRemoved
Set when an item is removed from the queue.
size_t GetQueueLength() const
Queue m_Queue
Queue of the chunks to be generated.
cEvent m_Event
Set when an item is added to the queue or the thread should terminate.
virtual void Execute(void) override
This function, overloaded by the descendants, is called in the new thread.
bool Initialize(cPluginInterface &a_PluginInterface, cChunkSink &a_ChunkSink, cIniFile &a_IniFile)
Read settings from the ini file and initialize in preperation for being started.
cChunkSink * m_ChunkSink
The destination where the generated chunks are sent.
cCriticalSection m_CS
CS protecting access to the queue.
cChunkGeneratorThread(void)
EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ)
Returns the biome at the specified coords.
void DoGenerate(cChunkCoords a_Coords)
Generates the specified chunk and sets it into the chunksink.
void GenerateBiomes(cChunkCoords a_Coords, cChunkDef::BiomeMap &a_BiomeMap)
Generates the biomes for the specified chunk (directly, not in a separate thread).
std::unique_ptr< cChunkGenerator > m_Generator
The actual chunk generator engine used.
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 ...
cPluginInterface * m_PluginInterface
The plugin interface that may modify the generated chunks.
virtual ~cChunkGeneratorThread() override
The interface through which the plugins are called for their OnChunkGenerating / OnChunkGenerated hoo...
virtual void CallHookChunkGenerated(cChunkDesc &a_ChunkDesc)=0
Called after the chunk is generated, before it is handed to the chunk sink.
virtual void CallHookChunkGenerating(cChunkDesc &a_ChunkDesc)=0
Called when the chunk is about to be generated.
The interface through which the generated chunks are handed to the cWorld or whoever created us.
virtual bool HasChunkAnyClients(cChunkCoords a_Coords)=0
Called when the generator is overloaded to skip chunks that are no longer needed.
virtual bool IsChunkValid(cChunkCoords a_Coords)=0
Called just before the chunk generation is started, to verify that it hasn't been generated in the me...
virtual void OnChunkGenerated(cChunkDesc &a_ChunkDesc)=0
Called after the chunk has been generated The interface may store the chunk, send it over network,...
virtual bool IsChunkQueued(cChunkCoords a_Coords)=0
Called to check whether the specified chunk is in the queued state.
void VerifyHeightmap(void)
Verifies that the heightmap corresponds to blocktype contents; if not, asserts on that column.
static std::unique_ptr< cChunkGenerator > CreateFromIniFile(cIniFile &a_IniFile)
Creates and initializes the entire generator based on the settings in the INI file.
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.