Esempio n. 1
0
        /// <summary>
        /// Removes a GraphNode from the Graph and also removes all the associated links to and from other
        /// GraphNode objects in this Graph.
        /// </summary>
        /// <param name="node">The GraphNode to remove.</param>
        public void RemoveTempNode(GraphNode node)
        {
            Cluster cluster = GetClusterAtPosition(node.pPosition);

            if (null != cluster)
            {
                for (Int32 i = 0; i < cluster.pNodes.Count; i++)
                {
                    if (node != cluster.pNodes[i])
                    {
                        UnlinkGraphNodes(node, cluster.pNodes[i]);
                    }
                }

                cluster.RemoveNode(node);
            }

            //DebugCheckForReferences(node);
            mNodeFactory.RecycleNode(node);
            RemoveNode(node);

            //DebugCheckNodes();
        }
Esempio n. 2
0
        /// <summary>
        /// Nasty little function which essentially removes a Cluster's nodes and any links associated
        /// with them. Things get complicated with the fact that adjecent Clusters have GraphNode in them
        /// which link back to GraphNode in this Cluster, which need to be cleaned up, and sometimes completely
        /// removed. The method handles it all.
        /// </summary>
        /// <param name="cluster"></param>
        private void ClearCluster(Cluster cluster)
        {
            if (null != cluster)
            {
                // Loop through every node in the cluster cleaning up its links to other nodes
                // as we go.
                for (Int32 i = cluster.pNodes.Count - 1; i >= 0; i--)
                {
                    GraphNode node = cluster.pNodes[i];

                    // Loop through all the neighbours removing the links as we go.
                    for (Int32 j = node.pNeighbours.Count - 1; j >= 0; j--)
                    {
                        GraphNode neighbourNode = node.pNeighbours[j].mGraphNode;

                        // Since this is in the cluster being regenerated, all links to other nodes
                        // should be removed; this node/cluster isn't going to exist in a moment.
                        UnlinkGraphNodes(node, neighbourNode);

                        //
                        // Next comes the convoluted process for checking if the GraphNode just unlinked
                        // actually lives in another cluster, and if so, possibly removing that GraphNode
                        // as well, but only in the case where the neighbour ONLY links to GraphNodes 
                        // within its own Cluster (remember we already removed the link to the cluster we 
                        // are destroying. In the case where it links out to another Cluster, that node 
                        // still has some purpose, so it shouldn't be removed; just the links to the
                        // Cluster being destroyed.
                        //

                        Cluster neighbourCluster = GetClusterAtPosition(neighbourNode.pPosition);

                        // Is this a GraphNode that lives in a Cluster outside the one being cleared?
                        if (neighbourCluster != cluster)
                        {
                            // Search through all the neighbours trying to find one that is in a different Cluster,
                            // signifying that this GraphNode needs to live on. Remember that nodes in corners can
                            // be linked to multiple adjacent Clusters.
                            Boolean foundOther = false;

                            for (Int32 k = neighbourNode.pNeighbours.Count - 1; k >= 0; k--)
                            {
                                // Slicks naming...
                                GraphNode otherNeighbourNode = neighbourNode.pNeighbours[k].mGraphNode;

                                Cluster otherNeighbourCluster = GetClusterAtPosition(otherNeighbourNode.pPosition);

                                // If the neighbour lives outside this Cluster than we don't want to remove the current
                                // neighbour being evaluated.
                                if (otherNeighbourCluster != neighbourCluster)
                                {
                                    foundOther = true;
                                    break;
                                }
                            }

                            if (!foundOther)
                            {
                                // Now loop through all the neighbours AGAIN, this time removing all links between the
                                // GraphNode about to be removed, and all the others that will live on.
                                for (Int32 k = neighbourNode.pNeighbours.Count - 1; k >= 0; k--)
                                {
                                    GraphNode otherNeighbourNode = neighbourNode.pNeighbours[k].mGraphNode;

                                    UnlinkGraphNodes(neighbourNode, otherNeighbourNode);
                                }

                                // Remove this neighbour from the Graph objects.
                                //DebugCheckForReferences(neighbourNode);

                                mNodeFactory.RecycleNode(neighbourNode);
                                RemoveNode(neighbourNode);
                                neighbourCluster.RemoveNode(neighbourNode);
                            }
                        }
                    }

                    // If this is a temporary node it should not be removed from the Graph because it will not
                    // be automatically re-added. It still gets all the links removed because those WILL be 
                    // automatically generated.
                    if (!(node as NavMeshTileGraphNode).pIsTemporary)
                    {
                        //DebugCheckForReferences(node);
                        mNodeFactory.RecycleNode(node);
                        RemoveNode(node);
                        cluster.RemoveNode(node);
                    }
                }
            }

            //DebugCheckNodes();
        }
