public void UnloadMapTile(uint tileX, uint tileY, VMapManager vm) { uint tileID = PackTileID(tileX, tileY); var tile = iLoadedTiles.LookupByKey(tileID); if (!iLoadedTiles.ContainsKey(tileID)) { Log.outError(LogFilter.Server, "StaticMapTree.UnloadMapTile() : trying to unload non-loaded tile - Map:{0} X:{1} Y:{2}", iMapID, tileX, tileY); return; } if (tile) // file associated with tile { FileStream stream = OpenMapTileFile(VMapManager.VMapPath, iMapID, tileX, tileY, vm); if (stream != null) { using (BinaryReader reader = new BinaryReader(stream)) { bool result = true; if (reader.ReadStringFromChars(8) != MapConst.VMapMagic) { result = false; } uint numSpawns = reader.ReadUInt32(); for (uint i = 0; i < numSpawns && result; ++i) { // read model spawns ModelSpawn spawn; result = ModelSpawn.ReadFromFile(reader, out spawn); if (result) { // release model instance vm.ReleaseModelInstance(spawn.name); // update tree if (!iSpawnIndices.ContainsKey(spawn.Id)) { result = false; } else { uint referencedNode = iSpawnIndices[spawn.Id]; if (!iLoadedSpawns.ContainsKey(referencedNode)) { Log.outError(LogFilter.Server, "StaticMapTree.UnloadMapTile() : trying to unload non-referenced model '{0}' (ID:{1})", spawn.name, spawn.Id); } else if (--iLoadedSpawns[referencedNode] == 0) { iTreeValues[referencedNode].SetUnloaded(); iLoadedSpawns.Remove(referencedNode); } } } } } } } iLoadedTiles.Remove(tileID); }
public void UnloadMap(VMapManager vm) { foreach (var id in iLoadedSpawns) { iTreeValues[id.Key].SetUnloaded(); for (uint refCount = 0; refCount < id.Key; ++refCount) { vm.ReleaseModelInstance(iTreeValues[id.Key].name); } } iLoadedSpawns.Clear(); iLoadedTiles.Clear(); }