Example #1
0
    private float GetLandMaskValue(Vector2 position, Simplex2D noise)
    {
        float noise_val = noise.GetFractalNoise(2.0f * position / Radius);
        float r         = position.magnitude / Radius;

        if (noise_val > max_noise_value)
        {
            max_noise_value = noise_val;
        }
        return((noise_val * (1.0f - Alpha) + noise_val * Alpha / r) * (1.0f - Mathf.Pow(Utils.Smoothstep(r / 2.0f), 5.0f)));
    }
Example #2
0
    private List <RiverNode> GenerateDownslopes(MapArray <int> bitmask)
    {
        var simplex = new Simplex2D(52562);

        MapArray <float> weights = new MapArray <float>(1000.0f);
        var rivernet             = new List <RiverNode>();
        var node_lookup          = new Dictionary <GBTCorner, RiverNode>();
        var queue = new BinaryMinHeap <QueueElement <RiverNode> >();

        // Assign weights to each land vertex and add coast vertices to the queue.
        foreach (KeyValuePair <GBTCorner, int> kvp in bitmask.GetCornerEnumerator())
        {
            if ((kvp.Value & 1) > 0)
            {
                weights[kvp.Key] = simplex.GetFractalNoise(4.0f * kvp.Key.position / Radius);
                if ((kvp.Value & 2) > 0)
                {
                    RiverNode node = new RiverNode(kvp.Key);
                    queue.Push(new QueueElement <RiverNode>(weights[kvp.Key], node));
                    rivernet.Add(node);
                    node_lookup[kvp.Key] = node;
                }
            }
        }

        while (queue.Count > 0)
        {
            RiverNode node = queue.Pop().value;

            GBTCorner lowest        = new GBTCorner(-1);
            float     lowest_weight = 999.0f;

            // Find the neighboring land node with the lowest weight which has not already
            // been added to the network.
            foreach (GBTCorner adjacent in node.Vertex.GetAdjacent())
            {
                if (CheckValidAdjacent(node, adjacent, bitmask, node_lookup) && weights[adjacent] < lowest_weight)
                {
                    lowest_weight = weights[adjacent];
                    lowest        = adjacent;
                }
            }

            // Add the lowest node to the network, and push it and the into the queue.
            if (lowest.isValid())
            {
                var new_node = new RiverNode(lowest);
                new_node.Downslope = node;
                if (node.Left == null)
                {
                    node.Left = new_node;
                    // If the node hasn't been filled, add it to the queue again, but with a lower weight.
                    weights[node.Vertex] += 0.05f;
                    queue.Push(new QueueElement <RiverNode>(weights[node.Vertex], node));
                }
                else if (node.Right == null)
                {
                    node.Right = new_node;
                }
                node_lookup[lowest] = new_node;
                queue.Push(new QueueElement <RiverNode>(weights[lowest], new_node));
            }
        }

        return(rivernet);
    }