diff options
author | Ovahlord <dreadkiller@gmx.de> | 2024-04-26 01:14:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-26 01:14:48 +0200 |
commit | bf9cd88cebf752ce8614fbac8a7c6d1f0de7fee8 (patch) | |
tree | 43386a00d6c2ad9ff29fbeed1c59d5db556852bd /src | |
parent | 1fc5f9c6240d5f02e7d6a44f545c25e21023559a (diff) |
Core/Objects: implement internal heartbeat timer for WorldObjects (#29941)
This is the first step of porting the functionality of #25822 by cutting each change into a nicely self-contained commit
---------
Co-authored-by: Mykhailo Redko <ovitnez@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.h | 5 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 6a7075cfe4d..70588e275ef 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -880,7 +880,7 @@ void MovementInfo::OutDebug() WorldObject::WorldObject(bool isWorldObject) : Object(), WorldLocation(), LastUsedScriptID(0), m_movementInfo(), m_name(), m_isActive(false), m_isFarVisible(false), m_isStoredInWorldObjectGridContainer(isWorldObject), m_zoneScript(nullptr), m_transport(nullptr), m_zoneId(0), m_areaId(0), m_staticFloorZ(VMAP_INVALID_HEIGHT), m_outdoors(false), m_liquidStatus(LIQUID_MAP_NO_WATER), -m_currMap(nullptr), m_InstanceId(0), _dbPhase(0), m_notifyflags(0) +m_currMap(nullptr), m_InstanceId(0), _dbPhase(0), m_notifyflags(0), _heartbeatTimer(HEARTBEAT_INTERVAL) { m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE | GHOST_VISIBILITY_GHOST); m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE); @@ -904,6 +904,13 @@ WorldObject::~WorldObject() void WorldObject::Update(uint32 diff) { m_Events.Update(diff); + + _heartbeatTimer -= Milliseconds(diff); + while (_heartbeatTimer <= 0ms) + { + _heartbeatTimer += HEARTBEAT_INTERVAL; + Heartbeat(); + } } void WorldObject::SetIsStoredInWorldObjectGridContainer(bool on) diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 720cd54d516..3183ff1939e 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -145,6 +145,7 @@ namespace UF } float const DEFAULT_COLLISION_HEIGHT = 2.03128f; // Most common value in dbc +static constexpr Milliseconds const HEARTBEAT_INTERVAL = 5s + 200ms; class TC_GAME_API Object { @@ -823,6 +824,8 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation virtual bool IsInvisibleDueToDespawn([[maybe_unused]] WorldObject const* seer) const { return false; } //difference from IsAlwaysVisibleFor: 1. after distance check; 2. use owner or charmer as seer virtual bool IsAlwaysDetectableFor([[maybe_unused]] WorldObject const* seer) const { return false; } + + virtual void Heartbeat() { } private: Map* m_currMap; // current object's Map location @@ -837,6 +840,8 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation std::unique_ptr<SmoothPhasing> _smoothPhasing; + Milliseconds _heartbeatTimer; + virtual bool _IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D, bool incOwnRadius = true, bool incTargetRadius = true) const; bool CanDetect(WorldObject const* obj, bool ignoreStealth, bool checkAlert = false) const; |