summaryrefslogtreecommitdiffstats
path: root/src/Chunk.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Chunk.h')
-rw-r--r--src/Chunk.h88
1 files changed, 64 insertions, 24 deletions
diff --git a/src/Chunk.h b/src/Chunk.h
index 7eee3999c..bc66b6528 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -9,7 +9,9 @@
#include "Simulator/SandSimulator.h"
#include "Simulator/IncrementalRedstoneSimulator.h"
+#include "Blocks/GetHandlerCompileTimeTemplate.h"
+#include "ChunkMap.h"
@@ -28,7 +30,11 @@ class cServer;
class MTRand;
class cPlayer;
class cChunkMap;
+class cBeaconEntity;
+class cBoundingBox;
class cChestEntity;
+class cCHunkDataCallback;
+class cCommandBlockEntity;
class cDispenserEntity;
class cFurnaceEntity;
class cNoteEntity;
@@ -42,9 +48,12 @@ class cBlockArea;
class cFluidSimulatorData;
class cMobCensus;
class cMobSpawner;
+class cRedstonePoweredEntity;
+class cSetChunkData;
typedef std::list<cClientHandle *> cClientHandleList;
typedef cItemCallback<cEntity> cEntityCallback;
+typedef cItemCallback<cBeaconEntity> cBeaconCallback;
typedef cItemCallback<cChestEntity> cChestCallback;
typedef cItemCallback<cDispenserEntity> cDispenserCallback;
typedef cItemCallback<cFurnaceEntity> cFurnaceCallback;
@@ -52,6 +61,7 @@ typedef cItemCallback<cNoteEntity> cNoteBlockCallback;
typedef cItemCallback<cCommandBlockEntity> cCommandBlockCallback;
typedef cItemCallback<cMobHeadEntity> cMobHeadCallback;
typedef cItemCallback<cFlowerPotEntity> cFlowerPotCallback;
+typedef cItemCallback<cRedstonePoweredEntity> cRedstonePoweredCallback;
@@ -62,8 +72,16 @@ class cChunk :
public cChunkDef // The inheritance is "misused" here only to inherit the functions and constants defined in cChunkDef
{
public:
+ /** Represents the presence state of the chunk */
+ enum ePresence
+ {
+ cpInvalid, /**< The chunk is not present at all and is not queued in the loader / generator */
+ cpQueued, /**< The chunk is not present, but is queued for loading / generation */
+ cpPresent, /**< The chunk is present */
+ };
+
cChunk(
- int a_ChunkX, int a_ChunkY, int a_ChunkZ, // Chunk coords
+ int a_ChunkX, int a_ChunkZ, // Chunk coords
cChunkMap * a_ChunkMap, cWorld * a_World, // Parent objects
cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, // Neighbor chunks
cAllocationPool<cChunkData::sChunkSection> & a_Pool
@@ -71,11 +89,25 @@ public:
cChunk(cChunk & other);
~cChunk();
- bool IsValid(void) const {return m_IsValid; } // Returns true if the chunk block data is valid (loaded / generated)
- void SetValid(void); // Also wakes up any calls to cChunkMap::GetHeight()
- void MarkRegenerating(void); // Marks all clients attached to this chunk as wanting this chunk
- bool IsDirty(void) const {return m_IsDirty; } // Returns true if the chunk has changed since it was last saved
- bool HasLoadFailed(void) const {return m_HasLoadFailed; } // Returns true if the chunk failed to load and hasn't been generated since then
+ /** Returns true iff the chunk block data is valid (loaded / generated) */
+ bool IsValid(void) const {return (m_Presence == cpPresent); }
+
+ /** Returns true iff the chunk is in the queue for loading / generating */
+ bool IsQueued(void) const {return (m_Presence == cpQueued); }
+
+ /** Sets the chunk's presence.
+ Wakes up any calls to cChunkMap::GetHeight() when setting to cpPresent. */
+ void SetPresence(ePresence a_Presence);
+
+ /** Called to indicate whether the chunk should be queued in the generator if it fails to load. Set by cChunkMap::GetChunk(). */
+ void SetShouldGenerateIfLoadFailed(bool a_ShouldGenerateIfLoadFailed);
+
+ /** Marks all clients attached to this chunk as wanting this chunk. Also sets presence to cpQueued. */
+ void MarkRegenerating(void);
+
+ /** Returns true iff the chunk has changed since it was last saved. */
+ bool IsDirty(void) const {return m_IsDirty; }
+
bool CanUnload(void);
bool IsLightValid(void) const {return m_IsLightValid; }
@@ -90,7 +122,10 @@ public:
void MarkSaving(void); // Marks the chunk as being saved.
void MarkSaved(void); // Marks the chunk as saved, if it didn't change from the last call to MarkSaving()
void MarkLoaded(void); // Marks the chunk as freshly loaded. Fails if the chunk is already valid
- void MarkLoadFailed(void); // Marks the chunk as failed to load. Ignored is the chunk is already valid
+
+ /** Marks the chunk as failed to load.
+ If m_ShouldGenerateIfLoadFailed is set, queues the chunk for generating. */
+ void MarkLoadFailed(void);
/** Gets all chunk data, calls the a_Callback's methods for each data type */
void GetAllData(cChunkDataCallback & a_Callback);
@@ -131,7 +166,6 @@ public:
void TickBlock(int a_RelX, int a_RelY, int a_RelZ);
int GetPosX(void) const { return m_PosX; }
- int GetPosY(void) const { return m_PosY; }
int GetPosZ(void) const { return m_PosZ; }
cWorld * GetWorld(void) const { return m_World; }
@@ -151,7 +185,7 @@ public:
void FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, bool a_SendToClients = true); // Doesn't force block updates on neighbors, use for simple changes such as grass growing etc.
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const;
- BLOCKTYPE GetBlock(Vector3i a_cords) const { return GetBlock(a_cords.x, a_cords.y, a_cords.z);}
+ BLOCKTYPE GetBlock(const Vector3i & a_RelCoords) const { return GetBlock(a_RelCoords.x, a_RelCoords.y, a_RelCoords.z); }
void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta);
void GetBlockInfo (int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight);
@@ -212,6 +246,10 @@ public:
/** Calls the callback for each entity; returns true if all entities processed, false if the callback aborted by returning true */
bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible
+ /** Calls the callback for each entity that has a nonempty intersection with the specified boundingbox.
+ Returns true if all entities processed, false if the callback aborted by returning true. */
+ bool ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback); // Lua-accessible
+
/** 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. */
bool DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult); // Lua-accessible
@@ -235,6 +273,11 @@ public:
/** 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
+
+ /** Calls the callback for the redstone powered entity at the specified coords; returns false if there's no redstone powered entity at those coords, true if found */
+ bool DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cRedstonePoweredCallback & a_Callback);
+ /** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
+ bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Lua-acessible
/** Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found */
bool DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Lua-acessible
@@ -289,7 +332,7 @@ public:
void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL);
- void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL);
+ void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount, cClientHandle * a_Exclude = NULL);
void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
void BroadcastSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL);
void BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL);
@@ -377,12 +420,8 @@ public:
cFluidSimulatorData * GetLavaSimulatorData (void) { return m_LavaSimulatorData; }
cSandSimulatorChunkData & GetSandSimulatorData (void) { return m_SandSimulatorData; }
- cRedstoneSimulatorChunkData * GetRedstoneSimulatorData(void) { return &m_RedstoneSimulatorData; }
- cRedstoneSimulatorChunkData * GetRedstoneSimulatorQueuedData(void) { return &m_RedstoneSimulatorQueuedData; }
- cIncrementalRedstoneSimulator::PoweredBlocksList * GetRedstoneSimulatorPoweredBlocksList(void) { return &m_RedstoneSimulatorPoweredBlocksList; }
- cIncrementalRedstoneSimulator::LinkedBlocksList * GetRedstoneSimulatorLinkedBlocksList(void) { return &m_RedstoneSimulatorLinkedBlocksList; }
- cIncrementalRedstoneSimulator::SimulatedPlayerToggleableList * GetRedstoneSimulatorSimulatedPlayerToggleableList(void) { return &m_RedstoneSimulatorSimulatedPlayerToggleableList; }
- cIncrementalRedstoneSimulator::RepeatersDelayList * GetRedstoneSimulatorRepeatersDelayList(void) { return &m_RedstoneSimulatorRepeatersDelayList; }
+ cRedstoneSimulatorChunkData * GetRedstoneSimulatorData(void) { return m_RedstoneSimulatorData; }
+ void SetRedstoneSimulatorData(cRedstoneSimulatorChunkData * a_Data) { m_RedstoneSimulatorData = a_Data; }
bool IsRedstoneDirty(void) const { return m_IsRedstoneDirty; }
void SetIsRedstoneDirty(bool a_Flag) { m_IsRedstoneDirty = a_Flag; }
@@ -421,7 +460,12 @@ private:
typedef std::vector<sSetBlockQueueItem> sSetBlockQueueVector;
- bool m_IsValid; // True if the chunk is loaded / generated
+ /** Holds the presence status of the chunk - if it is present, or in the loader / generator queue, or unloaded */
+ ePresence m_Presence;
+
+ /** If the chunk fails to load, should it be queued in the generator or reset back to invalid? */
+ bool m_ShouldGenerateIfLoadFailed;
+
bool m_IsLightValid; // True if the blocklight and skylight are calculated
bool m_IsDirty; // True if the chunk has changed since it was last saved
bool m_IsSaving; // True if the chunk is being saved
@@ -440,7 +484,7 @@ private:
/** Number of times the chunk has been requested to stay (by various cChunkStay objects); if zero, the chunk can be unloaded */
int m_StayCount;
- int m_PosX, m_PosY, m_PosZ;
+ int m_PosX, m_PosZ;
cWorld * m_World;
cChunkMap * m_ChunkMap;
@@ -462,12 +506,8 @@ private:
cFluidSimulatorData * m_LavaSimulatorData;
cSandSimulatorChunkData m_SandSimulatorData;
- cRedstoneSimulatorChunkData m_RedstoneSimulatorData;
- cRedstoneSimulatorChunkData m_RedstoneSimulatorQueuedData;
- cIncrementalRedstoneSimulator::PoweredBlocksList m_RedstoneSimulatorPoweredBlocksList;
- cIncrementalRedstoneSimulator::LinkedBlocksList m_RedstoneSimulatorLinkedBlocksList;
- cIncrementalRedstoneSimulator::SimulatedPlayerToggleableList m_RedstoneSimulatorSimulatedPlayerToggleableList;
- cIncrementalRedstoneSimulator::RepeatersDelayList m_RedstoneSimulatorRepeatersDelayList;
+ cRedstoneSimulatorChunkData * m_RedstoneSimulatorData;
+
/** Indicates if simulate-once blocks should be updated by the redstone simulator */
bool m_IsRedstoneDirty;