public TValue this[GBTCorner key] { get { return(GetValue(key)); } set { SetValue(key, value); } }
private bool CheckValidAdjacent(RiverNode node, GBTCorner adjacent, MapArray <int> bitmask, Dictionary <GBTCorner, RiverNode> node_lookup) { bool result = true; result = result && ((bitmask[adjacent] & 2) < 2); result = result && (node.Downslope == null || node.Downslope.Vertex != adjacent); result = result && (!node_lookup.ContainsKey(adjacent)); return(result); }
public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } else { GBTCorner b = (GBTCorner)obj; return(this == b); } }
public List <GBTCorner> GetAdjacent() { var result = new List <GBTCorner>(); for (int i = 0; i < 3; i++) { GBTCorner corner = _Adjacent[i + 3 * ((_value & Left) >> 29)]; GBTHex new_hex = new GBTHex(_value & HexMask) + new GBTHex(corner._value & HexMask); result.Add(new GBTCorner(new_hex, ((corner._value & Left) > 0 ? CornerDirection.L : CornerDirection.R))); } return(result); }
public TValue GetValue(GBTCorner key) { TValue output; if (corner_data.TryGetValue(key, out output)) { return(output); } else { return(default_value); } }
private void TriangulateHex(GBTHex hex, Color[] colors) { if (colors == null) { return; } Vector2 center = hex.position; var corners = hex.GetCorners(); for (int i = 0; i < corners.Count; i++) { int inext = (i + 1) % 6; GBTCorner first = corners[i]; GBTCorner second = corners[inext]; CreateTriangle(center, colors[0], second.position, colors[inext + 1], first.position, colors[i + 1]); } }
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); }
public RiverNode(GBTCorner vert) { vertex = vert; width = -1.0f; downslope = left = right = null; }
public void SetValue(GBTCorner key, TValue value) { corner_data[key] = value; }