Exemplo n.º 1
0
        private void generateTerrainToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ActiveMdiChild != null)
            {
                if ((ActiveMdiChild as frmMap).Map != null)
                {
                    dlgTerrainGen terragen = new dlgTerrainGen((ActiveMdiChild as frmMap).Map);
                    if(terragen.ShowDialog() == DialogResult.Cancel)
                    {
                        ResetStatus();
                        return;
                    }
                    DialogResult dr = MessageBox.Show("This could DELETE EVERYTHING. ARE YOU SURE?", "ARE YOU NUTS", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.No)
                    {
                        ResetStatus();
                        return;
                    }
                    IMapGenerator mg = (IMapGenerator)terragen.pgMapGen.SelectedObject;

                    (ActiveMdiChild as frmMap).Map.Generator = mg;
                    dlgLongTask dlt = new dlgLongTask();
                    dlt.Start(delegate()
                    {
                        // ACTIVATE AUTOREPAIR
                        (ActiveMdiChild as frmMap).Map.Autorepair = true;

                        /////////////////////////////////////////////////////////////////
                        // UI Stuff
                        /////////////////////////////////////////////////////////////////
                        dlt.SetMarquees(true, true);
                        dlt.VocabSubtask = "chunk";
                        dlt.VocabSubtasks = "chunks";
                        dlt.Title = "Generating chunks.";
                        dlt.Subtitle = "This will take a while.  Go take a break.";
                        dlt.SetMarquees(false, false);
                        dlt.CurrentTask = "Replacing stuff in chunks...";
                        dlt.TasksComplete = 0;
                        dlt.TasksTotal = 1;
                        dlt.SubtasksTotal = 1;

                        int numchunks = 0;
                        // Generate terrain
                        // Drop soil
                        // Add pbarriers
                        // Add dungeons
                        // Add trees
                        // Fix fluids
                        // Fix lava

                        int stage = 0;
                        int numstages = 1;
                        ForEachProgressHandler feph = new ForEachProgressHandler(delegate(int Total, int Progress)
                        {
                            numchunks = Total;
                            dlt.TasksTotal = numchunks * numstages;
                            dlt.TasksComplete = Progress + (stage * numchunks);
                            dlt.SubtasksComplete = Progress;
                            dlt.SubtasksTotal = Total;
                        });
                        ForEachProgressHandler fl_feph = new ForEachProgressHandler(delegate(int Total, int Progress)
                        {
                            numchunks = Total;
                            dlt.TasksTotal = numchunks * numstages;
                            dlt.TasksComplete = Progress + (stage * numchunks);
                            dlt.SubtasksComplete = Progress;
                            dlt.SubtasksTotal = Total;

                            dlt.perfChart.AddValue((ActiveMdiChild as frmMap).Map.ChunksLoaded);
                        });

                        Vector3i Max = new Vector3i(0,0,0);
                        Vector3i Min = new Vector3i(int.MaxValue, int.MaxValue, int.MaxValue);
                        dlt.CurrentTask = "Determining map scale...";
                        (ActiveMdiChild as frmMap).Map.ForEachProgress += feph;
                        dlt.ShowPerfChart(true);
                        dlt.perfChart.Clear();
                        dlt.perfChart.ScaleMode = SpPerfChart.ScaleMode.Relative;
                        (ActiveMdiChild as frmMap).Map.ForEachChunk(delegate(IMapHandler _mh, long X, long Z)
                        {
                            if (Min.X > X) Min.X = X;
                            if (Max.X < X) Max.X = X;
                            if (Min.Z > Z) Min.Z = Z;
                            if (Max.Z < Z) Max.Z = Z;
                            dlt.CurrentSubtask = string.Format("Map Scale: ({0},{1})", Max.X - Min.X, Max.Z - Min.Z);
                            _mh.SaveAll();
                        });

                        (ActiveMdiChild as frmMap).Map.Cache.Enabled = false;

                        int total = (int)((Max.X - Min.X) * (Max.Z - Min.Z));
                        int completed = 0;
                        (ActiveMdiChild as frmMap).Map.ForEachKnownChunk(0,delegate(IMapHandler _mh, long X, long Z)
                        {
                            if (dlt.STOP) return;
                            dlt.CurrentSubtask = string.Format("Generating chunk ({0},{1})", X, Z);
                            double min, max;
                            (ActiveMdiChild as frmMap).Map.Generate(X, Z, out min, out max);
                            dlt.grpPerformance.Text = string.Format("Terrain Profile [{0},{1}]m", (int)(min * 100), (int)(max * 100));
                            dlt.perfChart.AddValue((decimal)max);
                            feph(total, completed++);
                        });

                        if ((ActiveMdiChild as frmMap).Map.Generator.GenerateCaves)
                        {
                            dlt.CurrentTask = "Generating caves...";
                            dlt.grpPerformance.Text = "Generation time (ms)";
                            Random rand = new Random((int)(ActiveMdiChild as frmMap).Map.RandomSeed);
                            Profiler profCaves = new Profiler("Cave");
                            (ActiveMdiChild as frmMap).Map.ForEachKnownChunk(0, delegate(IMapHandler _mh, long X, long Z)
                            {
                                if (dlt.STOP) return;
                                dlt.CurrentSubtask = string.Format("Generating caves in chunk ({0},{1})", X, Z);
                                if (rand.Next(3) != 0)
                                {
                                    int xo = (int)(X * _mh.ChunkScale.X);
                                    int zo = (int)(Z * _mh.ChunkScale.Z);
                                    int x = rand.Next((int)_mh.ChunkScale.X - 1);
                                    int z = rand.Next((int)_mh.ChunkScale.Z - 1);
                                    int y = rand.Next((int)(_mh.GetHeightAt(x, z) * 127) + 5);
                                    profCaves.Start();
                                    new Cave(ref rand, ref _mh, new Vector3i(x + xo, y, z + zo));
                                    Console.WriteLine("LOLDONE");
                                    dlt.perfChart.AddValue(profCaves.Stop());
                                    feph(total, completed++);
                                }
                            });
                        }
                        completed = 0;
                        /*
                        Profiler profTrees = new Profiler("Trees");
                        for (int X = (int)Min.X; X < Max.X + 1; X++)
                        {
                            for (int Z = (int)Min.Z; Z < Max.Z + 1; Z++)
                            {
                                profTrees.Start();
                                if (dlt.STOP) return;
                                dlt.CurrentSubtask = string.Format("Adding trees to chunk ({0},{1})", X, Z);
                                (ActiveMdiChild as frmMap).Map.Populate(X, Z);
                                dlt.grpPerformance.Text = "Performance";
                                profTrees.Stop();
                                dlt.perfChart.AddValue(profTrees.Stop());
                                feph(total, completed++);
                            }
                        }
                        */
                        /*
                        stage++;
                        dlt.CurrentTask = "Eroding chunk surfaces...";
                        (ActiveMdiChild as frmMap).Map.ForEachProgress += feph;
                        (ActiveMdiChild as frmMap).Map.ForEachChunk(delegate(IMapHandler _mh, long X, long Y)
                        {
                            dlt.CurrentSubtask = string.Format("Eroding chunk ({0},{1}, thermal)", X, Y);
                            //(ActiveMdiChild as frmMap).Map.ErodeThermal(5, 10, (int)X, (int)Y);

                            dlt.CurrentSubtask = string.Format("Eroding chunk ({0},{1}, hydraulic)", X, Y);
                            //(ActiveMdiChild as frmMap).Map.Erode(5, 10, (int)X, (int)Y);

                            dlt.CurrentSubtask = string.Format("Eroding chunk ({0},{1}, silt)", X, Y);
                            //(ActiveMdiChild as frmMap).Map.Silt(63,true, (int)X, (int)Y);

                            dlt.grpPerformance.Text = string.Format("Chunks in-memory ({0})", _mh.ChunksLoaded);
                            dlt.perfChart.AddValue(_mh.ChunksLoaded);
                        });
                        */

                        dlt.CurrentSubtask = "SAVING CHUNKS";
                        (ActiveMdiChild as frmMap).Map.SaveAll();
                        dlt.SetMarquees(false,false);
                        dlt.Done();
                        ClearReport();
                        (ActiveMdiChild as frmMap).Map.Time = 0;
                        //Utils.FixPlayerPlacement(ref (ActiveMdiChild as frmMap).Map);
                        (ActiveMdiChild as frmMap).Map.Save();

                        (ActiveMdiChild as frmMap).Map.Cache.Enabled = true;

                        MessageBox.Show("Done.  Keep in mind that loading may initially be slow.");

                        // DEACTIVATE AUTOREPAIR
                        (ActiveMdiChild as frmMap).Map.Autorepair = false;
                    });
                    dlt.ShowDialog();
                }
            }
        }
