blob: 52573caf0afa3ef06f430be5b310edbc2f933a65 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// WorldStorage.h
// Interfaces to the cWorldStorage class representing the chunk loading / saving thread
// This class decides which storage schema to use for saving; it queries all available schemas for loading
// Also declares the base class for all storage schemas, cWSSchema
#pragma once
#ifndef WORLDSTORAGE_H_INCLUDED
#define WORLDSTORAGE_H_INCLUDED
#include "cChunk.h"
#include "cIsThread.h"
/// Interface that all the world storage schemas need to implement
class cWSSchema ABSTRACT
{
public:
cWSSchema(cWorld * a_World) : m_World(a_World) {}
virtual ~cWSSchema() {} // Force the descendants' destructors to be virtual
virtual bool LoadChunk(const cChunkPtr & a_Chunk) = 0;
virtual bool SaveChunk(const cChunkPtr & a_Chunk) = 0;
virtual const AString GetName(void) const = 0;
protected:
cWorld * m_World;
} ;
typedef std::list<cWSSchema *> cWSSchemaList;
class cWorldStorage :
public cIsThread
{
typedef cIsThread super;
public:
cWorldStorage(void);
~cWorldStorage();
void QueueLoadChunk(cChunkPtr & a_Chunk); // Queues the chunk for loading; if not loaded, the chunk will be generated
void QueueSaveChunk(cChunkPtr & a_Chunk);
void UnqueueLoad(const cChunkPtr & a_Chunk);
void UnqueueSave(const cChunkPtr & a_Chunk);
bool Start(cWorld * a_World, const AString & a_StorageSchemaName); // Hide the cIsThread's Start() method, we need to provide args
void WaitForFinish(void);
protected:
cWorld * m_World;
AString m_StorageSchemaName;
cCriticalSection m_CSLoadQueue;
cChunkPtrList m_LoadQueue;
cCriticalSection m_CSSaveQueue;
cChunkPtrList m_SaveQueue;
cEvent m_Event; // Set when there's any addition to the queues
cWSSchemaList m_Schemas;
cWSSchema * m_SaveSchema;
void InitSchemas(void);
virtual void Execute(void) override;
bool LoadChunk(const cChunkPtr & a_Chunk);
} ;
#endif // WORLDSTORAGE_H_INCLUDED
|