diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2017-08-18 12:17:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-18 12:17:56 +0200 |
commit | 72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82 (patch) | |
tree | c1c1a040332d4ba1f784be25c67c9800e85015eb /src/World.h | |
parent | Sitting cats block enderchests from opening (#3906) (diff) | |
parent | Changed entity ownership model to use smart pointers (diff) | |
download | cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.gz cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.bz2 cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.lz cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.xz cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.zst cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.zip |
Diffstat (limited to 'src/World.h')
-rw-r--r-- | src/World.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/World.h b/src/World.h index 064dad0d2..8ff64046d 100644 --- a/src/World.h +++ b/src/World.h @@ -52,7 +52,7 @@ 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 << @@ -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. */ @@ -801,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. */ |