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>
This commit is contained in:
Ovahlord
2024-04-26 01:14:48 +02:00
committed by GitHub
parent 1fc5f9c624
commit bf9cd88ceb
2 changed files with 13 additions and 1 deletions

View File

@@ -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)

View File

@@ -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;