summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.h73
1 files changed, 59 insertions, 14 deletions
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 2805ee9e0..b151f745d 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -2,6 +2,7 @@
#pragma once
#include "../Item.h"
+#include "../OSSupport/AtomicUniquePtr.h"
@@ -72,6 +73,16 @@ struct TakeDamageInfo
// tolua_begin
class cEntity
{
+protected:
+ /** State variables for MoveToWorld. */
+ struct sWorldChangeInfo
+ {
+ cWorld * m_NewWorld;
+ Vector3d m_NewPosition;
+ bool m_SetPortalCooldown;
+ bool m_SendRespawn;
+ };
+
public:
enum eEntityType
@@ -163,6 +174,16 @@ public:
Adds the entity to the world. */
virtual bool Initialize(OwnedEntity a_Self, cWorld & a_EntityWorld);
+ /** Called when the entity is added to a world.
+ e.g after first spawning or after successfuly moving between worlds.
+ \param a_World The world being added to. */
+ virtual void OnAddToWorld(cWorld & a_World);
+
+ /** Called when the entity is removed from a world.
+ e.g. When the entity is destroyed or moved to a different world.
+ \param a_World The world being removed from. */
+ virtual void OnRemoveFromWorld(cWorld & a_World);
+
// tolua_begin
eEntityType GetEntityType(void) const { return m_EntityType; }
@@ -268,8 +289,14 @@ public:
If this returns false, you must stop using the cEntity pointer you have. */
bool IsTicking(void) const;
- /** Destroys the entity and schedules it for memory freeing; if a_ShouldBroadcast is set to true, broadcasts the DestroyEntity packet */
- virtual void Destroy(bool a_ShouldBroadcast = true);
+ /** Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet */
+ virtual void Destroy();
+
+ OBSOLETE void Destroy(bool a_ShouldBroadcast)
+ {
+ LOGWARNING("cEntity:Destory(bool) is deprecated, use cEntity:Destroy() instead.");
+ Destroy();
+ }
/** Makes this pawn take damage from an attack by a_Attacker. Damage values are calculated automatically and DoTakeDamage() called */
void TakeDamage(cEntity & a_Attacker);
@@ -442,9 +469,18 @@ public:
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ);
/** Schedules a MoveToWorld call to occur on the next Tick of the entity */
- void ScheduleMoveToWorld(cWorld * a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown = false, bool a_ShouldSendRespawn = false);
+ OBSOLETE void ScheduleMoveToWorld(cWorld * a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown = false, bool a_ShouldSendRespawn = false)
+ {
+ LOGWARNING("ScheduleMoveToWorld is deprecated, use MoveToWorld instead");
+ MoveToWorld(a_World, a_NewPosition, a_ShouldSetPortalCooldown, a_ShouldSendRespawn);
+ }
+
+ bool MoveToWorld(cWorld * a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown = false, bool a_ShouldSendRespawn = false);
- bool MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d a_NewPosition);
+ bool MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d a_NewPosition)
+ {
+ return MoveToWorld(a_World, a_NewPosition, false, a_ShouldSendRespawn);
+ }
/** Moves entity to specified world, taking a world pointer */
bool MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn = true);
@@ -454,7 +490,11 @@ public:
// tolua_end
- virtual bool DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d a_NewPosition);
+ /** Returns true if a world change is scheduled to happen. */
+ bool IsWorldChangeScheduled() const
+ {
+ return (m_WorldChangeInfo.load() != nullptr);
+ }
/** Updates clients of changes in the entity. */
virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = nullptr);
@@ -543,13 +583,16 @@ public:
/** Set the entity's status to either ticking or not ticking. */
void SetIsTicking(bool a_IsTicking);
- /** Adds a mob to the leashed list of mobs */
+ /** Adds a mob to the leashed list of mobs. */
void AddLeashedMob(cMonster * a_Monster);
- /** Removes a mob from the leashed list of mobs */
+ /** Removes a mob from the leashed list of mobs. */
void RemoveLeashedMob(cMonster * a_Monster);
- /** Returs whether the entity has any mob leashed to */
+ /** Removes all mobs from the leashed list of mobs. */
+ void RemoveAllLeashedMobs();
+
+ /** Returs whether the entity has any mob leashed to it. */
bool HasAnyMobLeashed() const { return m_LeashedMobs.size() > 0; }
/** a lightweight calculation approach to get explosion exposure rate
@@ -619,12 +662,8 @@ protected:
cWorld * m_World;
- /** State variables for ScheduleMoveToWorld. */
- bool m_IsWorldChangeScheduled;
- bool m_WorldChangeSetPortalCooldown;
- bool m_WorldChangeSendRespawn;
- cWorld * m_NewWorld;
- Vector3d m_NewWorldPosition;
+ /** If not nullptr, a world change is scheduled and a task is queued in the current world. */
+ cAtomicUniquePtr<sWorldChangeInfo> m_WorldChangeInfo;
/** Whether the entity is capable of taking fire or lava damage. */
bool m_IsFireproof;
@@ -671,6 +710,10 @@ protected:
overrides can provide further processing, such as forcing players to move at the given speed. */
virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ);
+ /** Handles the moving of this entity between worlds.
+ Should handle degenerate cases such as moving to the same world. */
+ virtual void DoMoveToWorld(const sWorldChangeInfo & a_WorldChangeInfo);
+
virtual void Destroyed(void) {} // Called after the entity has been destroyed
/** Applies friction to an entity
@@ -689,6 +732,8 @@ protected:
Only to be used when the caller will broadcast a teleport or equivalent to clients. */
virtual void ResetPosition(Vector3d a_NewPos);
+ /** If has any mobs are leashed, broadcasts every leashed entity to this. */
+ void BroadcastLeashedMobs();
private: