summaryrefslogtreecommitdiffstats
path: root/src/World.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/World.h')
-rw-r--r--src/World.h45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/World.h b/src/World.h
index a53d3471c..8ff64046d 100644
--- a/src/World.h
+++ b/src/World.h
@@ -40,19 +40,19 @@ class cChunkGenerator; // The thread responsible for generating chunks
class cBeaconEntity;
class cBrewingstandEntity;
class cChestEntity;
+class cCuboid;
class cDispenserEntity;
class cFlowerPotEntity;
class cFurnaceEntity;
class cNoteEntity;
class cMobHeadEntity;
class cCompositeChat;
-class cCuboid;
class cSetChunkData;
class cBroadcaster;
class cDeadlockDetect;
typedef std::list< cPlayer * > cPlayerList;
-typedef std::list< std::pair< cPlayer *, cWorld * > > cAwaitingPlayerList;
+typedef std::list< std::pair< std::unique_ptr<cPlayer>, cWorld * > > cAwaitingPlayerList;
typedef std::unique_ptr<cSetChunkData> cSetChunkDataPtr;
typedef std::vector<cSetChunkDataPtr> cSetChunkDataPtrs;
@@ -258,13 +258,18 @@ public:
Uses a queue to store the player object until the Tick thread processes the addition event.
Also adds the player as an entity in the chunkmap, and the player's ClientHandle, if any, for ticking.
If a_OldWorld is provided, a corresponding ENTITY_CHANGED_WORLD event is triggerred after the addition. */
- void AddPlayer(cPlayer * a_Player, cWorld * a_OldWorld = nullptr);
+ void AddPlayer(std::unique_ptr<cPlayer> a_Player, cWorld * a_OldWorld = nullptr);
/** Removes the player from the world.
Removes the player from the addition queue, too, if appropriate.
If the player has a ClientHandle, the ClientHandle is removed from all chunks in the world and will not be ticked by this world anymore.
- @param a_RemoveFromChunk determines if the entity should be removed from its chunk as well. Should be false when ticking from cChunk. */
- void RemovePlayer(cPlayer * a_Player, bool a_RemoveFromChunk);
+ @param a_RemoveFromChunk determines if the entity should be removed from its chunk as well. Should be false when ticking from cChunk.
+ @return An owning reference to the given player. */
+ std::unique_ptr<cPlayer> RemovePlayer(cPlayer & a_Player, bool a_RemoveFromChunk);
+
+#ifdef _DEBUG
+ bool IsPlayerReferencedInWorldOrChunk(cPlayer & a_Player);
+#endif
/** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */
virtual bool ForEachPlayer(cPlayerListCallback & a_Callback) override; // >> EXPORTED IN MANUALBINDINGS <<
@@ -277,7 +282,7 @@ public:
bool FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
// TODO: This interface is dangerous - rewrite to DoWithClosestPlayer(pos, sight, action)
- cPlayer * FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, bool a_CheckLineOfSight = true);
+ cPlayer * FindClosestPlayer(Vector3d a_Pos, float a_SightLimit, bool a_CheckLineOfSight = true);
/** Finds the player over his uuid and calls the callback */
bool DoWithPlayerByUUID(const AString & a_PlayerUUID, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
@@ -287,7 +292,7 @@ public:
/** Adds the entity into its appropriate chunk; takes ownership of the entity ptr.
The entity is added lazily - this function only puts it in a queue that is then processed by the Tick thread. */
- void AddEntity(cEntity * a_Entity);
+ void AddEntity(OwnedEntity a_Entity);
/** Returns true if an entity with the specified UniqueID exists in the world.
Note: Only loaded chunks are considered. */
@@ -412,11 +417,11 @@ public:
// tolua_begin
// Vector3i variants:
- void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta); }
- BLOCKTYPE GetBlock (const Vector3i & a_Pos) { return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z); }
- NIBBLETYPE GetBlockMeta(const Vector3i & a_Pos) { return GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z); }
- void SetBlockMeta(const Vector3i & a_Pos, NIBBLETYPE a_MetaData) { SetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z, a_MetaData); }
- NIBBLETYPE GetBlockBlockLight(const Vector3i & a_Pos) { return GetBlockBlockLight( a_Pos.x, a_Pos.y, a_Pos.z); }
+ void FastSetBlock(Vector3i a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta); }
+ BLOCKTYPE GetBlock (Vector3i a_Pos) { return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z); }
+ NIBBLETYPE GetBlockMeta(Vector3i a_Pos) { return GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z); }
+ void SetBlockMeta(Vector3i a_Pos, NIBBLETYPE a_MetaData) { SetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z, a_MetaData); }
+ NIBBLETYPE GetBlockBlockLight(Vector3i a_Pos) { return GetBlockBlockLight( a_Pos.x, a_Pos.y, a_Pos.z); }
// tolua_end
/** Writes the block area into the specified coords.
@@ -484,9 +489,19 @@ public:
double GetSpawnZ(void) const { return m_SpawnZ; }
/** Wakes up the simulators for the specified block */
- virtual void WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void WakeUpSimulators(Vector3i a_Block) override;
/** Wakes up the simulators for the specified area of blocks */
+ void WakeUpSimulatorsInArea(const cCuboid & a_Area);
+
+ // DEPRECATED, use vector-parametered version instead
+ void WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ)
+ {
+ LOGWARNING("cWorld::WakeUpSimulators(int, int, int) is deprecated, use cWorld::WakeUpSimulators(Vector3i) instead.");
+ WakeUpSimulators({a_BlockX, a_BlockY, a_BlockZ});
+ }
+
+ // DEPRECATED, use vector-parametered version instead
void WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ);
// tolua_end
@@ -791,7 +806,9 @@ public:
/** Spawns a mob of the specified type. Returns the mob's UniqueID if recognized and spawned, cEntity::INVALID_ID otherwise */
virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType, bool a_Baby = false) override; // tolua_export
- UInt32 SpawnMobFinalize(cMonster * a_Monster);
+ /** Wraps cEntity::Initialize, doing Monster-specific things before spawning the monster.
+ Takes ownership of the given Monster reference. */
+ UInt32 SpawnMobFinalize(std::unique_ptr<cMonster> a_Monster);
/** Creates a projectile of the specified type. Returns the projectile's UniqueID if successful, cEntity::INVALID_ID otherwise
Item parameter is currently used for Fireworks to correctly set entity metadata based on item metadata. */