Exemplo n.º 2
0
        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();
                }
            }
        }
Exemplo n.º 3
0
 public abstract int ExpandFluids(byte fluidID, bool CompleteRegen, ForEachProgressHandler ph);
Exemplo n.º 4
0
		public int ExpandFluids(byte fluidID, bool CompleteRegen, ForEachProgressHandler ph)
		{
			int bc = 0; // Whether the water map has changed.
			ForEachProgress += ph;
			UnloadChunks();
			ForEachChunk(delegate(long X, long Y)
			{
				BeginTransaction();
				Chunk tc = GetChunk(X, Y);
				if (tc == null) return;
				int xm = (int)tc.Size.X - 1;
				int ym = (int)tc.Size.Y - 1;
				int zm = (int)tc.Size.Z - 1;
				for (int _z = 0; _z < (int)tc.Size.Z; _z++)
				{
					for (int _x = 0; _x < (int)tc.Size.X; _x++)
					{
						for (int _y = 0; _y < (int)tc.Size.Y; _y++)
						{
							int x = _x + (int)(X * ChunkScale.X);
							int y = _y + (int)(Y * ChunkScale.Y);
							int z = _z;
							// If this block is air, and a block in any neighborly position except downwards is fluidID...
							if (GetBlockAt(x, y, z) == 0)
							{
								bool w = false;
								if (GetBlockAt(x + 1, y, z) == fluidID)
									w = true;
								else if (GetBlockAt(x - 1, y, z) == fluidID)
									w = true;
								if (GetBlockAt(x, y + 1, z) == fluidID)
									w = true;
								else if (GetBlockAt(x, y - 1, z) == fluidID)
									w = true;
								else if (z < zm && GetBlockAt(x, y, z + 1) == fluidID)
									w = true;
								if (w)
								{
									SetBlockAt(x, y, z, fluidID);
									++bc;
								}
							}
						}
					}
				}
				// Go backwards to help reduce block expansion time.
				for (int _z = (int)tc.Size.Z - 1; _z > 0; _z--)
				{
					for (int _x = (int)tc.Size.X - 1; _x > 0; _x--)
					{
						for (int _y = (int)tc.Size.Y - 1; _y > 0; _y--)
						{
							int x = _x + (int)(X * ChunkScale.X);
							int y = _y + (int)(Y * ChunkScale.Y);
							int z = _z;
							// If this block is air, and a block in any neighborly position except downwards is fluidID...
							if (GetBlockAt(x, y, z) == 0)
							{
								bool w = false;
								if (GetBlockAt(x + 1, y, z) == fluidID)
									w = true;
								else if (GetBlockAt(x - 1, y, z) == fluidID)
									w = true;
								if (GetBlockAt(x, y + 1, z) == fluidID)
									w = true;
								else if (GetBlockAt(x, y - 1, z) == fluidID)
									w = true;
								else if (z < zm && GetBlockAt(x, y, z + 1) == fluidID)
									w = true;
								if (w)
								{
									SetBlockAt(x, y, z, fluidID);
									++bc;
								}
							}
						}
					}
				}
				CommitTransaction();
			});
			return bc;
		}
Exemplo n.º 5
0
 public override int ExpandFluids(byte fluidID, bool CompleteRegen, ForEachProgressHandler ph)
 {
     int total = 0;
     int chunksProcessed=0;
     ForEachChunk(delegate(IMapHandler mh, long X, long Z)
     {
         total += ExpandFluids(X, Z, fluidID, CompleteRegen);
         ph(-1, ++chunksProcessed);
     });
     return total;
 }
Exemplo n.º 6
0
 public abstract int ExpandFluids(byte fluidID, bool CompleteRegen, ForEachProgressHandler ph);