feat(Core/WorldObjects): implement Heartbeat timers (#20872)
This commit is contained in:
@@ -446,6 +446,8 @@ bool GameObject::Create(ObjectGuid::LowType guidlow, uint32 name_id, Map* map, u
|
|||||||
|
|
||||||
void GameObject::Update(uint32 diff)
|
void GameObject::Update(uint32 diff)
|
||||||
{
|
{
|
||||||
|
WorldObject::Update(diff);
|
||||||
|
|
||||||
if (AI())
|
if (AI())
|
||||||
AI()->UpdateAI(diff);
|
AI()->UpdateAI(diff);
|
||||||
else if (!AIM_Initialize())
|
else if (!AIM_Initialize())
|
||||||
|
|||||||
@@ -1050,7 +1050,7 @@ void MovementInfo::OutDebug()
|
|||||||
WorldObject::WorldObject(bool isWorldObject) : WorldLocation(),
|
WorldObject::WorldObject(bool isWorldObject) : WorldLocation(),
|
||||||
LastUsedScriptID(0), m_name(""), m_isActive(false), m_visibilityDistanceOverride(), m_isWorldObject(isWorldObject), m_zoneScript(nullptr),
|
LastUsedScriptID(0), m_name(""), m_isActive(false), m_visibilityDistanceOverride(), m_isWorldObject(isWorldObject), m_zoneScript(nullptr),
|
||||||
_zoneId(0), _areaId(0), _floorZ(INVALID_HEIGHT), _outdoors(false), _liquidData(), _updatePositionData(false), m_transport(nullptr),
|
_zoneId(0), _areaId(0), _floorZ(INVALID_HEIGHT), _outdoors(false), _liquidData(), _updatePositionData(false), m_transport(nullptr),
|
||||||
m_currMap(nullptr), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL), m_useCombinedPhases(true), m_notifyflags(0), m_executed_notifies(0)
|
m_currMap(nullptr), _heartbeatTimer(HEARTBEAT_INTERVAL), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL), m_useCombinedPhases(true), m_notifyflags(0), m_executed_notifies(0)
|
||||||
{
|
{
|
||||||
m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE | GHOST_VISIBILITY_GHOST);
|
m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE | GHOST_VISIBILITY_GHOST);
|
||||||
m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
|
m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
|
||||||
@@ -1058,9 +1058,18 @@ WorldObject::WorldObject(bool isWorldObject) : WorldLocation(),
|
|||||||
sScriptMgr->OnWorldObjectCreate(this);
|
sScriptMgr->OnWorldObjectCreate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldObject::Update(uint32 time_diff)
|
void WorldObject::Update(uint32 diff)
|
||||||
{
|
{
|
||||||
sScriptMgr->OnWorldObjectUpdate(this, time_diff);
|
m_Events.Update(diff);
|
||||||
|
|
||||||
|
_heartbeatTimer -= Milliseconds(diff);
|
||||||
|
while (_heartbeatTimer <= 0ms)
|
||||||
|
{
|
||||||
|
_heartbeatTimer += HEARTBEAT_INTERVAL;
|
||||||
|
Heartbeat();
|
||||||
|
}
|
||||||
|
|
||||||
|
sScriptMgr->OnWorldObjectUpdate(this, diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldObject::SetWorldObject(bool on)
|
void WorldObject::SetWorldObject(bool on)
|
||||||
@@ -1134,6 +1143,8 @@ void WorldObject::CleanupsBeforeDelete(bool /*finalCleanup*/)
|
|||||||
{
|
{
|
||||||
if (IsInWorld())
|
if (IsInWorld())
|
||||||
RemoveFromWorld();
|
RemoveFromWorld();
|
||||||
|
|
||||||
|
m_Events.KillAllEvents(false); // non-delatable (currently cast spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldObject::_Create(ObjectGuid::LowType guidlow, HighGuid guidhigh, uint32 phaseMask)
|
void WorldObject::_Create(ObjectGuid::LowType guidlow, HighGuid guidhigh, uint32 phaseMask)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "DataMap.h"
|
#include "DataMap.h"
|
||||||
|
#include "EventProcessor.h"
|
||||||
#include "G3D/Vector3.h"
|
#include "G3D/Vector3.h"
|
||||||
#include "GridDefines.h"
|
#include "GridDefines.h"
|
||||||
#include "GridReference.h"
|
#include "GridReference.h"
|
||||||
@@ -96,6 +97,8 @@ struct PositionFullTerrainStatus;
|
|||||||
typedef std::unordered_map<Player*, UpdateData> UpdateDataMapType;
|
typedef std::unordered_map<Player*, UpdateData> UpdateDataMapType;
|
||||||
typedef GuidUnorderedSet UpdatePlayerSet;
|
typedef GuidUnorderedSet UpdatePlayerSet;
|
||||||
|
|
||||||
|
static constexpr Milliseconds HEARTBEAT_INTERVAL = 5s + 200ms;
|
||||||
|
|
||||||
class Object
|
class Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -220,6 +223,8 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] inline bool IsItem() const { return GetTypeId() == TYPEID_ITEM; }
|
[[nodiscard]] inline bool IsItem() const { return GetTypeId() == TYPEID_ITEM; }
|
||||||
|
|
||||||
|
virtual void Heartbeat() {}
|
||||||
|
|
||||||
virtual std::string GetDebugInfo() const;
|
virtual std::string GetDebugInfo() const;
|
||||||
|
|
||||||
DataMap CustomData;
|
DataMap CustomData;
|
||||||
@@ -408,7 +413,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
~WorldObject() override;
|
~WorldObject() override;
|
||||||
|
|
||||||
virtual void Update(uint32 /*time_diff*/);
|
virtual void Update(uint32 diff);
|
||||||
|
|
||||||
void _Create(ObjectGuid::LowType guidlow, HighGuid guidhigh, uint32 phaseMask);
|
void _Create(ObjectGuid::LowType guidlow, HighGuid guidhigh, uint32 phaseMask);
|
||||||
|
|
||||||
@@ -632,7 +637,9 @@ public:
|
|||||||
|
|
||||||
std::string GetDebugInfo() const override;
|
std::string GetDebugInfo() const override;
|
||||||
|
|
||||||
|
// Event handler
|
||||||
ElunaEventProcessor* elunaEvents;
|
ElunaEventProcessor* elunaEvents;
|
||||||
|
EventProcessor m_Events;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
@@ -666,7 +673,7 @@ protected:
|
|||||||
virtual bool IsAlwaysDetectableFor(WorldObject const* /*seer*/) const { return false; }
|
virtual bool IsAlwaysDetectableFor(WorldObject const* /*seer*/) const { return false; }
|
||||||
private:
|
private:
|
||||||
Map* m_currMap; //current object's Map location
|
Map* m_currMap; //current object's Map location
|
||||||
|
Milliseconds _heartbeatTimer;
|
||||||
//uint32 m_mapId; // object at map with map_id
|
//uint32 m_mapId; // object at map with map_id
|
||||||
uint32 m_InstanceId; // in map copy with instance id
|
uint32 m_InstanceId; // in map copy with instance id
|
||||||
uint32 m_phaseMask; // in area phase state
|
uint32 m_phaseMask; // in area phase state
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ void Unit::Update(uint32 p_time)
|
|||||||
// WARNING! Order of execution here is important, do not change.
|
// WARNING! Order of execution here is important, do not change.
|
||||||
// Spells must be processed with event system BEFORE they go to _UpdateSpells.
|
// Spells must be processed with event system BEFORE they go to _UpdateSpells.
|
||||||
// Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
|
// Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
|
||||||
m_Events.Update(p_time);
|
WorldObject::Update(p_time);
|
||||||
|
|
||||||
if (!IsInWorld())
|
if (!IsInWorld())
|
||||||
return;
|
return;
|
||||||
@@ -15760,7 +15760,6 @@ void Unit::CleanupBeforeRemoveFromMap(bool finalCleanup)
|
|||||||
if (finalCleanup)
|
if (finalCleanup)
|
||||||
m_cleanupDone = true;
|
m_cleanupDone = true;
|
||||||
|
|
||||||
m_Events.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
|
|
||||||
CombatStop();
|
CombatStop();
|
||||||
ClearComboPoints();
|
ClearComboPoints();
|
||||||
ClearComboPointHolders();
|
ClearComboPointHolders();
|
||||||
|
|||||||
@@ -1952,9 +1952,6 @@ public:
|
|||||||
float m_threatModifier[MAX_SPELL_SCHOOL];
|
float m_threatModifier[MAX_SPELL_SCHOOL];
|
||||||
float m_modAttackSpeedPct[3];
|
float m_modAttackSpeedPct[3];
|
||||||
|
|
||||||
// Event handler
|
|
||||||
EventProcessor m_Events;
|
|
||||||
|
|
||||||
SpellImmuneList m_spellImmune[MAX_SPELL_IMMUNITY];
|
SpellImmuneList m_spellImmune[MAX_SPELL_IMMUNITY];
|
||||||
uint32 m_lastSanctuaryTime;
|
uint32 m_lastSanctuaryTime;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user