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 
18 
19 
20 
21 
22 // fwd:
23 class cWorld;
24 
26 
27 
28 
29 
30 
32 class cWSSchema abstract
33 {
34 public:
35  cWSSchema(cWorld * a_World) : m_World(a_World) {}
36  virtual ~cWSSchema() {} // Force the descendants' destructors to be virtual
37 
38  virtual bool LoadChunk(const cChunkCoords & a_Chunk) = 0;
39  virtual bool SaveChunk(const cChunkCoords & a_Chunk) = 0;
40  virtual const AString GetName(void) const = 0;
41 
42 protected:
43 
44  cWorld * m_World;
45 } ;
46 
47 typedef std::list<cWSSchema *> cWSSchemaList;
48 
49 
50 
51 
52 
55  public cIsThread
56 {
57  typedef cIsThread super;
58 
59 public:
60 
61  cWorldStorage(void);
62  virtual ~cWorldStorage() override;
63 
66  void QueueLoadChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback = nullptr);
67 
70  void QueueSaveChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback = nullptr);
71 
73  void Initialize(cWorld & a_World, const AString & a_StorageSchemaName, int a_StorageCompressionFactor);
74  void Stop(void); // Hide the cIsThread's Stop() method, we need to signal the event
75  void WaitForFinish(void);
76  void WaitForLoadQueueEmpty(void);
77  void WaitForSaveQueueEmpty(void);
78 
79  size_t GetLoadQueueLength(void);
80  size_t GetSaveQueueLength(void);
81 
82 protected:
83 
86 
89 
92 
94  cWSSchema * m_SaveSchema;
95 
98 
99 
101  bool LoadChunk(int a_ChunkX, int a_ChunkZ);
102 
103  void InitSchemas(int a_StorageCompressionFactor);
104 
105  virtual void Execute(void) override;
106 
108  bool LoadOneChunk(void);
109 
111  bool SaveOneChunk(void);
112 } ;
113 
114 
115 
116 
cWSSchema * m_SaveSchema
The one storage schema used for saving.
Definition: WorldStorage.h:94
cWSSchemaList m_Schemas
All the storage schemas (all used for loading)
Definition: WorldStorage.h:91
cChunkCoordsQueue m_LoadQueue
Definition: WorldStorage.h:87
cChunkCoordsQueue m_SaveQueue
Definition: WorldStorage.h:88
Definition: Event.h:17
cQueue< cChunkCoordsWithCallback > cChunkCoordsQueue
Definition: WorldStorage.h:23
Definition: World.h:65
cEvent m_Event
Set when there&#39;s any addition to the queues.
Definition: WorldStorage.h:97
cWorld * m_World
Definition: WorldStorage.h:84
std::string AString
Definition: StringUtils.h:13
Interface class used as a callback for operations that involve chunk coords.
Definition: ChunkDef.h:610
std::list< cWSSchema * > cWSSchemaList
Definition: WorldStorage.h:47
AString m_StorageSchemaName
Definition: WorldStorage.h:85
cIsThread super
Definition: WorldStorage.h:57
The actual world storage class.
Definition: WorldStorage.h:54