public static void WriteLoadedChunks() // writes all chunk data from memory to disk, and clears memory // for every chunk loaded in dictionary { foreach (string chunkIndex in TempChunkData.Keys) { Index index = Index.FromString(chunkIndex); string region = GetParentRegion(index).ToString(); // check if region is loaded, and load it if it's not if (LoadRegionData(GetParentRegion(index)) == false) { CreateRegionFile(GetParentRegion(index)); LoadRegionData(GetParentRegion(index)); } // write chunk data into region dictionary int chunkRegionIndex = GetChunkRegionIndex(index); LoadedRegions[region][chunkRegionIndex] = TempChunkData[chunkIndex]; } TempChunkData.Clear(); // for every region loaded in dictionary foreach (string regionIndex in LoadedRegions.Keys) { WriteRegionFile(regionIndex); } LoadedRegions.Clear(); }
private static void WriteRegionFile(string regionIndex) { string[] regionData = LoadedRegions [regionIndex]; StreamWriter writer = new StreamWriter(GetRegionPath(Index.FromString(regionIndex))); int count = 0; foreach (string chunk in regionData) { writer.Write(chunk); if (count != regionData.Length - 1) { writer.Write((char)ushort.MaxValue); } count++; } writer.Flush(); writer.Close(); }
private static void WriteRegionFile(string regionIndex) { string[] regionData = LoadedRegions[regionIndex]; StreamWriter writer = new StreamWriter(GetRegionPath(Index.FromString(regionIndex))); StreamWriter show_Writer = new StreamWriter(GetRegionPath_Show(Index.FromString(regionIndex))); int count = 0; foreach (string chunk in regionData) { writer.Write(chunk); for (int i = 0; i < chunk.Length; i++) { show_Writer.Write((ushort)chunk[i]); if (i % 2 == 0) { show_Writer.Write(','); } else { show_Writer.Write('/'); } } if (count != regionData.Length - 1) { writer.Write((char)ushort.MaxValue); show_Writer.Write(';'); show_Writer.WriteLine(); } count++; } show_Writer.WriteLine(count.ToString() + "个chunk"); show_Writer.Flush(); show_Writer.Close(); writer.Flush(); writer.Close(); }