Core/Maps: Fixes nulls which unloading instance maps.
This commit is contained in:
@@ -45,17 +45,17 @@ namespace Game.Maps
|
|||||||
{
|
{
|
||||||
base.Update(diff);
|
base.Update(diff);
|
||||||
|
|
||||||
foreach (var i in m_InstancedMaps.ToList())
|
foreach (var pair in m_InstancedMaps.ToList())
|
||||||
{
|
{
|
||||||
if (i.Value.CanUnload(diff))
|
if (pair.Value.CanUnload(diff))
|
||||||
{
|
{
|
||||||
if (!DestroyInstance(i))
|
if (!DestroyInstance(pair))
|
||||||
{
|
{
|
||||||
//m_unloadTimer
|
//m_unloadTimer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
i.Value.Update(diff);
|
pair.Value.Update(diff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,6 +265,7 @@ namespace Game.Maps
|
|||||||
Global.MapMgr.FreeInstanceId(pair.Value.GetInstanceId());
|
Global.MapMgr.FreeInstanceId(pair.Value.GetInstanceId());
|
||||||
|
|
||||||
// erase map
|
// erase map
|
||||||
|
pair.Value.Dispose();
|
||||||
m_InstancedMaps.Remove(pair.Key);
|
m_InstancedMaps.Remove(pair.Key);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+22
-19
@@ -36,7 +36,7 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace Game.Maps
|
namespace Game.Maps
|
||||||
{
|
{
|
||||||
public class Map
|
public class Map : IDisposable
|
||||||
{
|
{
|
||||||
public Map(uint id, long expiry, uint instanceId, Difficulty spawnmode, Map parent = null)
|
public Map(uint id, long expiry, uint instanceId, Difficulty spawnmode, Map parent = null)
|
||||||
{
|
{
|
||||||
@@ -86,6 +86,27 @@ namespace Game.Maps
|
|||||||
Global.ScriptMgr.OnCreateMap(this);
|
Global.ScriptMgr.OnCreateMap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Global.ScriptMgr.OnDestroyMap(this);
|
||||||
|
|
||||||
|
for (var i = 0; i < i_worldObjects.Count; ++i)
|
||||||
|
{
|
||||||
|
WorldObject obj = i_worldObjects[i];
|
||||||
|
Contract.Assert(obj.IsWorldObject());
|
||||||
|
obj.RemoveFromWorld();
|
||||||
|
obj.ResetMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_scriptSchedule.Empty())
|
||||||
|
Global.MapMgr.DecreaseScheduledScriptCount((uint)m_scriptSchedule.Count);
|
||||||
|
|
||||||
|
if (m_parentMap == this)
|
||||||
|
m_childTerrainMaps = null;
|
||||||
|
|
||||||
|
Global.MMapMgr.unloadMapInstance(GetId(), i_InstanceId);
|
||||||
|
}
|
||||||
|
|
||||||
public static bool ExistMap(uint mapid, uint gx, uint gy)
|
public static bool ExistMap(uint mapid, uint gx, uint gy)
|
||||||
{
|
{
|
||||||
string fileName = $"{Global.WorldMgr.GetDataPath()}/maps/{mapid:D4}_{gx:D2}_{gy:D2}.map";
|
string fileName = $"{Global.WorldMgr.GetDataPath()}/maps/{mapid:D4}_{gx:D2}_{gy:D2}.map";
|
||||||
@@ -1647,24 +1668,6 @@ namespace Game.Maps
|
|||||||
_corpsesByCell.Clear();
|
_corpsesByCell.Clear();
|
||||||
_corpsesByPlayer.Clear();
|
_corpsesByPlayer.Clear();
|
||||||
_corpseBones.Clear();
|
_corpseBones.Clear();
|
||||||
|
|
||||||
Global.ScriptMgr.OnDestroyMap(this);
|
|
||||||
|
|
||||||
for (var i = 0; i < i_worldObjects.Count; ++i)
|
|
||||||
{
|
|
||||||
WorldObject obj = i_worldObjects[i];
|
|
||||||
Contract.Assert(obj.IsWorldObject());
|
|
||||||
obj.RemoveFromWorld();
|
|
||||||
obj.ResetMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_scriptSchedule.Empty())
|
|
||||||
Global.MapMgr.DecreaseScheduledScriptCount((uint)m_scriptSchedule.Count);
|
|
||||||
|
|
||||||
if (m_parentMap == this)
|
|
||||||
m_childTerrainMaps = null;
|
|
||||||
|
|
||||||
Global.MMapMgr.unloadMapInstance(GetId(), i_InstanceId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private GridMap GetGridMap(float x, float y)
|
private GridMap GetGridMap(float x, float y)
|
||||||
|
|||||||
@@ -269,9 +269,10 @@ namespace Game.Entities
|
|||||||
foreach (var pair in i_maps)
|
foreach (var pair in i_maps)
|
||||||
pair.Value.UnlinkAllChildTerrainMaps();
|
pair.Value.UnlinkAllChildTerrainMaps();
|
||||||
|
|
||||||
foreach (var pair in i_maps)
|
foreach (var pair in i_maps.ToList())
|
||||||
{
|
{
|
||||||
pair.Value.UnloadAll();
|
pair.Value.UnloadAll();
|
||||||
|
pair.Value.Dispose();
|
||||||
i_maps.Remove(pair.Key);
|
i_maps.Remove(pair.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user