Core/Maps: Improvements to terrain swap handling

* Fixed memory leak when unloading grids
* Handle child maps being entered
* Allow chaining more child maps (Draenor -> Tanaan Jungle -> Tanaan Jungle - No Hubs Phase)
This commit is contained in:
Shauren
2020-05-24 22:34:25 +02:00
parent ebb6f12db8
commit eba31dea27
12 changed files with 187 additions and 152 deletions

View File

@@ -78,9 +78,9 @@ Map* MapManager::CreateBaseMap(uint32 id)
if (!map)
{
MapEntry const* entry = sMapStore.AssertEntry(id);
if (entry->ParentMapID != -1)
if (entry->ParentMapID != -1 || entry->CosmeticParentMapID != -1)
{
CreateBaseMap(entry->ParentMapID);
CreateBaseMap(entry->ParentMapID != -1 ? entry->ParentMapID : entry->CosmeticParentMapID);
// must have been created by parent map
map = FindBaseMap(id);
@@ -103,6 +103,8 @@ Map* MapManager::CreateBaseMap_i(MapEntry const* mapEntry)
else
map = new Map(mapEntry->ID, i_gridCleanUpDelay, 0, DIFFICULTY_NONE);
map->DiscoverGridMapFiles();
i_maps[mapEntry->ID] = map;
for (uint32 childMapId : _parentMapData[mapEntry->ID])
@@ -280,16 +282,15 @@ bool MapManager::IsValidMAP(uint32 mapid, bool startUp)
void MapManager::UnloadAll()
{
// first unlink child maps
// first unload maps
for (auto iter = i_maps.begin(); iter != i_maps.end(); ++iter)
iter->second->UnlinkAllChildTerrainMaps();
for (MapMapType::iterator iter = i_maps.begin(); iter != i_maps.end();)
{
iter->second->UnloadAll();
// then delete them
for (auto iter = i_maps.begin(); iter != i_maps.end(); ++iter)
delete iter->second;
i_maps.erase(iter++);
}
i_maps.clear();
if (m_updater.activated())
m_updater.deactivate();