Esempio n. 1
0
        private void btnRender_Click(object sender, EventArgs e)
        {
            var watch = new Stopwatch();

            watch.Start();
            if (terrain == null)
            {
                LoadData();
            }
            lbOutput.Items.Add($"Loading terrrain = {watch.ElapsedMilliseconds}");

            watch.Restart();
            var renderer = new TerrainRenderer();
            var images   = new Dictionary <Tuple <int, int>, Bitmap>();
            var tasks    = new List <Task>();


            foreach (var chunk in terrain)
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    images.Add(new Tuple <int, int>(chunk.X, chunk.Y),
                               renderer.RenderLayer(chunk, (int)numElevation.Value, (int)numDepth.Value));
                }));
            }
            Task.WaitAll(tasks.ToArray());

            CombineRenderedChunks(images);

            pictureBox1.Size  = renderedImage.Size;
            pictureBox1.Image = renderedImage;
            lbOutput.Items.Add($"Rendering terrrain = {watch.ElapsedMilliseconds}");
        }
Esempio n. 2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            var watch = new Stopwatch();

            watch.Start();
            if (terrain == null)
            {
                LoadData();
                lbOutput.Items.Add($"Loading terrrain = {watch.ElapsedMilliseconds}");
            }

            watch.Restart();
            var renderer = new TerrainRenderer();
            var images   = new Dictionary <Tuple <int, int>, Bitmap>();
            var tasks    = new List <Task>();

            var materialId = ((KeyValuePair <int, string>)cbSubstances.SelectedItem).Key;

            var minQuality = 0;

            if (!int.TryParse(txtMinQuality.Text, out minQuality))
            {
                return;
            }

            foreach (var chunk in terrain)
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    images.Add(new Tuple <int, int>(chunk.X, chunk.Y),
                               renderer.RenderSearchResults(chunk, (int)numElevation.Value, (int)numDepth.Value, materialId, minQuality));
                }));
            }
            Task.WaitAll(tasks.ToArray());

            CombineRenderedChunks(images);

            pictureBox1.Size  = renderedImage.Size;
            pictureBox1.Image = renderedImage;
            lbOutput.Items.Add($"Rendering terrrain = {watch.ElapsedMilliseconds}");
        }