Exemplo n.º 1
0
    public void GenerateMap()
    {
        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        Color[,] map;

        if (randSeed)
        {
            seed = System.DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString();
        }

        // IPerlinLayer blue = new BasePerlinLayer(fill, frequency, octaves, octaveFreqMultiplier, octaveAmpMultiplier, "hello world");
        IPerlinLayer red = new BasePerlinLayer(fill, frequency, octaves, octaveFreqMultiplier, octaveAmpMultiplier, seed);
        // IPerlinLayer green = new CompositePerlinLayer(blue, red, PerlinOperation.Intersection);

        PerlinMap <Color> perlinMap = new PerlinMap <Color>(Color.black, red, Color.white);

        // perlinMap.AddLayer(blue, Color.blue);
        // perlinMap.AddLayer(red, Color.red);

        stopwatch.Start();
        map = perlinMap.GetCells(0, 0, width, height);
        stopwatch.Stop();
        genTimeText.text = string.Format("Generated {0} cells in {1}ms.", width * height, stopwatch.ElapsedMilliseconds == 0 ? "<1" : stopwatch.ElapsedMilliseconds.ToString());

        if (perlinVisualizer != null)
        {
            perlinVisualizer.SetMap(map);
        }
    }
Exemplo n.º 2
0
    public void GenerateMap()
    {
        // Refresh all layers. Inefficient, only need to refresh comp layers that use a base layer that changed.
        foreach (IPerlinLayerController layer in layers.Values)
        {
            layer.RefreshLayer();
        }

        int width  = (int)widthSlider.value;
        int height = (int)heightSlider.value;

        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        Color[,] map;

        // Create PerlinMap with its layers.
        PerlinMap <Color> perlinMap = new PerlinMap <Color>(Color.black);

        layerOrder.ForEach(layerName => {
            IPerlinLayerController controller = layers[layerName];
            if (!controller.IsVisible())
            {
                return;
            }
            perlinMap.AddLayer(controller.GetLayer(), controller.GetValue());
        });

        stopwatch.Start();
        map = perlinMap.GetCells(0, 0, width, height);
        stopwatch.Stop();
        genTimeText.text = string.Format("Generated {0} cells in {1}ms.", width * height, stopwatch.ElapsedMilliseconds == 0 ? "<1" : stopwatch.ElapsedMilliseconds.ToString());

        visualizer.SetMap(map);
    }