Example #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()
                    {
                        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;

                        (ActiveMdiChild as frmMap).Map.ForEachProgress +=new ForEachProgressHandler(delegate(int Total, int Progress){
                            dlt.TasksTotal = Total;
                            dlt.TasksComplete = Progress;
                        });
                        (ActiveMdiChild as frmMap).Map.ForEachChunk(delegate(long X, long Y)
                        {
                            if (dlt.STOP) return;
                            dlt.SubtasksComplete = 0;
                            dlt.CurrentSubtask = string.Format("Generating chunk ({0},{1})", X, Y);
                            (ActiveMdiChild as frmMap).Map.Generate((ActiveMdiChild as frmMap).Map, X, Y);
                            dlt.SubtasksComplete = 1;
                        });
                        dlt.CurrentTask = "Fixing fluids, may take a while...";
                        dlt.SubtasksTotal = 2;
                        dlt.SubtasksComplete = 0;
                        IMapHandler mh = (ActiveMdiChild as frmMap).Map;
                        dlt.CurrentSubtask = "Fixing water...";
                        int hurr = 1;
                        int hurrT = 0;
                        int passes = 0;
                        while (hurr != 0)
                        {
                            passes++;
                            dlt.CurrentSubtask = string.Format("Fixing water (Pass #{0}, {1} blocks added)...", passes, hurrT);
                            hurr = mh.ExpandFluids(09, false, delegate(int Total,int Complete){
                                dlt.SubtasksTotal = Total;
                                dlt.SubtasksComplete = Complete;
                            });
                            hurrT += hurr;
                        }
                        dlt.SubtasksComplete++;
                        dlt.CurrentSubtask = "Fixing lava...";
                        passes = 0;
                        hurrT = 0;
                        hurr = 1;
                        while (hurr != 0)
                        {
                            passes++;
                            dlt.CurrentSubtask = string.Format("Fixing lava ({0} passes, {1} blocks added)...", passes, hurrT);
                            hurr = mh.ExpandFluids(11, false, delegate(int Total, int Complete)
                            {
                                dlt.SubtasksTotal = Total;
                                dlt.SubtasksComplete = Complete;
                            });
                            hurrT += hurr;
                        }
                        dlt.SubtasksComplete++;
                        (ActiveMdiChild as frmMap).Map = mh;
                        dlt.Done();
                        MessageBox.Show("Done.  Keep in mind that loading may initially be slow.");
                    });
                    dlt.ShowDialog();
                }
            }
        }
Example #2
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();
                }
            }
        }