Esempio n. 1
0
        // Worker thread from Generate Button
        private void MapGenerationWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MapCrafter craft = e.Argument as MapCrafter;

            mapGenerationWorker.ReportProgress(0, "Initializing Minecraft Realm...");
            craft.initializeMinecraftWorld();
            mapGenerationWorker.ReportProgress(0, "Loading Dorf Maps...");
            craft.loadDwarfMaps();
            totalChunks = (MapCrafter.getChunkFinishX() - MapCrafter.getChunkStartX()) *
                          (MapCrafter.getChunkFinishY() - MapCrafter.getChunkStartY());
            doneChunks = 0;
            Stopwatch watch    = Stopwatch.StartNew();
            Stopwatch unitTime = new Stopwatch();



            /*
             * for (int xi = MapCrafter.getChunkStartX(); xi < MapCrafter.getChunkFinishX(); xi++)
             * {
             *  for (int zi = MapCrafter.getChunkStartY(); zi < MapCrafter.getChunkFinishY(); zi++)
             *  {
             *      // This scales the dimensions based off the blocksPerEmbarkTile [1..8]
             *      double xMin = ((xi * 16.0 / (double)Settings.Default.blocksPerEmbarkTile) + Settings.Default.mapCenterX);
             *      double xMax = (((xi + 1) * 16.0 / (double)Settings.Default.blocksPerEmbarkTile) + Settings.Default.mapCenterX);
             *      double yMin = ((zi * 16.0 / (double)Settings.Default.blocksPerEmbarkTile) + Settings.Default.mapCenterY);
             *      double yMax = (((zi + 1) * 16.0 / (double)Settings.Default.blocksPerEmbarkTile) + Settings.Default.mapCenterY);
             *      // craft.generateInternalMapChunk(xMin, xMax, yMin, yMax);
             *
             *  }
             * }
             */

            for (int xi = MapCrafter.getChunkStartX(); xi < MapCrafter.getChunkFinishX(); xi++)
            {
                for (int zi = MapCrafter.getChunkStartY(); zi < MapCrafter.getChunkFinishY(); zi++)
                {
                    if (mapGenerationWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }
                    unitTime.Restart();
                    craft.generateSingleChunk(xi, zi);
                    doneChunks++;
                    TimeSpan elapsedTime   = watch.Elapsed;
                    TimeSpan remainingTime = TimeSpan.FromTicks(elapsedTime.Ticks / doneChunks * (totalChunks - doneChunks));
                    double   speed         = 1000 / unitTime.ElapsedMilliseconds;
                    mapGenerationWorker.ReportProgress((doneChunks * 1000) / totalChunks, "Done " + doneChunks + " out of " + totalChunks + " Minecraft chunks at " + speed + " chunks per second. " + remainingTime.ToString(@"hh\:mm\:ss") + " left.");
                }
                if (mapGenerationWorker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
            }
            craft.saveMinecraftWorld();
        }
Esempio n. 2
0
        private void MapGenerationWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MapCrafter craft = e.Argument as MapCrafter;

            mapGenerationWorker.ReportProgress(0, "Initializing Minecraft Realm...");
            craft.initializeMinecraftWorld();
            mapGenerationWorker.ReportProgress(0, "Loading Dorf Maps...");
            craft.loadDwarfMaps();
            totalChunks = (MapCrafter.getChunkFinishX() - MapCrafter.getChunkStartX()) *
                          (MapCrafter.getChunkFinishY() - MapCrafter.getChunkStartY());
            doneChunks = 0;
            Stopwatch watch    = Stopwatch.StartNew();
            Stopwatch unitTime = new Stopwatch();

            for (int xi = MapCrafter.getChunkStartX(); xi < MapCrafter.getChunkFinishX(); xi++)
            {
                for (int zi = MapCrafter.getChunkStartY(); zi < MapCrafter.getChunkFinishY(); zi++)
                {
                    if (mapGenerationWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }
                    unitTime.Restart();
                    craft.generateSingleChunk(xi, zi);
                    doneChunks++;
                    TimeSpan elapsedTime   = watch.Elapsed;
                    TimeSpan remainingTime = TimeSpan.FromTicks(elapsedTime.Ticks / doneChunks * (totalChunks - doneChunks));
                    double   speed         = 1000 / unitTime.ElapsedMilliseconds;
                    mapGenerationWorker.ReportProgress((doneChunks * 1000) / totalChunks, "Done " + doneChunks + " out of " + totalChunks + " Minecraft chunks at " + speed + " chunks per second. " + remainingTime.ToString(@"hh\:mm\:ss") + " left.");
                }
                if (mapGenerationWorker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
            }
            craft.saveMinecraftWorld();
        }