Skip to content

Commit 5da26d1

Browse files
Ovahlordr4d1sh
andcommitted
Core/Objects: implement internal heartbeat timer for WorldObjects
Co-authored-by: Mykhailo Redko <ovitnez@gmail.com>
1 parent 5aa0d5d commit 5da26d1

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/server/game/Entities/Object/Object.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ void MovementInfo::OutDebug()
936936
WorldObject::WorldObject(bool isWorldObject) : Object(), WorldLocation(), LastUsedScriptID(0),
937937
m_movementInfo(), m_name(), m_isActive(false), m_isFarVisible(false), m_isStoredInWorldObjectGridContainer(isWorldObject), m_zoneScript(nullptr),
938938
m_transport(nullptr), m_zoneId(0), m_areaId(0), m_staticFloorZ(VMAP_INVALID_HEIGHT), m_outdoors(false), m_liquidStatus(LIQUID_MAP_NO_WATER),
939-
m_currMap(nullptr), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL), m_notifyflags(0)
939+
m_currMap(nullptr), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL), m_notifyflags(0), _heartbeatTimer(HEARTBEAT_INTERVAL)
940940
{
941941
m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE | GHOST_VISIBILITY_GHOST);
942942
m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
@@ -960,6 +960,13 @@ WorldObject::~WorldObject()
960960
void WorldObject::Update(uint32 diff)
961961
{
962962
m_Events.Update(diff);
963+
964+
_heartbeatTimer -= Milliseconds(diff);
965+
while (_heartbeatTimer <= 0ms)
966+
{
967+
_heartbeatTimer += HEARTBEAT_INTERVAL;
968+
Heartbeat();
969+
}
963970
}
964971

965972
void WorldObject::SetIsStoredInWorldObjectGridContainer(bool on)

src/server/game/Entities/Object/Object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct QuaternionData;
6363
typedef std::unordered_map<Player*, UpdateData> UpdateDataMapType;
6464

6565
float const DEFAULT_COLLISION_HEIGHT = 2.03128f; // Most common value in dbc
66+
static constexpr Milliseconds const HEARTBEAT_INTERVAL = 5s + 200ms;
6667

6768
class TC_GAME_API Object
6869
{
@@ -624,6 +625,8 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
624625
virtual bool IsInvisibleDueToDespawn() const { return false; }
625626
//difference from IsAlwaysVisibleFor: 1. after distance check; 2. use owner or charmer as seer
626627
virtual bool IsAlwaysDetectableFor(WorldObject const* /*seer*/) const { return false; }
628+
629+
virtual void Heartbeat() { }
627630
private:
628631
Map* m_currMap; // current object's Map location
629632

@@ -634,6 +637,8 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
634637

635638
ObjectGuid _privateObjectOwner;
636639

640+
Milliseconds _heartbeatTimer;
641+
637642
virtual bool _IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D, bool incOwnRadius = true, bool incTargetRadius = true) const;
638643

639644
bool CanNeverSee(WorldObject const* obj) const;

0 commit comments

Comments
 (0)