Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
cChunkStay Class Referenceabstract

Makes chunks stay loaded until this object is cleared or destroyed Works by setting internal flags in the cChunk that it should not be unloaded. More...

#include <ChunkStay.h>

Inheritance diagram for cChunkStay:
Inheritance graph
[legend]
Collaboration diagram for cChunkStay:
Collaboration graph
[legend]

Public Member Functions

void Add (int a_ChunkX, int a_ChunkZ)
 Adds a chunk to be locked from unloading. More...
 
 cChunkStay (void)
 
void Clear (void)
 Clears all the chunks that have been added. More...
 
virtual void Disable (void)
 Disables the ChunkStay, the chunks are released and the ChunkStay object can be edited with Add() and Remove() again. More...
 
void Enable (cChunkMap &a_ChunkMap)
 Enables the ChunkStay on the specified chunkmap, causing it to load and generate chunks. More...
 
const cChunkCoordsVectorGetChunks (void) const
 Returns all the chunks that should be kept. More...
 
virtual bool OnAllChunksAvailable (void)=0
 Called once all of the contained chunks are available. More...
 
virtual void OnChunkAvailable (int a_ChunkX, int a_ChunkZ)=0
 Called when a specific chunk become available. More...
 
virtual void OnDisabled (void)=0
 Called by the ChunkMap when the ChunkStay is disabled. More...
 
void Remove (int a_ChunkX, int a_ChunkZ)
 Releases the chunk so that it's no longer locked from unloading. More...
 
virtual ~cChunkStay ()
 Deletes the object. More...
 

Protected Member Functions

bool ChunkAvailable (int a_ChunkX, int a_ChunkZ)
 Called by cChunkMap when a chunk is available, checks m_NumLoaded and triggers the appropriate callbacks. More...
 

Protected Attributes

cChunkMapm_ChunkMap
 The chunkmap where the object is enabled. More...
 
cChunkCoordsVector m_Chunks
 The list of chunks to lock from unloading. More...
 
cChunkCoordsVector m_OutstandingChunks
 The chunks that still need loading. More...
 

Friends

class cChunkMap
 

Detailed Description

Makes chunks stay loaded until this object is cleared or destroyed Works by setting internal flags in the cChunk that it should not be unloaded.

To optimize for speed, cChunkStay has an Enabled flag, it will "stay" the chunks only when enabled and it will refuse chunk-list manipulations when enabled. The object itself is not made thread-safe, it's supposed to be used from a single thread only. This class is abstract, the descendants are expected to provide the OnChunkAvailable() and the OnAllChunksAvailable() callback implementations. Note that those are called from the contexts of different threads' - the caller, the Loader or the Generator thread.

Definition at line 35 of file ChunkStay.h.

Constructor & Destructor Documentation

◆ cChunkStay()

cChunkStay::cChunkStay ( void  )

Definition at line 14 of file ChunkStay.cpp.

◆ ~cChunkStay()

cChunkStay::~cChunkStay ( )
virtual

Deletes the object.

Note that this calls Clear(), which means that the ChunkStay needs to be disabled.

Definition at line 23 of file ChunkStay.cpp.

Member Function Documentation

◆ Add()

void cChunkStay::Add ( int  a_ChunkX,
int  a_ChunkZ 
)

Adds a chunk to be locked from unloading.

To be used only while the ChunkStay object is not enabled.

Definition at line 42 of file ChunkStay.cpp.

◆ ChunkAvailable()

bool cChunkStay::ChunkAvailable ( int  a_ChunkX,
int  a_ChunkZ 
)
protected

Called by cChunkMap when a chunk is available, checks m_NumLoaded and triggers the appropriate callbacks.

May be called for chunks outside this ChunkStay. Returns true if the ChunkStay is to be automatically disabled by the ChunkMap; returns false to keep the ChunkStay.

Definition at line 106 of file ChunkStay.cpp.

◆ Clear()

void cChunkStay::Clear ( void  )

Clears all the chunks that have been added.

To be used only while the ChunkStay object is not enabled.

Definition at line 32 of file ChunkStay.cpp.

◆ Disable()

void cChunkStay::Disable ( void  )
virtual

Disables the ChunkStay, the chunks are released and the ChunkStay object can be edited with Add() and Remove() again.

Definition at line 93 of file ChunkStay.cpp.

◆ Enable()

void cChunkStay::Enable ( cChunkMap a_ChunkMap)

Enables the ChunkStay on the specified chunkmap, causing it to load and generate chunks.

All the contained chunks are queued for loading / generating.

Definition at line 80 of file ChunkStay.cpp.

◆ GetChunks()

const cChunkCoordsVector& cChunkStay::GetChunks ( void  ) const
inline

Returns all the chunks that should be kept.

Definition at line 63 of file ChunkStay.h.

◆ OnAllChunksAvailable()

virtual bool cChunkStay::OnAllChunksAvailable ( void  )
pure virtual

Called once all of the contained chunks are available.

If returns true, the ChunkStay is automatically disabled by the ChunkMap; if it returns false, the ChunkStay is kept.

Implemented in cNetherPortalScanner, cLightingThread::cLightingChunkStay, and cLuaChunkStay.

◆ OnChunkAvailable()

virtual void cChunkStay::OnChunkAvailable ( int  a_ChunkX,
int  a_ChunkZ 
)
pure virtual

Called when a specific chunk become available.

Implemented in cLightingThread::cLightingChunkStay, cLuaChunkStay, and cNetherPortalScanner.

◆ OnDisabled()

virtual void cChunkStay::OnDisabled ( void  )
pure virtual

Called by the ChunkMap when the ChunkStay is disabled.

The object may choose to delete itself.

Implemented in cNetherPortalScanner, cLightingThread::cLightingChunkStay, and cLuaChunkStay.

◆ Remove()

void cChunkStay::Remove ( int  a_ChunkX,
int  a_ChunkZ 
)

Releases the chunk so that it's no longer locked from unloading.

To be used only while the ChunkStay object is not enabled.

Definition at line 61 of file ChunkStay.cpp.

Friends And Related Function Documentation

◆ cChunkMap

friend class cChunkMap
friend

Definition at line 77 of file ChunkStay.h.

Member Data Documentation

◆ m_ChunkMap

cChunkMap* cChunkStay::m_ChunkMap
protected

The chunkmap where the object is enabled.

Valid only after call to Enable() and before Disable().

Definition at line 82 of file ChunkStay.h.

◆ m_Chunks

cChunkCoordsVector cChunkStay::m_Chunks
protected

The list of chunks to lock from unloading.

Definition at line 85 of file ChunkStay.h.

◆ m_OutstandingChunks

cChunkCoordsVector cChunkStay::m_OutstandingChunks
protected

The chunks that still need loading.

Definition at line 88 of file ChunkStay.h.


The documentation for this class was generated from the following files: