Cuberite
A lightweight, fast and extensible game server for Minecraft
WorldStorage.h
Go to the documentation of this file.
1 
2 // WorldStorage.h
3 
4 // Interfaces to the cWorldStorage class representing the chunk loading / saving thread
5 // This class decides which storage schema to use for saving; it queries all available schemas for loading
6 // Also declares the base class for all storage schemas, cWSSchema
7 // Helper serialization class cJsonChunkSerializer is declared as well
8 
9 
10 
11 
12 
13 #pragma once
14 
15 #include "../OSSupport/IsThread.h"
16 #include "../OSSupport/Queue.h"
17 #include "ChunkDef.h"
18 
19 
20 
21 
22 // fwd:
23 class cWorld;
24 
25 
26 
27 
28 
30 class cWSSchema abstract
31 {
32 public:
33  cWSSchema(cWorld * a_World) : m_World(a_World) {}
34  virtual ~cWSSchema() {} // Force the descendants' destructors to be virtual
35 
36  virtual bool LoadChunk(const cChunkCoords & a_Chunk) = 0;
37  virtual bool SaveChunk(const cChunkCoords & a_Chunk) = 0;
38  virtual const AString GetName(void) const = 0;
39 
40 protected:
41 
42  cWorld * m_World;
43 } ;
44 
45 typedef std::list<cWSSchema *> cWSSchemaList;
46 
47 
48 
49 
50 
53  public cIsThread
54 {
55  using Super = cIsThread;
56 
57 public:
58 
59  cWorldStorage();
60  virtual ~cWorldStorage() override;
61 
63  void QueueLoadChunk(int a_ChunkX, int a_ChunkZ);
64 
66  void QueueSaveChunk(int a_ChunkX, int a_ChunkZ);
67 
69  void Initialize(cWorld & a_World, const AString & a_StorageSchemaName, int a_StorageCompressionFactor);
70  void Stop(void); // Hide the cIsThread's Stop() method, we need to signal the event
71  void WaitForFinish(void);
72  void WaitForLoadQueueEmpty(void);
73  void WaitForSaveQueueEmpty(void);
74 
75  size_t GetLoadQueueLength(void);
76  size_t GetSaveQueueLength(void);
77 
78 protected:
79 
82 
85 
88 
90  cWSSchema * m_SaveSchema;
91 
94 
95 
97  bool LoadChunk(int a_ChunkX, int a_ChunkZ);
98 
99  void InitSchemas(int a_StorageCompressionFactor);
100 
101  virtual void Execute(void) override;
102 
104  bool LoadOneChunk(void);
105 
107  bool SaveOneChunk(void);
108 } ;
109 
110 
111 
112 
cWorldStorage::Initialize
void Initialize(cWorld &a_World, const AString &a_StorageSchemaName, int a_StorageCompressionFactor)
Initializes the storage schemas, ready to be started.
Definition: WorldStorage.cpp:63
cWorldStorage::GetSaveQueueLength
size_t GetSaveQueueLength(void)
Definition: WorldStorage.cpp:132
cWSSchemaList
std::list< cWSSchema * > cWSSchemaList
Definition: WorldStorage.h:45
cWorldStorage::WaitForFinish
void WaitForFinish(void)
Definition: WorldStorage.cpp:83
cIsThread
Definition: IsThread.h:23
cWorldStorage::~cWorldStorage
virtual ~cWorldStorage() override
Definition: WorldStorage.cpp:51
cWorldStorage::WaitForLoadQueueEmpty
void WaitForLoadQueueEmpty(void)
Definition: WorldStorage.cpp:105
cWorldStorage::QueueSaveChunk
void QueueSaveChunk(int a_ChunkX, int a_ChunkZ)
Queues a chunk to be saved, asynchronously.
Definition: WorldStorage.cpp:155
cIsThread::cIsThread
cIsThread(AString &&a_ThreadName)
Definition: IsThread.cpp:16
cWorldStorage::m_Schemas
cWSSchemaList m_Schemas
All the storage schemas (all used for loading)
Definition: WorldStorage.h:87
cWorldStorage::Stop
void Stop(void)
Definition: WorldStorage.cpp:74
cWorld
Definition: World.h:47
cWorldStorage::InitSchemas
void InitSchemas(int a_StorageCompressionFactor)
Definition: WorldStorage.cpp:167
cEvent
Definition: Event.h:17
cWorldStorage::Execute
virtual void Execute(void) override
This function, overloaded by the descendants, is called in the new thread.
Definition: WorldStorage.cpp:203
cWorldStorage::m_Event
cEvent m_Event
Set when there's any addition to the queues.
Definition: WorldStorage.h:93
cWorldStorage::LoadOneChunk
bool LoadOneChunk(void)
Loads one chunk from the queue (if any queued); returns true if there was a chunk in the queue to loa...
Definition: WorldStorage.cpp:227
cWorldStorage::m_SaveQueue
cQueue< cChunkCoords > m_SaveQueue
Definition: WorldStorage.h:84
cWorldStorage
The actual world storage class.
Definition: WorldStorage.h:52
cWorldStorage::m_StorageSchemaName
AString m_StorageSchemaName
Definition: WorldStorage.h:81
cWorldStorage::m_World
cWorld * m_World
Definition: WorldStorage.h:80
cQueue< cChunkCoords >
cWorldStorage::m_LoadQueue
cQueue< cChunkCoords > m_LoadQueue
Definition: WorldStorage.h:83
cChunkCoords
Definition: ChunkDef.h:55
cWorldStorage::WaitForSaveQueueEmpty
void WaitForSaveQueueEmpty(void)
Definition: WorldStorage.cpp:114
cWorldStorage::GetLoadQueueLength
size_t GetLoadQueueLength(void)
Definition: WorldStorage.cpp:123
ChunkDef.h
cWorldStorage::SaveOneChunk
bool SaveOneChunk(void)
Saves one chunk from the queue (if any queued); returns true if there was a chunk in the queue to sav...
Definition: WorldStorage.cpp:247
cWorldStorage::QueueLoadChunk
void QueueLoadChunk(int a_ChunkX, int a_ChunkZ)
Queues a chunk to be loaded, asynchronously.
Definition: WorldStorage.cpp:141
AString
std::string AString
Definition: StringUtils.h:11
cWorldStorage::LoadChunk
bool LoadChunk(int a_ChunkX, int a_ChunkZ)
Loads the chunk specified; returns true on success, false on failure.
Definition: WorldStorage.cpp:274
cWorldStorage::m_SaveSchema
cWSSchema * m_SaveSchema
The one storage schema used for saving.
Definition: WorldStorage.h:90
cWorldStorage::cWorldStorage
cWorldStorage()
Definition: WorldStorage.cpp:40