ContainsConnection() public method

public ContainsConnection ( GraphNode node ) : bool
node GraphNode
return bool
示例#1
0
        /// <summary>
        /// Updates an area in the list graph.
        /// Recalculates possibly affected connections, i.e all connectionlines passing trough the bounds of the guo will be recalculated
        /// </summary>
        void IUpdatableGraph.UpdateArea(GraphUpdateObject guo)
        {
            if (nodes == null)
            {
                return;
            }

            for (int i = 0; i < nodeCount; i++)
            {
                var node = nodes[i];
                if (guo.bounds.Contains((Vector3)node.position))
                {
                    guo.WillUpdateNode(node);
                    guo.Apply(node);
                }
            }

            if (guo.updatePhysics)
            {
                // Use a copy of the bounding box, we should not change the GUO's bounding box since it might be used for other graph updates
                Bounds bounds = guo.bounds;

                if (thickRaycast)
                {
                    // Expand the bounding box to account for the thick raycast
                    bounds.Expand(thickRaycastRadius * 2);
                }

                // Create a temporary list used for holding connection data
                List <Connection> tmpList = Pathfinding.Util.ListPool <Connection> .Claim();

                for (int i = 0; i < nodeCount; i++)
                {
                    PointNode node    = nodes[i];
                    var       nodePos = (Vector3)node.position;

                    List <Connection> conn = null;

                    for (int j = 0; j < nodeCount; j++)
                    {
                        if (j == i)
                        {
                            continue;
                        }

                        var otherNodePos = (Vector3)nodes[j].position;
                        // Check if this connection intersects the bounding box.
                        // If it does we need to recalculate that connection.
                        if (VectorMath.SegmentIntersectsBounds(bounds, nodePos, otherNodePos))
                        {
                            float     dist;
                            PointNode other           = nodes[j];
                            bool      contains        = node.ContainsConnection(other);
                            bool      validConnection = IsValidConnection(node, other, out dist);

                            // Fill the 'conn' list when we need to change a connection
                            if (conn == null && (contains != validConnection))
                            {
                                tmpList.Clear();
                                conn = tmpList;
                                conn.AddRange(node.connections);
                            }

                            if (!contains && validConnection)
                            {
                                // A new connection should be added
                                uint cost = (uint)Mathf.RoundToInt(dist * Int3.FloatPrecision);
                                conn.Add(new Connection(other, cost));
                                RegisterConnectionLength((other.position - node.position).sqrMagnitudeLong);
                            }
                            else if (contains && !validConnection)
                            {
                                // A connection should be removed
                                for (int q = 0; q < conn.Count; q++)
                                {
                                    if (conn[q].node == other)
                                    {
                                        conn.RemoveAt(q);
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    // Save the new connections if any were changed
                    if (conn != null)
                    {
                        node.connections = conn.ToArray();
                        node.SetConnectivityDirty();
                    }
                }

                // Release buffers back to the pool
                Pathfinding.Util.ListPool <Connection> .Release(ref tmpList);
            }
        }
示例#2
0
        /** Updates an area in the list graph.
         * Recalculates possibly affected connections, i.e all connectionlines passing trough the bounds of the \a guo will be recalculated
         * \astarpro */
        public void UpdateArea(GraphUpdateObject guo)
        {
            if (nodes == null)
            {
                return;
            }

            for (int i = 0; i < nodeCount; i++)
            {
                if (guo.bounds.Contains((Vector3)nodes[i].position))
                {
                    guo.WillUpdateNode(nodes[i]);
                    guo.Apply(nodes[i]);
                }
            }

            if (guo.updatePhysics)
            {
                //Use a copy of the bounding box, we should not change the GUO's bounding box since it might be used for other graph updates
                Bounds bounds = guo.bounds;

                if (thickRaycast)
                {
                    //Expand the bounding box to account for the thick raycast
                    bounds.Expand(thickRaycastRadius * 2);
                }

                //Create two temporary arrays used for holding new connections and costs
                List <GraphNode> tmp_arr = Pathfinding.Util.ListPool <GraphNode> .Claim();

                List <uint> tmp_arr2 = Pathfinding.Util.ListPool <uint> .Claim();

                for (int i = 0; i < nodeCount; i++)
                {
                    PointNode node = nodes[i];
                    var       a    = (Vector3)node.position;

                    List <GraphNode> conn  = null;
                    List <uint>      costs = null;

                    for (int j = 0; j < nodeCount; j++)
                    {
                        if (j == i)
                        {
                            continue;
                        }

                        var b = (Vector3)nodes[j].position;
                        if (VectorMath.SegmentIntersectsBounds(bounds, a, b))
                        {
                            float     dist;
                            PointNode other           = nodes[j];
                            bool      contains        = node.ContainsConnection(other);
                            bool      validConnection = IsValidConnection(node, other, out dist);

                            if (!contains && validConnection)
                            {
                                // A new connection should be added

                                if (conn == null)
                                {
                                    tmp_arr.Clear();
                                    tmp_arr2.Clear();
                                    conn  = tmp_arr;
                                    costs = tmp_arr2;
                                    conn.AddRange(node.connections);
                                    costs.AddRange(node.connectionCosts);
                                }

                                uint cost = (uint)Mathf.RoundToInt(dist * Int3.FloatPrecision);
                                conn.Add(other);
                                costs.Add(cost);
                            }
                            else if (contains && !validConnection)
                            {
                                // A connection should be removed

                                if (conn == null)
                                {
                                    tmp_arr.Clear();
                                    tmp_arr2.Clear();
                                    conn  = tmp_arr;
                                    costs = tmp_arr2;
                                    conn.AddRange(node.connections);
                                    costs.AddRange(node.connectionCosts);
                                }

                                int p = conn.IndexOf(other);

                                //Shouldn't have to check for it, but who knows what might go wrong
                                if (p != -1)
                                {
                                    conn.RemoveAt(p);
                                    costs.RemoveAt(p);
                                }
                            }
                        }
                    }

                    // Save the new connections if any were changed
                    if (conn != null)
                    {
                        node.connections     = conn.ToArray();
                        node.connectionCosts = costs.ToArray();
                    }
                }

                // Release buffers back to the pool
                Pathfinding.Util.ListPool <GraphNode> .Release(tmp_arr);

                Pathfinding.Util.ListPool <uint> .Release(tmp_arr2);
            }
        }
        /** Updates an area in the list graph.
         * Recalculates possibly affected connections, i.e all connectionlines passing trough the bounds of the \a guo will be recalculated
         * \astarpro */
        public void UpdateArea(GraphUpdateObject guo)
        {
            if (nodes == null)
            {
                return;
            }

            for (int i = 0; i < nodeCount; i++)
            {
                if (guo.bounds.Contains((Vector3)nodes[i].position))
                {
                    guo.WillUpdateNode(nodes[i]);
                    guo.Apply(nodes[i]);
                }
            }

            if (guo.updatePhysics)
            {
                //Use a copy of the bounding box, we should not change the GUO's bounding box since it might be used for other graph updates
                Bounds bounds = guo.bounds;

                if (thickRaycast)
                {
                    //Expand the bounding box to account for the thick raycast
                    bounds.Expand(thickRaycastRadius * 2);
                }

                //Create two temporary arrays used for holding new connections and costs
                List <GraphNode> tmp_arr = Pathfinding.Util.ListPool <GraphNode> .Claim();

                List <uint> tmp_arr2 = Pathfinding.Util.ListPool <uint> .Claim();

                for (int i = 0; i < nodeCount; i++)
                {
                    PointNode node = nodes[i] as PointNode;
                    Vector3   a    = (Vector3)node.position;

                    List <GraphNode> conn  = null;
                    List <uint>      costs = null;

                    for (int j = 0; j < nodeCount; j++)
                    {
                        if (j == i)
                        {
                            continue;
                        }

                        Vector3 b = (Vector3)nodes[j].position;
                        if (Polygon.LineIntersectsBounds(bounds, a, b))
                        {
                            float     dist;
                            PointNode other    = nodes[j] as PointNode;
                            bool      contains = node.ContainsConnection(other);

                            //Note, the IsValidConnection test will actually only be done once
                            //no matter what,so there is no performance penalty there
                            if (!contains && IsValidConnection(node, other, out dist))
                            {
                                //Debug.DrawLine (a+Vector3.up*0.1F,b+Vector3.up*0.1F,Color.green);
                                if (conn == null)
                                {
                                    tmp_arr.Clear();
                                    tmp_arr2.Clear();
                                    conn  = tmp_arr;
                                    costs = tmp_arr2;
                                    conn.AddRange(node.connections);
                                    costs.AddRange(node.connectionCosts);
                                }

                                uint cost = (uint)Mathf.RoundToInt(dist * Int3.FloatPrecision);
                                conn.Add(other);
                                costs.Add(cost);
                            }
                            else if (contains && !IsValidConnection(node, other, out dist))
                            {
                                //Debug.DrawLine (a+Vector3.up*0.5F*Random.value,b+Vector3.up*0.5F*Random.value,Color.red);
                                if (conn == null)
                                {
                                    tmp_arr.Clear();
                                    tmp_arr2.Clear();
                                    conn  = tmp_arr;
                                    costs = tmp_arr2;
                                    conn.AddRange(node.connections);
                                    costs.AddRange(node.connectionCosts);
                                }

                                int p = conn.IndexOf(other);

                                //Shouldn't have to check for it, but who knows what might go wrong
                                if (p != -1)
                                {
                                    conn.RemoveAt(p);
                                    costs.RemoveAt(p);
                                }
                            }
                        }
                    }

                    if (conn != null)
                    {
                        node.connections     = conn.ToArray();
                        node.connectionCosts = costs.ToArray();
                    }
                }

                Pathfinding.Util.ListPool <GraphNode> .Release(tmp_arr);

                Pathfinding.Util.ListPool <uint> .Release(tmp_arr2);
            }
        }
示例#4
0
        // Token: 0x0600052A RID: 1322 RVA: 0x0002D6B8 File Offset: 0x0002BAB8
        public void UpdateArea(GraphUpdateObject guo)
        {
            if (this.nodes == null)
            {
                return;
            }
            for (int i = 0; i < this.nodeCount; i++)
            {
                if (guo.bounds.Contains((Vector3)this.nodes[i].position))
                {
                    guo.WillUpdateNode(this.nodes[i]);
                    guo.Apply(this.nodes[i]);
                }
            }
            if (guo.updatePhysics)
            {
                Bounds bounds = guo.bounds;
                if (this.thickRaycast)
                {
                    bounds.Expand(this.thickRaycastRadius * 2f);
                }
                List <GraphNode> list = ListPool <GraphNode> .Claim();

                List <uint> list2 = ListPool <uint> .Claim();

                for (int j = 0; j < this.nodeCount; j++)
                {
                    PointNode        pointNode = this.nodes[j];
                    Vector3          a         = (Vector3)pointNode.position;
                    List <GraphNode> list3     = null;
                    List <uint>      list4     = null;
                    for (int k = 0; k < this.nodeCount; k++)
                    {
                        if (k != j)
                        {
                            Vector3 b = (Vector3)this.nodes[k].position;
                            if (Polygon.LineIntersectsBounds(bounds, a, b))
                            {
                                PointNode pointNode2 = this.nodes[k];
                                bool      flag       = pointNode.ContainsConnection(pointNode2);
                                float     num;
                                if (!flag && this.IsValidConnection(pointNode, pointNode2, out num))
                                {
                                    if (list3 == null)
                                    {
                                        list.Clear();
                                        list2.Clear();
                                        list3 = list;
                                        list4 = list2;
                                        list3.AddRange(pointNode.connections);
                                        list4.AddRange(pointNode.connectionCosts);
                                    }
                                    uint item = (uint)Mathf.RoundToInt(num * 1000f);
                                    list3.Add(pointNode2);
                                    list4.Add(item);
                                }
                                else if (flag && !this.IsValidConnection(pointNode, pointNode2, out num))
                                {
                                    if (list3 == null)
                                    {
                                        list.Clear();
                                        list2.Clear();
                                        list3 = list;
                                        list4 = list2;
                                        list3.AddRange(pointNode.connections);
                                        list4.AddRange(pointNode.connectionCosts);
                                    }
                                    int num2 = list3.IndexOf(pointNode2);
                                    if (num2 != -1)
                                    {
                                        list3.RemoveAt(num2);
                                        list4.RemoveAt(num2);
                                    }
                                }
                            }
                        }
                    }
                    if (list3 != null)
                    {
                        pointNode.connections     = list3.ToArray();
                        pointNode.connectionCosts = list4.ToArray();
                    }
                }
                ListPool <GraphNode> .Release(list);

                ListPool <uint> .Release(list2);
            }
        }
        // Token: 0x060025C3 RID: 9667 RVA: 0x001A1AF0 File Offset: 0x0019FCF0
        void IUpdatableGraph.UpdateArea(GraphUpdateObject guo)
        {
            if (this.nodes == null)
            {
                return;
            }
            for (int i = 0; i < this.nodeCount; i++)
            {
                PointNode pointNode = this.nodes[i];
                if (guo.bounds.Contains((Vector3)pointNode.position))
                {
                    guo.WillUpdateNode(pointNode);
                    guo.Apply(pointNode);
                }
            }
            if (guo.updatePhysics)
            {
                Bounds bounds = guo.bounds;
                if (this.thickRaycast)
                {
                    bounds.Expand(this.thickRaycastRadius * 2f);
                }
                List <Connection> list = ListPool <Connection> .Claim();

                for (int j = 0; j < this.nodeCount; j++)
                {
                    PointNode         pointNode2 = this.nodes[j];
                    Vector3           a          = (Vector3)pointNode2.position;
                    List <Connection> list2      = null;
                    for (int k = 0; k < this.nodeCount; k++)
                    {
                        if (k != j)
                        {
                            Vector3 b = (Vector3)this.nodes[k].position;
                            if (VectorMath.SegmentIntersectsBounds(bounds, a, b))
                            {
                                PointNode pointNode3 = this.nodes[k];
                                bool      flag       = pointNode2.ContainsConnection(pointNode3);
                                float     num;
                                bool      flag2 = this.IsValidConnection(pointNode2, pointNode3, out num);
                                if (list2 == null && flag != flag2)
                                {
                                    list.Clear();
                                    list2 = list;
                                    list2.AddRange(pointNode2.connections);
                                }
                                if (!flag && flag2)
                                {
                                    uint cost = (uint)Mathf.RoundToInt(num * 1000f);
                                    list2.Add(new Connection(pointNode3, cost, byte.MaxValue));
                                }
                                else if (flag && !flag2)
                                {
                                    for (int l = 0; l < list2.Count; l++)
                                    {
                                        if (list2[l].node == pointNode3)
                                        {
                                            list2.RemoveAt(l);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (list2 != null)
                    {
                        pointNode2.connections = list2.ToArray();
                    }
                }
                ListPool <Connection> .Release(ref list);
            }
        }