Core/Scripts: Removed script calls from constructors and destructors

(cherry picked from commit 783f9c0ea3)
This commit is contained in:
Shauren
2024-03-14 20:32:03 +01:00
parent 303ecbbf4e
commit 4e54a4ffb9
3 changed files with 18 additions and 6 deletions

View File

@@ -86,10 +86,6 @@ struct RespawnInfoWithHandle : RespawnInfo
Map::~Map()
{
// UnloadAll must be called before deleting the map
sScriptMgr->OnDestroyMap(this);
// Delete all waiting spawns, else there will be a memory leak
// This doesn't delete from database.
UnloadAllRespawnInfos();
@@ -300,8 +296,6 @@ i_scriptLock(false), _respawnTimes(std::make_unique<RespawnListContainer>()), _r
_weatherUpdateTimer.SetInterval(time_t(1 * IN_MILLISECONDS));
MMAP::MMapFactory::createOrGetMMapManager()->loadMapInstance(sWorld->GetDataPath(), GetId(), GetInstanceId());
sScriptMgr->OnCreateMap(this);
}
void Map::InitVisibilityDistance()

View File

@@ -25,6 +25,7 @@
#include "MMapFactory.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "VMapFactory.h"
#include "VMapManager2.h"
#include "World.h"
@@ -95,8 +96,12 @@ void MapInstanced::UnloadAll()
{
// Unload instanced maps
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
{
i->second->UnloadAll();
sScriptMgr->OnDestroyMap(i->second.get());
}
m_InstancedMaps.clear();
// Unload own grids (just dummy(placeholder) grids, neccesary to unload GridMaps!)
@@ -236,6 +241,8 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save,
Trinity::unique_trackable_ptr<Map>& ptr = m_InstancedMaps[InstanceId];
ptr.reset(map);
map->SetWeakPtr(ptr);
sScriptMgr->OnCreateMap(map);
return map;
}
@@ -263,6 +270,8 @@ BattlegroundMap* MapInstanced::CreateBattleground(uint32 InstanceId, Battlegroun
Trinity::unique_trackable_ptr<Map>& ptr = m_InstancedMaps[InstanceId];
ptr.reset(map);
map->SetWeakPtr(ptr);
sScriptMgr->OnCreateMap(map);
return map;
}
@@ -287,6 +296,8 @@ bool MapInstanced::DestroyInstance(InstancedMaps::iterator &itr)
Map::UnloadAll();
}
sScriptMgr->OnDestroyMap(itr->second.get());
// Free up the instance id and allow it to be reused for bgs and arenas (other instances are handled in the InstanceSaveMgr)
if (itr->second->IsBattlegroundOrArena())
sMapMgr->FreeInstanceId(itr->second->GetInstanceId());

View File

@@ -33,6 +33,7 @@
#include "Player.h"
#include "WorldSession.h"
#include "Opcodes.h"
#include "ScriptMgr.h"
#include <numeric>
MapManager::MapManager()
@@ -89,6 +90,8 @@ Map* MapManager::CreateBaseMap(uint32 id)
Trinity::unique_trackable_ptr<Map>& ptr = i_maps[id];
ptr.reset(map);
map->SetWeakPtr(ptr);
sScriptMgr->OnCreateMap(map);
}
ASSERT(map);
@@ -260,8 +263,12 @@ void MapManager::UnloadAll()
{
// first unload maps
for (auto iter = i_maps.begin(); iter != i_maps.end(); ++iter)
{
iter->second->UnloadAll();
sScriptMgr->OnDestroyMap(iter->second.get());
}
// then delete them
i_maps.clear();