12 #include "../Generating/ChunkGenerator.h"
13 #include "../Entities/Entity.h"
14 #include "../BlockEntities/BlockEntity.h"
41 Super(
"World Storage Executor"),
85 LOGD(
"Waiting for the world storage to finish saving");
98 LOGD(
"World storage thread finished");
143 ASSERT((a_ChunkX > -0x08000000) && (a_ChunkX < 0x08000000));
144 ASSERT((a_ChunkZ > -0x08000000) && (a_ChunkZ < 0x08000000));
189 LOGWARNING(
"Unknown storage schema name \"%s\". Using default (\"%s\"). Available schemas:",
194 LOGWARNING(
"\t\"%s\"", (*itr)->GetName().c_str());
289 if (((*itr) !=
m_SaveSchema) && (*itr)->LoadChunk(Coords))
void LOGWARNING(std::string_view a_Format, const Args &... args)
int NoCaseCompare(const AString &s1, const AString &s2)
Case-insensitive string comparison.
Wraps the chunk coords into a single structure.
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.
size_t Size(void)
Returns the size at time of being called.
void EnqueueItem(ItemType a_Item)
Enqueues an item to the queue, may block if other threads are accessing the queue.
void Clear(void)
Removes all Items from the Queue, calling Delete on each of them.
void BlockTillEmpty(void)
Blocks until the queue is empty.
bool TryDequeueItem(ItemType &item)
Dequeues an item from the queue if any are present.
void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ)
Marks the chunk as failed-to-load:
void MarkChunkSaved(int a_ChunkX, int a_ChunkZ)
bool IsChunkValid(int a_ChunkX, int a_ChunkZ) const
Returns true iff the chunk is present and valid.
bool IsChunkQueued(int a_ChunkX, int a_ChunkZ) const
Returns true iff the chunk is in the loader / generator queue.
void MarkChunkSaving(int a_ChunkX, int a_ChunkZ)
Example storage schema - forgets all chunks.
virtual bool SaveChunk(const cChunkCoords &a_Chunk) override
cWSSForgetful(cWorld *a_World)
virtual bool LoadChunk(const cChunkCoords &a_Chunk) override
virtual const AString GetName(void) const override
bool LoadChunk(int a_ChunkX, int a_ChunkZ)
Loads the chunk specified; returns true on success, false on failure.
bool LoadOneChunk(void)
Loads one chunk from the queue (if any queued); returns true if there was a chunk in the queue to loa...
virtual ~cWorldStorage() override
void Initialize(cWorld &a_World, const AString &a_StorageSchemaName, int a_StorageCompressionFactor)
Initializes the storage schemas, ready to be started.
cEvent m_Event
Set when there's any addition to the queues.
AString m_StorageSchemaName
size_t GetSaveQueueLength(void)
size_t GetLoadQueueLength(void)
virtual void Execute(void) override
This function, overloaded by the descendants, is called in the new thread.
void WaitForSaveQueueEmpty(void)
bool SaveOneChunk(void)
Saves one chunk from the queue (if any queued); returns true if there was a chunk in the queue to sav...
void QueueLoadChunk(int a_ChunkX, int a_ChunkZ)
Queues a chunk to be loaded, asynchronously.
cQueue< cChunkCoords > m_LoadQueue
void InitSchemas(int a_StorageCompressionFactor)
void QueueSaveChunk(int a_ChunkX, int a_ChunkZ)
Queues a chunk to be saved, asynchronously.
void WaitForLoadQueueEmpty(void)
cQueue< cChunkCoords > m_SaveQueue
cWSSchema * m_SaveSchema
The one storage schema used for saving.
cWSSchemaList m_Schemas
All the storage schemas (all used for loading)
Implements the Anvil world storage schema.