Exemplo n.º 1
0
        public void ConnectSuperNode(Node from, SuperNode superNode, float dist)
        {
            var directChild = dist <= superNode.GridSize;

            if (SuperNodes.ContainsKey(superNode))
            {
                if (SuperNodes[superNode].Length <= dist)
                {
                    return;
                }
            }
            else
            {
                if (directChild)
                {
                    superNode.ChildNodes.Add(this);
                }
            }
            SuperNodes[superNode] = new SuperNodeConnection(from, superNode, dist);
            if (directChild)
            {
                foreach (var snode in SuperNodes.Keys)
                {
                    if (snode == superNode || SuperNodes[snode].Length > superNode.GridSize)
                    {
                        continue;
                    }
                    snode.ConnectTo(superNode, dist, from);
                }
            }
        }
Exemplo n.º 2
0
        public bool RecalculateSuperNodePathAfterDelete(SuperNode superNode, VoxelGraph graph)
        {
            SuperNodeConnection old = null;

            if (SuperNodes.ContainsKey(superNode))
            {
                old = SuperNodes[superNode];
                SuperNodes.Remove(superNode);
            }
            var neighbours = GetNeighbours().Where(n => n.To.SuperNodes.ContainsKey(superNode)).ToList();
            var queue      = new PriorityQueue <Edge>();

            foreach (var neighbour in neighbours)
            {
                queue.Enqueue(neighbour, neighbour.To.SuperNodes[superNode].Length + neighbour.Length);
            }
            while (!queue.IsEmpty())
            {
                var n = queue.Dequeue();
                if (!n.To.SuperNodes.ContainsKey(superNode))
                {
                    continue;
                }
                if (Equals(n.To.SuperNodes[superNode].To))
                {
                    if (n.To.RecalculateSuperNodePathAfterDelete(superNode, graph))
                    {
                        queue.Enqueue(n, n.To.SuperNodes[superNode].Length + n.Length);
                    }
                }
                else
                {
                    var dist = n.Length + n.To.SuperNodes[superNode].Length;
                    if (old != null && old.To.Equals(n.To) && old.Length.Equals(dist))
                    {
                        ConnectSuperNode(n.To, superNode, dist);
                    }
                    else
                    {
                        ConnectSuperNode(n.To, superNode, dist);
                        graph.MarkDirty(this);
                        foreach (var neighbour in GetNeighbours().Where(ne => ne.To.SuperNodes.ContainsKey(superNode) && Equals(ne.To.SuperNodes[superNode].To)))
                        {
                            neighbour.To.RecalculateSuperNodePathAfterDeleteRec(superNode, graph);
                        }
                    }
                    return(true);
                }
            }
            graph.MarkDirty(this);
            superNode.RemoveChildNode(this);
            return(false);
        }