private void recalcLightingToolStripMenuItem_Click(object sender, EventArgs e) { if (ActiveMdiChild != null) { if ((ActiveMdiChild as frmMap).Map != null) { tsbStatus.Text = "Waiting for user response lol"; DialogResult dr = MessageBox.Show("MineEdit will try and recalculate lighting GLOBALLY using quartz-lightgen.\n\nThis will inevitably take a long time. ARE YOU SURE?", "DO YOU HAVE THE PATIENCE", MessageBoxButtons.YesNo); if (dr == DialogResult.No) { ResetStatus(); return; } dlgLongTask dlt = new dlgLongTask(); dlt.Start(delegate() { ShittyLighter lighter = new ShittyLighter(); dlt.VocabSubtask = "chunk"; dlt.VocabSubtasks = "chunks"; dlt.Title = "Relighting Map"; dlt.Subtitle = "This will take a while. Go take a break."; dlt.SetMarquees(false, false); dlt.CurrentTask = "Relighting..."; dlt.TasksComplete = 0; dlt.TasksTotal = 1; dlt.SubtasksTotal = 1; IMapHandler mh = (ActiveMdiChild as frmMap).Map; ForEachProgressHandler FEPH = new ForEachProgressHandler(delegate(int Total, int Progress) { dlt.TasksTotal = Total; dlt.TasksComplete = Progress; dlt.CurrentSubtask = "Processes"; dlt.SubtasksComplete = mh.ChunksLoaded; dlt.SubtasksTotal = 200; if (mh.ChunksLoaded>200) { string ot = dlt.CurrentTask; Console.WriteLine("****SAVING****"); dlt.CurrentTask = "[Saving to avoid overusing RAM]"; (ActiveMdiChild as frmMap).Map.SaveAll(); dlt.CurrentTask = ot; } (ActiveMdiChild as frmMap).Map.CullUnchanged(); }); dlt.CurrentTask = "Gathering chunks needing light..."; mh.ForEachProgress += FEPH; List<string> chunks = new List<string>(); string tf = Path.GetTempFileName(); mh.ForEachChunk(delegate(IMapHandler _map,long X, long Y) { chunks.Add(string.Format("{0},{1}",X,Y)); //_map.RegenerateLighting(X, Y); }); File.WriteAllLines(tf, chunks.ToArray()); string args = "'" + Path.GetDirectoryName(mh.Filename) + Path.DirectorySeparatorChar + "' '"+tf+"'"; Process child = Process.Start("lightgen.exe", args); //child.WaitForInputIdle(); /* // Skylight dlt.CurrentTask = "Skylight..."; mh.ForEachProgress += FEPH; lighter.SkylightGlobal(ref mh); mh.SaveAll(); // Blocklight dlt.CurrentTask = "Relighting (BlockLight)..."; mh.ForEachProgress += FEPH; lighter.BlocklightGlobal(ref mh); mh.SaveAll(); */ (ActiveMdiChild as frmMap).Map = mh; dlt.Done(); }); (ActiveMdiChild as frmMap).Map.Autorepair = true; dlt.ShowDialog(); (ActiveMdiChild as frmMap).Map.Autorepair = false; MessageBox.Show("Lighting regenerated for "+dlt.TasksComplete+" chunks.", "Report"); //(ActiveMdiChild as frmMap).Enabled = true; (ActiveMdiChild as frmMap).ReloadAll(); ResetStatus(); } } }