summaryrefslogtreecommitdiffstats
path: root/src/ChunkMap.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ChunkMap.h')
-rw-r--r--src/ChunkMap.h134
1 files changed, 67 insertions, 67 deletions
diff --git a/src/ChunkMap.h b/src/ChunkMap.h
index 6b7df7610..ef9fe196b 100644
--- a/src/ChunkMap.h
+++ b/src/ChunkMap.h
@@ -96,14 +96,14 @@ public:
void BroadcastSpawnEntity(cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr);
void BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = nullptr);
void BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ);
-
+
/** Sends the block entity, if it is at the coords specified, to a_Client */
void SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client);
-
+
/** a_Player rclked block entity at the coords specified, handle it
returns true if the use was successful, return false to use the block as a "normal" block */
bool UseBlockEntity(cPlayer * a_Player, int a_X, int a_Y, int a_Z);
-
+
/** Calls the callback for the chunk specified, with ChunkMapCS locked; returns false if the chunk doesn't exist, otherwise returns the same value as the callback */
bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback & a_Callback);
@@ -120,25 +120,25 @@ public:
void MarkChunkDirty (int a_ChunkX, int a_ChunkZ, bool a_MarkRedstoneDirty = false);
void MarkChunkSaving (int a_ChunkX, int a_ChunkZ);
void MarkChunkSaved (int a_ChunkX, int a_ChunkZ);
-
+
/** Sets the chunk data as either loaded from the storage or generated.
BlockLight and BlockSkyLight are optional, if not present, chunk will be marked as unlighted.
If MarkDirty is set, the chunk is set as dirty (used after generating)
Modifies the BlockEntity list in a_SetChunkData - moves the block entities into the chunk.
*/
void SetChunkData(cSetChunkData & a_SetChunkData);
-
+
void ChunkLighted(
int a_ChunkX, int a_ChunkZ,
const cChunkDef::BlockNibbles & a_BlockLight,
const cChunkDef::BlockNibbles & a_SkyLight
);
-
+
bool GetChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataCallback & a_Callback);
-
+
/** Copies the chunk's blocktypes into a_Blocks; returns true if successful */
bool GetChunkBlockTypes (int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_Blocks);
-
+
/** Returns true iff the chunk is in the loader / generator queue. */
bool IsChunkQueued(int a_ChunkX, int a_ChunkZ);
@@ -154,7 +154,7 @@ public:
void SetBlocks(const sSetBlockVector & a_Blocks);
void CollectPickupsByPlayer(cPlayer & a_Player);
-
+
BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ);
NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ);
NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ);
@@ -166,21 +166,21 @@ public:
/** Replaces world blocks with a_Blocks, if they are of type a_FilterBlockType */
void ReplaceBlocks(const sSetBlockVector & a_Blocks, BLOCKTYPE a_FilterBlockType);
-
+
/** Special function used for growing trees, replaces only blocks that tree may overwrite */
void ReplaceTreeBlocks(const sSetBlockVector & a_Blocks);
-
+
/** Returns the biome at the specified coords. Reads the biome from the chunk, if loaded, otherwise uses the world generator to provide the biome value */
EMCSBiome GetBiomeAt (int a_BlockX, int a_BlockZ);
-
+
/** Sets the biome at the specified coords. Returns true if successful, false if not (chunk not loaded).
Doesn't resend the chunk to clients. */
bool SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome);
-
+
/** Sets the biome at the area. Returns true if successful, false if any subarea failed (chunk not loaded).
(Re)sends the chunks to their relevant clients if successful. */
bool SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome);
-
+
/** Retrieves block types and metas of the specified blocks.
If a chunk is not loaded, doesn't modify the block and consults a_ContinueOnFailure whether to process the rest of the array.
Returns true if all blocks were read, false if any one failed. */
@@ -195,10 +195,10 @@ public:
Uses a blockchange packet to send the block.
If the relevant chunk isn't loaded, doesn't do anything. */
void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer * a_Player);
-
+
/** Compares clients of two chunks, calls the callback accordingly */
void CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback);
-
+
/** Compares clients of two chunks, calls the callback accordingly */
void CompareChunkClients(cChunk * a_Chunk1, cChunk * a_Chunk2, cClientDiffCallback & a_Callback);
@@ -207,23 +207,23 @@ public:
/** Removes the client from the chunk */
void RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client);
-
+
/** Removes the client from all chunks it is present in */
void RemoveClientFromChunks(cClientHandle * a_Client);
/** Adds the entity to its appropriate chunk, takes ownership of the entity pointer */
void AddEntity(cEntity * a_Entity);
-
+
/** Adds the entity to its appropriate chunk, if the entity is not already added.
Takes ownership of the entity pointer */
void AddEntityIfNotPresent(cEntity * a_Entity);
-
+
/** Returns true if the entity with specified ID is present in the chunks */
bool HasEntity(UInt32 a_EntityID);
-
+
/** Removes the entity from its appropriate chunk */
void RemoveEntity(cEntity * a_Entity);
-
+
/** Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true */
bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible
@@ -237,7 +237,7 @@ public:
/** Destroys and returns a list of blocks destroyed in the explosion at the specified coordinates */
void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, cVector3iArray & a_BlockAffected);
-
+
/** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param.
Returns true if entity found and callback returned false. */
bool DoWithEntityByID(UInt32 a_EntityID, cEntityCallback & a_Callback); // Lua-accessible
@@ -269,7 +269,7 @@ public:
/** Calls the callback for each furnace in the specified chunk.
Returns true if all furnaces processed, false if the callback aborted by returning true. */
bool ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback & a_Callback); // Lua-accessible
-
+
/** Calls the callback for the block entity at the specified coords.
Returns false if there's no block entity at those coords, true if found. */
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible
@@ -337,39 +337,39 @@ public:
Returns true if successful, false if not (possibly an out-of-memory error).
If the return value is true, the callback was / will be called. */
bool GenerateChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallAfter = nullptr); // Lua-accessible
-
+
/** Marks the chunk as failed-to-load */
void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ);
-
+
/** Sets the sign text. Returns true if sign text changed. */
bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
-
+
/** Marks the chunk as being regenerated - all its clients want that chunk again (used by cWorld::RegenerateChunk()) */
void MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ);
-
+
bool IsChunkLighted(int a_ChunkX, int a_ChunkZ);
-
+
/** Calls the callback for each chunk in the coords specified (all cords are inclusive). Returns true if all chunks have been processed successfully */
bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback);
/** Calls the callback for each loaded chunk. Returns true if all chunks have been processed successfully */
bool ForEachLoadedChunk(std::function<bool(int, int)> a_Callback);
-
+
/** Writes the block area into the specified coords. Returns true if all chunks have been processed. Prefer cBlockArea::Write() instead. */
bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes);
/** Returns the number of valid chunks and the number of dirty chunks */
void GetChunkStats(int & a_NumChunksValid, int & a_NumChunksDirty);
-
+
/** Grows a melon or a pumpkin next to the block specified (assumed to be the stem) */
void GrowMelonPumpkin(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, MTRand & a_Rand);
-
+
/** Grows a sugarcane present at the block specified by the amount of blocks specified, up to the max height specified in the config */
void GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow);
-
+
/** Grows a cactus present at the block specified by the amount of blocks specified, up to the max height specified in the config */
void GrowCactus(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow);
-
+
/** Sets the blockticking to start at the specified block. Only one blocktick per chunk may be set, second call overwrites the first call */
void SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ);
@@ -380,7 +380,7 @@ public:
void SpawnMobs(cMobSpawner & a_MobSpawner);
void Tick(std::chrono::milliseconds a_Dt);
-
+
/** Ticks a single block. Used by cWorld::TickQueuedBlocks() to tick the queued blocks */
void TickBlock(int a_BlockX, int a_BlockY, int a_BlockZ);
@@ -390,15 +390,15 @@ public:
cWorld * GetWorld(void) { return m_World; }
int GetNumChunks(void);
-
+
void ChunkValidated(void); // Called by chunks that have become valid
-
+
/** Queues the specified block for ticking (block update) */
void QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ);
-
+
/** Returns the CS for locking the chunkmap; only cWorld::cLock may use this function! */
cCriticalSection & GetCS(void) { return m_CSLayers; }
-
+
/** Increments (a_AlwaysTicked == true) or decrements (false) the m_AlwaysTicked counter for the specified chunk.
If the m_AlwaysTicked counter is greater than zero, the chunk is ticked in the tick-thread regardless of
whether it has any clients or not.
@@ -410,10 +410,10 @@ private:
// The chunks can manipulate neighbors while in their Tick() method, using LockedGetBlock() and LockedSetBlock()
friend class cChunk;
-
+
// The chunkstay can (de-)register itself using AddChunkStay() and DelChunkStay()
friend class cChunkStay;
-
+
class cChunkLayer
{
@@ -427,30 +427,30 @@ private:
/** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */
cChunkPtr GetChunk( int a_ChunkX, int a_ChunkZ);
-
+
/** Returns the specified chunk, or nullptr if not created yet */
cChunk * FindChunk(int a_ChunkX, int a_ChunkZ);
-
+
int GetX(void) const {return m_LayerX; }
int GetZ(void) const {return m_LayerZ; }
-
+
int GetNumChunksLoaded(void) const ;
-
+
void GetChunkStats(int & a_NumChunksValid, int & a_NumChunksDirty) const;
-
+
void Save(void);
void UnloadUnusedChunks(void);
-
+
/** Collect a mob census, of all mobs, their megatype, their chunk and their distance o closest player */
void CollectMobCensus(cMobCensus & a_ToFill);
-
+
/** Try to Spawn Monsters inside all Chunks */
void SpawnMobs(cMobSpawner & a_MobSpawner);
void Tick(std::chrono::milliseconds a_Dt);
-
+
void RemoveClient(cClientHandle * a_Client);
-
+
/** Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true */
bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible
@@ -459,18 +459,18 @@ private:
/** Returns true if there is an entity with the specified ID within this layer's chunks */
bool HasEntity(UInt32 a_EntityID);
-
+
protected:
-
+
cChunkPtr m_Chunks[LAYER_SIZE * LAYER_SIZE];
int m_LayerX;
int m_LayerZ;
cChunkMap * m_Parent;
int m_NumChunksLoaded;
-
+
cAllocationPool<cChunkData::sChunkSection> & m_Pool;
};
-
+
class cStarvationCallbacks
: public cAllocationPool<cChunkData::sChunkSection>::cStarvationCallbacks
{
@@ -487,23 +487,23 @@ private:
LOG("Out of Memory");
}
};
-
+
typedef std::list<cChunkLayer *> cChunkLayerList;
-
+
typedef std::list<cChunkStay *> cChunkStays;
/** Finds the cChunkLayer object responsible for the specified chunk; returns nullptr if not found. Assumes m_CSLayers is locked. */
cChunkLayer * FindLayerForChunk(int a_ChunkX, int a_ChunkZ);
-
+
/** Returns the specified cChunkLayer object; returns nullptr if not found. Assumes m_CSLayers is locked. */
cChunkLayer * FindLayer(int a_LayerX, int a_LayerZ);
-
+
/** Returns the cChunkLayer object responsible for the specified chunk; creates it if not found. */
cChunkLayer * GetLayerForChunk (int a_ChunkX, int a_ChunkZ);
-
+
/** Returns the specified cChunkLayer object; creates it if not found. */
cChunkLayer * GetLayer(int a_LayerX, int a_LayerZ);
-
+
void RemoveLayer(cChunkLayer * a_Layer);
cCriticalSection m_CSLayers;
@@ -511,7 +511,7 @@ private:
cEvent m_evtChunkValid; // Set whenever any chunk becomes valid, via ChunkValidated()
cWorld * m_World;
-
+
/** The cChunkStay descendants that are currently enabled in this chunkmap */
cChunkStays m_ChunkStays;
@@ -520,33 +520,33 @@ private:
cChunkPtr GetChunk (int a_ChunkX, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid
cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate
cChunkPtr GetChunkNoLoad(int a_ChunkX, int a_ChunkZ); // Doesn't load, doesn't generate
-
+
/** Gets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */
bool LockedGetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta);
-
+
/** Gets a block type in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */
bool LockedGetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType);
-
+
/** Gets a block meta in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */
bool LockedGetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE & a_BlockMeta);
-
+
/** Sets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */
bool LockedSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
/** Fast-sets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */
bool LockedFastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
-
+
/** Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSLayers is locked. To be called only from cChunkMap. */
cChunk * FindChunk(int a_ChunkX, int a_ChunkZ);
/** Adds a new cChunkStay descendant to the internal list of ChunkStays; loads its chunks.
To be used only by cChunkStay; others should use cChunkStay::Enable() instead */
void AddChunkStay(cChunkStay & a_ChunkStay);
-
+
/** Removes the specified cChunkStay descendant from the internal list of ChunkStays.
To be used only by cChunkStay; others should use cChunkStay::Disable() instead */
void DelChunkStay(cChunkStay & a_ChunkStay);
-
+
};