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 
std::string AString
Definition: StringUtils.h:11
std::list< cWSSchema * > cWSSchemaList
Definition: WorldStorage.h:45
Wraps the chunk coords into a single structure.
Definition: ChunkDef.h:57
Definition: Event.h:18
cIsThread(AString &&a_ThreadName)
Definition: IsThread.cpp:16
Definition: World.h:53
The actual world storage class.
Definition: WorldStorage.h:54
bool LoadChunk(int a_ChunkX, int a_ChunkZ)
Loads the chunk specified; returns true on success, false on failure.
void WaitForFinish(void)
bool LoadOneChunk(void)
Loads one chunk from the queue (if any queued); returns true if there was a chunk in the queue to loa...
cWorld * m_World
Definition: WorldStorage.h:80
void Stop(void)
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.
Definition: WorldStorage.h:93
AString m_StorageSchemaName
Definition: WorldStorage.h:81
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
Definition: WorldStorage.h:83
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
Definition: WorldStorage.h:84
cWSSchema * m_SaveSchema
The one storage schema used for saving.
Definition: WorldStorage.h:90
cWSSchemaList m_Schemas
All the storage schemas (all used for loading)
Definition: WorldStorage.h:87