Cuberite
A lightweight, fast and extensible game server for Minecraft
ChunkStay.h
Go to the documentation of this file.
1 
2 // ChunkStay.h
3 
4 /* Declares the cChunkStay class representing a base for classes that want to wait for certain chunks to load,
5 then do some action on them. While the object is enabled, the chunks contained within are locked and will
6 not unload
7 */
8 
9 
10 
11 
12 
13 #pragma once
14 
15 #include "ChunkDef.h"
16 
17 
18 
19 // fwd
20 class cChunkMap;
21 
22 
23 
24 
25 
36 {
37 public:
38  cChunkStay(void);
39 
41  virtual ~cChunkStay();
42 
45  void Clear(void);
46 
49  void Add(int a_ChunkX, int a_ChunkZ);
50 
53  void Remove(int a_ChunkX, int a_ChunkZ);
54 
57  void Enable (cChunkMap & a_ChunkMap);
58 
60  virtual void Disable(void);
61 
63  const cChunkCoordsVector & GetChunks(void) const { return m_Chunks; }
64 
66  virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) = 0;
67 
70  virtual bool OnAllChunksAvailable(void) = 0;
71 
73  virtual void OnDisabled(void) = 0;
74 
75 protected:
76 
77  friend class cChunkMap;
78 
79 
83 
86 
89 
90 
94  bool ChunkAvailable(int a_ChunkX, int a_ChunkZ);
95 } ;
96 
97 
98 
99 
100 
std::vector< cChunkCoords > cChunkCoordsVector
Definition: ChunkDef.h:444
Makes chunks stay loaded until this object is cleared or destroyed Works by setting internal flags in...
Definition: ChunkStay.h:36
virtual void Disable(void)
Disables the ChunkStay, the chunks are released and the ChunkStay object can be edited with Add() and...
Definition: ChunkStay.cpp:93
void Clear(void)
Clears all the chunks that have been added.
Definition: ChunkStay.cpp:32
virtual bool OnAllChunksAvailable(void)=0
Called once all of the contained chunks are available.
void Remove(int a_ChunkX, int a_ChunkZ)
Releases the chunk so that it's no longer locked from unloading.
Definition: ChunkStay.cpp:61
void Add(int a_ChunkX, int a_ChunkZ)
Adds a chunk to be locked from unloading.
Definition: ChunkStay.cpp:42
void Enable(cChunkMap &a_ChunkMap)
Enables the ChunkStay on the specified chunkmap, causing it to load and generate chunks.
Definition: ChunkStay.cpp:80
bool ChunkAvailable(int a_ChunkX, int a_ChunkZ)
Called by cChunkMap when a chunk is available, checks m_NumLoaded and triggers the appropriate callba...
Definition: ChunkStay.cpp:106
cChunkStay(void)
Definition: ChunkStay.cpp:14
cChunkCoordsVector m_Chunks
The list of chunks to lock from unloading.
Definition: ChunkStay.h:85
virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ)=0
Called when a specific chunk become available.
virtual void OnDisabled(void)=0
Called by the ChunkMap when the ChunkStay is disabled.
cChunkMap * m_ChunkMap
The chunkmap where the object is enabled.
Definition: ChunkStay.h:82
const cChunkCoordsVector & GetChunks(void) const
Returns all the chunks that should be kept.
Definition: ChunkStay.h:63
virtual ~cChunkStay()
Deletes the object.
Definition: ChunkStay.cpp:23
cChunkCoordsVector m_OutstandingChunks
The chunks that still need loading.
Definition: ChunkStay.h:88