Esempio n. 3
0
        /// <summary>
        /// Nasty little function which essentially removes a Cluster's nodes and any links associated
        /// with them. Things get complicated with the fact that adjecent Clusters have GraphNode in them
        /// which link back to GraphNode in this Cluster, which need to be cleaned up, and sometimes completely
        /// removed. The method handles it all.
        /// </summary>
        /// <param name="cluster"></param>
        private void ClearCluster(Cluster cluster)
        {
            if (null != cluster)
            {
                // Loop through every node in the cluster cleaning up its links to other nodes
                // as we go.
                for (Int32 i = cluster.pNodes.Count - 1; i >= 0; i--)
                {
                    GraphNode node = cluster.pNodes[i];

                    // Loop through all the neighbours removing the links as we go.
                    for (Int32 j = node.pNeighbours.Count - 1; j >= 0; j--)
                    {
                        GraphNode neighbourNode = node.pNeighbours[j].mGraphNode;

                        // Since this is in the cluster being regenerated, all links to other nodes
                        // should be removed; this node/cluster isn't going to exist in a moment.
                        UnlinkGraphNodes(node, neighbourNode);

                        //
                        // Next comes the convoluted process for checking if the GraphNode just unlinked
                        // actually lives in another cluster, and if so, possibly removing that GraphNode
                        // as well, but only in the case where the neighbour ONLY links to GraphNodes
                        // within its own Cluster (remember we already removed the link to the cluster we
                        // are destroying. In the case where it links out to another Cluster, that node
                        // still has some purpose, so it shouldn't be removed; just the links to the
                        // Cluster being destroyed.
                        //

                        Cluster neighbourCluster = GetClusterAtPosition(neighbourNode.pPosition);

                        // Is this a GraphNode that lives in a Cluster outside the one being cleared?
                        if (neighbourCluster != cluster)
                        {
                            // Search through all the neighbours trying to find one that is in a different Cluster,
                            // signifying that this GraphNode needs to live on. Remember that nodes in corners can
                            // be linked to multiple adjacent Clusters.
                            Boolean foundOther = false;

                            for (Int32 k = neighbourNode.pNeighbours.Count - 1; k >= 0; k--)
                            {
                                // Slicks naming...
                                GraphNode otherNeighbourNode = neighbourNode.pNeighbours[k].mGraphNode;

                                Cluster otherNeighbourCluster = GetClusterAtPosition(otherNeighbourNode.pPosition);

                                // If the neighbour lives outside this Cluster than we don't want to remove the current
                                // neighbour being evaluated.
                                if (otherNeighbourCluster != neighbourCluster)
                                {
                                    foundOther = true;
                                    break;
                                }
                            }

                            if (!foundOther)
                            {
                                // Now loop through all the neighbours AGAIN, this time removing all links between the
                                // GraphNode about to be removed, and all the others that will live on.
                                for (Int32 k = neighbourNode.pNeighbours.Count - 1; k >= 0; k--)
                                {
                                    GraphNode otherNeighbourNode = neighbourNode.pNeighbours[k].mGraphNode;

                                    UnlinkGraphNodes(neighbourNode, otherNeighbourNode);
                                }

                                // Remove this neighbour from the Graph objects.
                                //DebugCheckForReferences(neighbourNode);

                                mNodeFactory.RecycleNode(neighbourNode);
                                RemoveNode(neighbourNode);
                                neighbourCluster.RemoveNode(neighbourNode);
                            }
                        }
                    }

                    // If this is a temporary node it should not be removed from the Graph because it will not
                    // be automatically re-added. It still gets all the links removed because those WILL be
                    // automatically generated.
                    if (!(node as NavMeshTileGraphNode).pIsTemporary)
                    {
                        //DebugCheckForReferences(node);
                        mNodeFactory.RecycleNode(node);
                        RemoveNode(node);
                        cluster.RemoveNode(node);
                    }
                }
            }

            //DebugCheckNodes();
        }