2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
// cChunkGenerator.h
|
|
|
|
|
|
|
|
// Interfaces to the cChunkGenerator class representing the thread that generates chunks
|
|
|
|
|
|
|
|
// The object 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 (if the cChunkPtr is thread-safe)
|
|
|
|
// If the generator queue is overloaded, the generator skips chunks with no clients in them
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-25 07:55:20 -05:00
|
|
|
#pragma once
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
#include "cIsThread.h"
|
|
|
|
#include "cChunk.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cWorld;
|
|
|
|
class cWorldGenerator;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cChunkGenerator :
|
|
|
|
cIsThread
|
2011-12-25 07:55:20 -05:00
|
|
|
{
|
2012-02-13 16:47:03 -05:00
|
|
|
typedef cIsThread super;
|
|
|
|
|
2011-12-25 07:55:20 -05:00
|
|
|
public:
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
cChunkGenerator (void);
|
2011-12-25 07:55:20 -05:00
|
|
|
~cChunkGenerator();
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
bool Start(cWorld * a_World, const AString & a_WorldGeneratorName);
|
|
|
|
void Stop(void);
|
|
|
|
|
2012-02-17 12:56:25 -05:00
|
|
|
void GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Queues the chunk for generation; removes duplicate requests
|
2012-02-18 12:53:22 -05:00
|
|
|
|
|
|
|
void WaitForQueueEmpty(void);
|
|
|
|
|
|
|
|
int GetQueueLength(void);
|
2011-12-25 07:55:20 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cWorld * m_World;
|
|
|
|
cWorldGenerator * m_pWorldGenerator;
|
|
|
|
|
|
|
|
cCriticalSection m_CS;
|
|
|
|
cChunkCoordsList m_Queue;
|
|
|
|
cEvent m_Event; // Set when an item is added to the queue or the thread should terminate
|
2012-02-18 12:53:22 -05:00
|
|
|
cEvent m_evtRemoved; // Set when an item is removed from the queue
|
2012-02-17 12:56:25 -05:00
|
|
|
|
|
|
|
// cIsThread override:
|
|
|
|
virtual void Execute(void) override;
|
|
|
|
|
|
|
|
void DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
|
2012-02-13 16:47:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-25 07:55:20 -05:00
|
|
|
|