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

Takes requests for generating chunks and processes them in a separate thread one by one. More...

#include <ChunkGeneratorThread.h>

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

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

cChunkSinkm_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< cChunkGeneratorm_Generator
 The actual chunk generator engine used. More...
 
cPluginInterfacem_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...
 

Detailed Description

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.

Member Typedef Documentation

◆ Queue

using cChunkGeneratorThread::Queue = std::list<QueueItem>
private

Definition at line 125 of file ChunkGeneratorThread.h.

◆ Super

Definition at line 27 of file ChunkGeneratorThread.h.

Constructor & Destructor Documentation

◆ cChunkGeneratorThread()

cChunkGeneratorThread::cChunkGeneratorThread ( void  )

Definition at line 20 of file ChunkGeneratorThread.cpp.

◆ ~cChunkGeneratorThread()

cChunkGeneratorThread::~cChunkGeneratorThread ( )
overridevirtual

Definition at line 32 of file ChunkGeneratorThread.cpp.

Member Function Documentation

◆ DoGenerate()

void cChunkGeneratorThread::DoGenerate ( cChunkCoords  a_Coords)
private

Generates the specified chunk and sets it into the chunksink.

Definition at line 243 of file ChunkGeneratorThread.cpp.

◆ Execute()

void cChunkGeneratorThread::Execute ( void  )
overrideprivatevirtual

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

Implements cIsThread.

Definition at line 153 of file ChunkGeneratorThread.cpp.

◆ GenerateBiomes()

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.

◆ GetBiomeAt()

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.

◆ GetQueueLength()

size_t cChunkGeneratorThread::GetQueueLength ( void  ) const

Definition at line 124 of file ChunkGeneratorThread.cpp.

◆ GetSeed()

int cChunkGeneratorThread::GetSeed ( ) const

Definition at line 134 of file ChunkGeneratorThread.cpp.

◆ Initialize()

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.

◆ QueueGenerateChunk()

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.

◆ Stop()

void cChunkGeneratorThread::Stop ( void  )

Definition at line 59 of file ChunkGeneratorThread.cpp.

◆ WaitForQueueEmpty()

void cChunkGeneratorThread::WaitForQueueEmpty ( void  )

Definition at line 110 of file ChunkGeneratorThread.cpp.

Member Data Documentation

◆ m_ChunkSink

cChunkSink* cChunkGeneratorThread::m_ChunkSink
private

The destination where the generated chunks are sent.

Definition at line 147 of file ChunkGeneratorThread.h.

◆ m_CS

cCriticalSection cChunkGeneratorThread::m_CS
mutableprivate

CS protecting access to the queue.

Definition at line 129 of file ChunkGeneratorThread.h.

◆ m_Event

cEvent cChunkGeneratorThread::m_Event
private

Set when an item is added to the queue or the thread should terminate.

Definition at line 135 of file ChunkGeneratorThread.h.

◆ m_evtRemoved

cEvent cChunkGeneratorThread::m_evtRemoved
private

Set when an item is removed from the queue.

Definition at line 138 of file ChunkGeneratorThread.h.

◆ m_Generator

std::unique_ptr<cChunkGenerator> cChunkGeneratorThread::m_Generator
private

The actual chunk generator engine used.

Definition at line 141 of file ChunkGeneratorThread.h.

◆ m_PluginInterface

cPluginInterface* cChunkGeneratorThread::m_PluginInterface
private

The plugin interface that may modify the generated chunks.

Definition at line 144 of file ChunkGeneratorThread.h.

◆ m_Queue

Queue cChunkGeneratorThread::m_Queue
private

Queue of the chunks to be generated.

Protected against multithreaded access by m_CS.

Definition at line 132 of file ChunkGeneratorThread.h.


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