Merge 5e444b87a0d28fda9ad42c5db16d53906331d61d into dab83dd19eeee975bb7e8bb70c29064eba3bf334

This commit is contained in:
天鹭 2025-11-08 18:15:37 +08:00 committed by GitHub
commit c83a9d2d42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View File

@ -120,7 +120,7 @@ class EventProcessor
[[nodiscard]] uint64 CalculateQueueTime(uint64 delay) const;
void CancelEventGroup(uint8 group);
bool HaveEventList() const { return !m_events.empty(); }
bool HasEvents() const { return !m_events.empty(); }
protected:
uint64 m_time{0};

View File

@ -54,6 +54,10 @@ Map::~Map()
{
// UnloadAll must be called before deleting the map
// Kill all scheduled events without executing them, since the map and its objects are being destroyed.
// This prevents events from running on invalid or deleted objects during map destruction.
Events.KillAllEvents(false);
sScriptMgr->OnDestroyMap(this);
if (!m_scriptSchedule.empty())
@ -447,7 +451,7 @@ void Map::Update(const uint32 t_diff, const uint32 s_diff, bool /*thread*/)
}
}
_creatureRespawnScheduler.Update(t_diff);
Events.Update(t_diff);
if (!t_diff)
{
@ -2758,13 +2762,13 @@ void Map::RemoveOldCorpses()
void Map::ScheduleCreatureRespawn(ObjectGuid creatureGuid, Milliseconds respawnTimer, Position pos)
{
_creatureRespawnScheduler.Schedule(respawnTimer, [this, creatureGuid, pos](TaskContext)
Events.AddEventAtOffset([this, creatureGuid, pos]()
{
if (Creature* creature = GetCreature(creatureGuid))
creature->Respawn();
else
SummonCreature(creatureGuid.GetEntry(), pos);
});
}, respawnTimer);
}
/// Send a packet to all players (or players selected team) in the zone (except self if mentioned)

View File

@ -23,6 +23,7 @@
#include "DataMap.h"
#include "Define.h"
#include "DynamicTree.h"
#include "EventProcessor.h"
#include "GameObjectModel.h"
#include "GridDefines.h"
#include "GridRefMgr.h"
@ -33,7 +34,6 @@
#include "PathGenerator.h"
#include "Position.h"
#include "SharedDefines.h"
#include "TaskScheduler.h"
#include "Timer.h"
#include "GridTerrainData.h"
#include <bitset>
@ -172,7 +172,7 @@ public:
// currently unused for normal maps
bool CanUnload(uint32 diff)
{
if (!m_unloadTimer)
if (!m_unloadTimer || Events.HasEvents())
return false;
if (m_unloadTimer <= diff)
@ -430,7 +430,7 @@ public:
void UpdatePlayerZoneStats(uint32 oldZone, uint32 newZone);
[[nodiscard]] uint32 ApplyDynamicModeRespawnScaling(WorldObject const* obj, uint32 respawnDelay) const;
TaskScheduler _creatureRespawnScheduler;
EventProcessor Events;
void ScheduleCreatureRespawn(ObjectGuid /*creatureGuid*/, Milliseconds /*respawnTimer*/, Position pos = Position());