Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 public void KillSuperNode(SuperNode node, VoxelGraph graph)
 {
     if (SuperNodes[node].Length <= node.GridSize)
     {
         graph.MarkDirty(this);
     }
     SuperNodes.Remove(node);
     foreach (var neighbour in GetNeighbours())
     {
         if (neighbour.To.SuperNodes.ContainsKey(node))
         {
             neighbour.To.KillSuperNode(node, graph);
         }
     }
 }
Exemplo n.º 3
0
        private void RecalculateSuperNodePathAfterDeleteRec(SuperNode superNode, VoxelGraph graph)
        {
            var   neighbours = GetNeighbours().Where(n => n.To.SuperNodes.ContainsKey(superNode));
            float length     = 0;
            Edge  closest    = null;

            foreach (var neighbour in neighbours)
            {
                var curDist = neighbour.Length + neighbour.To.SuperNodes[superNode].Length;
                if (closest == null)
                {
                    closest = neighbour;
                    length  = curDist;
                }
                else if (length > curDist)
                {
                    closest = neighbour;
                    length  = curDist;
                }
            }
            if (closest == null || closest.To.Equals(SuperNodes[superNode].To))
            {
                if (SuperNodes[superNode].Length.Equals(length))
                {
                    return;
                }
                SuperNodes[superNode].Length = length;
            }
            else
            {
                SuperNodes.Remove(superNode);
                ConnectSuperNode(closest.To, superNode, length);
                foreach (var neighbour in GetNeighbours().Where(ne => ne.To.SuperNodes.ContainsKey(superNode) && Equals(ne.To.SuperNodes[superNode].To)))
                {
                    neighbour.To.RecalculateSuperNodePathAfterDeleteRec(superNode, graph);
                }
            }
            if (length >= superNode.GridSize)
            {
                graph.MarkDirty(this);
            }
        }