private int OriginalSort(MapChunk x, MapChunk y) { if (x.Scene.WorldID != y.Scene.WorldID) return x.Scene.WorldID - y.Scene.WorldID; if (x.Scene.ParentChunkID != y.Scene.ParentChunkID) return x.Scene.ParentChunkID - y.Scene.ParentChunkID; return x.originalsortorder - y.originalsortorder; }
public void LoadMapChunkDatabase() { MapChunkDB = new List<MapChunk>(); string filePath = "Assets\\!onlymap.txt"; string line, line2; if (File.Exists(filePath)) { int x = 0; StreamReader file = null; try { System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex(@"\s+"); file = new StreamReader(filePath); while ((line = file.ReadLine()) != null) { string line_ = rx.Replace(line, @" "); string[] data = line_.Split(' '); if ((line2 = file.ReadLine()) != null) { string line2_ = rx.Replace(line2, @" "); string[] data2 = line2_.Split(' '); int worldid = int.Parse(data[2]); MapChunk m = new MapChunk(); m.Scene = new RevealSceneMessage(data.Skip(2).ToArray(), worldid); m.Map = new MapRevealSceneMessage(data2.Skip(2).ToArray(), worldid); m.SceneLine = line; m.MapLine = line2; m.originalsortorder = x++; MapChunkDB.Add(m); } } } catch (Exception e) { Logger.DebugException(e, "ReadMapDatabase"); } finally { if (file != null) file.Close(); } MapChunkDB.Sort(CompareMapChunks); StreamWriter f = new StreamWriter("Assets\\mapdboutput.txt"); for (x = 1; x < MapChunkDB.Count; x++) { MapChunk m0 = MapChunkDB[x - 1]; MapChunk m1 = MapChunkDB[x]; if (CompareMapChunks(m0, m1) == 0) { MapChunkDB.RemoveAt(x); x--; } } MapChunkDB.Sort(OriginalSort); MapChunk[] mdb = MapChunkDB.ToArray(); foreach (MapChunk m in mdb) { f.WriteLine(m.SceneLine); f.WriteLine(m.MapLine); } f.Close(); } }
private int CompareMapChunks(MapChunk x, MapChunk y) { if (x.Scene.ParentChunkID != y.Scene.ParentChunkID) return x.Scene.ParentChunkID - y.Scene.ParentChunkID; return x.Scene.ChunkID - y.Scene.ChunkID; }