コード例 #1
0
    private List <Node> FindNodesWithMinimulNeighbours(NodeLink nodeLink)
    {
        HashSet <Node> neighbours            = nodeLink.current.neighbours;
        List <Node>    minNodes              = new List <Node>();
        int            minCount              = 10;
        List <Node>    unconnectedNeighbours = neighbours.Where(nei => isUnconnectedNode(nodeLink, nei)).ToList <Node>();

        foreach (Node n in unconnectedNeighbours)
        {
            int nerghboursCount = n.neighbours.Where(nei =>
                                                     nei != nodeLink.current &&
                                                     !IsNodeAncestorOf(nei, nodeLink))
                                  .Count();

            if (nerghboursCount < minCount)
            {
                minCount = nerghboursCount;
                minNodes.Clear();
                minNodes.Add(n);
            }
            else if (nerghboursCount == minCount)
            {
                minNodes.Add(n);
            }
        }

        return(minNodes);
    }
コード例 #2
0
        static public NodeLink ConnectEdges(ShapeNode node1, int index1, ShapeNode node2, int index2, float weighting = 0.0f)
        {
            NodeLink result;

            if (node1.LinkList[index1] != null)
            {
                result = node1.LinkList[index1];
            }
            else
            {
                NodeLink newLink = new NodeLink(node1, node2);
                newLink.weight = weighting;

                /*
                 * string s;
                 * s = "(" + ((RectNode)node1).rect.Left + ", " + ((RectNode)node1).rect.Top + ")";
                 * s += "(" + ((RectNode)node1).rect.Right + ", " + ((RectNode)node1).rect.Bottom + ")";
                 * s += " - ";
                 * s += "(" + ((RectNode)node2).rect.Left + ", " + ((RectNode)node2).rect.Top + ")";
                 * s += "(" + ((RectNode)node2).rect.Right + ", " + ((RectNode)node2).rect.Bottom + ")";
                 *
                 * System.Diagnostics.Trace.WriteLine(" : New Link", s);
                 */

                node1.LinkList[index1] = newLink;
                node2.LinkList[index2] = newLink;

                result = newLink;
            }

            return(result);
        }
コード例 #3
0
 public NeuralOscillatorConnectionNode(
     double initialTime,
     NodeLink connection)
     : base(0.0, 0.0)
 {
     this.Connection = connection;
 }
コード例 #4
0
 public void LinkTo(NodeLink _link)
 {
     if (_link.node != this)
     {
         daOutcomes.Add(_link);
     }
 }
コード例 #5
0
ファイル: SplineComputer.cs プロジェクト: SwordElucidator/NYA
        /// <summary>
        /// Add a link to a Node for a point in this computer. This is called by the Node component.
        /// </summary>
        /// <param name="node">Node input</param>
        /// <param name="pointIndex">Point index to link</param>
        public void AddNodeLink(Node node, int pointIndex)
        {
            if (node == null)
            {
                return;
            }
            if (pointIndex < 0 || pointIndex >= spline.points.Length)
            {
                return;
            }
            for (int i = 0; i < nodeLinks.Length; i++)
            {
                if (nodeLinks[i].node == node && nodeLinks[i].pointIndex == pointIndex)
                {
                    Debug.LogError("Junction already exists, cannot add junction " + node.name + " at point " + pointIndex);
                    return;
                }
            }
            if (!node.HasConnection(this, pointIndex))
            {
                Debug.LogError("Junction " + node.name + " does not have a connection for point " + pointIndex + " Call AddConnection on the junction.");
                return;
            }
            NodeLink newLink = new NodeLink();

            newLink.node       = node;
            newLink.pointIndex = pointIndex;
            NodeLink[] newLinks = new NodeLink[_nodeLinks.Length + 1];
            _nodeLinks.CopyTo(newLinks, 0);
            newLinks[_nodeLinks.Length] = newLink;
            _nodeLinks = newLinks;
        }
コード例 #6
0
ファイル: MessageManager.cs プロジェクト: simur1995/TeamSASIA
    void Dropped(string guid)
    {
        NodeLink NL = NodeLink.Find(guid);

        lastMessage = "Dropped";
        NL.Fire("OnlineDrop", guid);
    }
コード例 #7
0
    public bool CopyFrom(StateGraph graph, IEnumerable <StateNodeRef> copyNodes, Vector2 offset)
    {
        List <StateNodeRef> nodes = copyNodes.Where(it => graph.CheckCopy(it)).ToList();

        foreach (var node in nodes)
        {
            NodeData data = new NodeData
            {
                Id       = node.Id,
                Bounds   = node.Node.Bounds,
                Data     = TypeSerializerHelper.Serialize(node.Node.Data),
                Name     = node.Node.Name,
                Comments = node.Node.Comments,
            };
            data.Bounds.position += offset;
            Datas.Add(data);
        }
        foreach (var link in graph.Links)
        {
            if (nodes.Contains(link.From) && nodes.Contains(link.To))
            {
                NodeLink nodeLink = new NodeLink
                {
                    FromIdx = Datas.FindIndex(it => it.Id == link.From.Id),
                    ToIdx   = Datas.FindIndex(it => it.Id == link.To.Id),
                    IsChild = link.IsChild
                };
                Links.Add(nodeLink);
            }
        }
        return(nodes.Count > 0);
    }
コード例 #8
0
    private StoryNode MapToStoryNode()
    {
        var groups    = inputGroups.GetInputGroups().Where(g => !string.IsNullOrEmpty(g.keys) && !string.IsNullOrEmpty(g.link)).ToList();
        var nodeLinks = new NodeLink[groups.Count];

        for (var i = 0; i < nodeLinks.Length; i++)
        {
            var keys = groups[i].keys;
            var link = groups[i].link;

            if (string.IsNullOrEmpty(keys) && string.IsNullOrEmpty(link))
            {
                continue;
            }

            nodeLinks[i] = new NodeLink
            {
                keys = keys.Split(','),
                link = GetFileName(link)
            };
        }

        return(new StoryNode
        {
            nodes = nodeLinks,
            text = text.text
        });
    }
コード例 #9
0
        public void TestPutComment()
        {
            var localName  = "test_multi_pages.docx";
            var remoteName = "TestPutComment.docx";
            var fullName   = Path.Combine(this.dataFolder, remoteName);
            var nodeLink   = new NodeLink {
                NodeId = "0.0.3"
            };
            var documentPosition = new DocumentPosition {
                Node = nodeLink, Offset = 0
            };
            var body = new Comment
            {
                RangeStart = documentPosition,
                RangeEnd   = documentPosition,
                Initial    = "IA",
                Author     = "Imran Anwar",
                Text       = "A new Comment"
            };

            this.StorageApi.PutCreate(fullName, null, null, File.ReadAllBytes(BaseTestContext.GetDataDir(BaseTestContext.CommonFolder) + localName));

            var request = new PutCommentRequest(remoteName, body, this.dataFolder);
            var actual  = this.WordsApi.PutComment(request);

            Assert.AreEqual(200, actual.Code);
        }
コード例 #10
0
        public void NewConnectionToThis(ScriptNodeConnection connection)
        {
            var     pinInfo = connection.InputPin;
            NodePin pinList;

            m_ToThisNodePin.TryGetValue(pinInfo.Name, out pinList);
            if (pinList == null)
            {
                pinList = new NodePin()
                {
                    Name   = new NameString(pinInfo.Name),
                    Type   = new NameString(pinInfo.PinType.Name),
                    LinkTo = new List <NodeLink>()
                };
            }

            if (pinList.LinkTo.Find(x => x.Connection == connection) == null)
            {
                var newPinInfo = new NodeLink()
                {
                    Connection = connection,
                    Target     = connection.InputElement.As <ScriptGraphNode>(),
                    Pin        = new NodePin()
                };
                pinList.LinkTo.Add(newPinInfo);
            }
        }
コード例 #11
0
    private bool isUnconnectedNode(NodeLink originLink, Node otherNode)
    {
        if (otherNode.nodeLinks.Count == 0)
        {
            return(true);
        }
        bool hasAncestorLink = false;
        bool hasSameLink     = false;
        bool hasChildLink    = false;

        foreach (NodeLink link in otherNode.nodeLinks)
        {
            if (link.IsAncestorOf(originLink))
            {
                hasAncestorLink = true;
                break;
            }

            if (link.IsSameChain(originLink.linkIdChain))
            {
                hasSameLink = true;
                break;
            }

            if (link.IsDirectChildOf(originLink))
            {
                hasChildLink = true;
                break;
            }
        }
        return(!hasAncestorLink && !hasSameLink && !hasChildLink);
    }
コード例 #12
0
    public static string ToString <T>(NodeLink <T> list)
    {
        var p = list;

        if (!Linked.IsCyclic(p))
        {
            var sb = new StringBuilder();
            sb.Append("[");
            while (p != null && p.Next != null)
            {
                if (p.Next.Value != null)
                {
                    sb.Append($"{p.Next.Value.ToString()},");
                }
                else
                {
                    sb.Append($"(null)");
                }
                p = p.Next;
            }
            if (sb[sb.Length - 1] != '[')
            {
                sb.Remove(sb.Length - 1, 1);
            }
            sb.Append("]");
            return(sb.ToString());
        }
        else
        {
            return("[cyclic]");
        }
    }
コード例 #13
0
 void    LinkCreatedCallback(NodeLink link)
 {
     if (editorEvents.isDraggingLink || editorEvents.isDraggingNewLink)
     {
         StopDragLink(true);
     }
 }
コード例 #14
0
        void CreateRing(float radius, float corridorWidth, List <Node> ring, List <Node> innerRing)
        {
            float circ = radius * 2.0f * (float)Math.PI;

            uint divs = 0;

            if (circ > corridorWidth)
            {
                // Calculate how many fixed position nodes we can put on this ring
                divs = 1;
                while ((circ / ((float)(divs * 2))) > corridorWidth)
                {
                    divs *= 2;
                }

                System.Diagnostics.Trace.WriteLine("\n" + circ + " = " + divs);

                // Add nodes to ring
                for (uint i = 0; i < divs; i++)
                {
                    float     angle = (((float)i) * (float)Math.PI * 2.0f) / (float)divs;
                    PolarNode pn    = new PolarNode(radius, angle);
                    pn.size = 0.0f; // ringWidth;
                    ring.Add(pn);
                    nodeDict.Add(pn, pn.LinkList);
                }

                // Connect nodes together on ring
                for (int index = 0; index < ring.Count; index++)
                {
                    int      index2 = (index + 1) % ring.Count;
                    NodeLink link   = new NodeLink(ring[index], ring[index2]);
                    link.weight = ringWeight;
                    ring[index].LinkList.Add(link);
                    ring[index2].LinkList.Add(link);
                }

                // Connect nodes to inner ring
                // Note: The number of nodes between the 2 rings may be different.
                if (innerRing != null)
                {
                    int step = 1;
                    while (divs > innerRing.Count)
                    {
                        step++;
                        divs /= 2;
                    }

                    int outerIndex = 0;
                    for (int innerIndex = 0; innerIndex < innerRing.Count; innerIndex++, outerIndex += step)
                    {
                        NodeLink link = new NodeLink(ring[outerIndex], innerRing[innerIndex]);
                        link.weight = spokeWeight;
                        ring[outerIndex].LinkList.Add(link);
                        innerRing[innerIndex].LinkList.Add(link);
                    }
                }
            }
        }
コード例 #15
0
 public ServiceAgentCommand(AgentIdentifier AgentId, CommandName CommandName, NodeLink Link, CommandArguments Args, CorrelationToken?CT = null)
 {
     this.AgentId     = AgentId;
     this.CommandName = CommandName;
     this.Link        = Link;
     this.Args        = Args;
     this.CT          = CT;
 }
コード例 #16
0
 public NodeLink(Node prev, Node current, NodeLink prevLink, int weight)
 {
     this.prev     = prev;
     this.current  = current;
     this.weight   = weight;
     this.prevLink = prevLink;
     linkIdChain   = new List <int>();
 }
コード例 #17
0
        void LinkRemovedCallback(NodeLink link)
        {
            const string undoName = "Link removed";

            Undo.RecordObject(graph, undoName);
            Undo.RecordObject(link.fromNode, undoName);
            Undo.RecordObject(link.toNode, undoName);
        }
コード例 #18
0
 public void RemoveStartNodeLink()
 {
     if (_startNodeLink)
     {
         _startNodeLink.RemoveNodeBridge(this);
         _startNodeLink = null;
         _startRect     = null;
     }
 }
コード例 #19
0
 protected void DisableNodeLinkInteractions(NodeLink nodeLink)
 {
     if (nodeLink)
     {
         nodeLink.OnBeginDragEvent -= nodeManager.NodeLinkDragStarted;
         nodeLink.OnDropEvent      -= nodeManager.NodeLinkDropped;
         nodeLink.OnEndDragEvent   -= nodeManager.NodeLinkDragEnded;
     }
 }
コード例 #20
0
        public void             RemoveLinkFromAnchors(Anchor fromAnchor, Anchor toAnchor)
        {
            NodeLink link = fromAnchor.links.FirstOrDefault(l => l.toAnchor == toAnchor);

            if (link != null)
            {
                RemoveLink(link);
            }
        }
コード例 #21
0
 public void RemoveEndNodeLink()
 {
     if (_endNodeLink)
     {
         _endNodeLink.RemoveNodeBridge(this);
         _endNodeLink = null;
         _endRect     = null;
     }
 }
コード例 #22
0
ファイル: MessageManager.cs プロジェクト: simur1995/TeamSASIA
    //private string tempViewPoint;

    void Grabbed(string guid)
    {
        NodeLink NL = NodeLink.Find(guid);

        Tempguid = guid;
        NL.Fire("OnlineGrab", guid);
        lastMessage = "OnlineGrab";
        Debug.Log("SENT");
    }
コード例 #23
0
 public void NodeLinkDragEnded(NodeLink nodeLink)
 {
     // Delete any non-connected bridges
     for (int i = 0; i < _currentNodeBridges.Count; i++)
     {
         _currentNodeBridges[i].Delete();
     }
     _currentNodeBridges.Clear();
     _state = State.Idle;
 }
コード例 #24
0
        /// <summary>
        /// recursive function analyzing vertices and adding found links to link list
        /// <param name="myQueryResult">The query result.</param>
        /// <param name="Nodes">list of nodes containing all nodes found by GenerateNodeList previously</param>
        /// <param name="Nodes">reference to list of nodes where found nodes are added</param>
        /// </summary>
        private void GenerateLinkList_AnalyzeVertices(IEnumerable <IVertexView> vertices, List <string> Nodes, ref List <NodeLink> Links)
        {
            foreach (var aVertex in vertices)
            {
                string sourcename = null;

                foreach (var property in aVertex.GetAllProperties())
                {
                    if ((property.Item1 is String) && (property.Item1.ToString().ToUpper().IndexOf("NODE") >= 0) && (property.Item2 is String))
                    {
                        sourcename = property.Item2.ToString();
                    }
                }

                foreach (var edge in aVertex.GetAllEdges())
                {
                    foreach (var targetvertex in edge.Item2.GetTargetVertices())
                    {
                        string targetname = null;

                        foreach (var property in targetvertex.GetAllProperties())
                        {
                            if ((property.Item1 is String) && (property.Item1.ToString().ToUpper().IndexOf("NODE") >= 0) && (property.Item2 is String))
                            {
                                targetname = property.Item2.ToString();
                                break;
                            }
                        }

                        if ((sourcename != null) && (targetname != null))
                        {
                            NodeLink newlink = new NodeLink();

                            if (edge.Item1 is String)
                            {
                                newlink.name = edge.Item1.ToString();
                            }
                            else
                            {
                                newlink.name = "";
                            }
                            newlink.source = Nodes.IndexOf(sourcename);
                            newlink.target = Nodes.IndexOf(targetname);

                            if ((newlink.source >= 0) && (newlink.target >= 0))
                            {
                                Links.Add(newlink);
                            }
                        }
                    }

                    GenerateLinkList_AnalyzeVertices(edge.Item2.GetTargetVertices(), Nodes, ref Links);
                }
            }
        }
コード例 #25
0
 private bool IsNodeAncestorOf(Node origin, NodeLink targetLink)
 {
     foreach (NodeLink originLink in origin.nodeLinks)
     {
         if (originLink.IsAncestorOf(targetLink))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #26
0
 private void DragConnection()
 {
     if (Input.GetMouseButtonDown(0))
     {
         draggingLink = false;
         linkingLink  = null;
         Vector2  pos     = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         NodeLink closest = GetClosestNodeLink(pos);
         if (closest != null)
         {
             Vector2 p = closest.transform.position;
             if (Vector3.Distance(p, pos) <= minConnectorDist)
             {
                 linkingLink  = closest;
                 draggingLink = true;
                 if (closest.linkedLink != null)
                 {
                     closest.linkedLink = null;
                 }
                 closest.linkedLink = null;
             }
             else
             {
                 linkingLink  = null;
                 draggingLink = false;
             }
         }
         else
         {
             linkingLink  = null;
             draggingLink = false;
         }
     }
     else if (Input.GetMouseButtonUp(0))
     {
         if (linkingLink != null && draggingLink == true)
         {
             Vector2  pos     = Camera.main.ScreenToWorldPoint(Input.mousePosition);
             NodeLink closest = GetClosestNodeLink(pos).GetComponent <NodeLink>();
             Vector2  p       = closest.transform.position;
             if (Vector3.Distance(p, pos) <= minConnectorDist)
             {
                 FormLink(linkingLink, closest);
             }
         }
         linkingLink  = null;
         draggingLink = false;
     }
     else if (Input.GetMouseButton(0) == false)
     {
         draggingLink = false;
         linkingLink  = null;
     }
 }
コード例 #27
0
 void LinkPostCreatedCallback(NodeLink link)
 {
     if (link.fromNode == this)
     {
         OnNodeAnchorLink(link.fromAnchor.fieldName, link.fromAnchor.fieldIndex);
     }
     else if (link.toNode == this)
     {
         OnNodeAnchorLink(link.toAnchor.fieldName, link.toAnchor.fieldIndex);
     }
 }
コード例 #28
0
 void LinkRemovedCallback(NodeLink link)
 {
     if (link.fromNode == this)
     {
         OnNodeAnchorUnlink(link.fromAnchor.fieldName, link.fromAnchor.fieldIndex);
     }
     else if (link.toNode == this)
     {
         OnNodeAnchorUnlink(link.toAnchor.fieldName, link.toAnchor.fieldIndex);
     }
 }
コード例 #29
0
        private static NodeLink CreateNodeLink(this SkillNodeLink nodeLink)
        {
            var data = new NodeLink
            {
                ChildKey  = nodeLink.ChildKey,
                LinkType  = nodeLink.LinkType,
                ParentKey = nodeLink.ParentKey
            };

            return(data);
        }
コード例 #30
0
ファイル: FlowNode.cs プロジェクト: zukaken/Unity
    public void Join(int sourcePin, FlowNode dstNode, int dstPin)
    {
        bool result = NodeLinks.FindIndex(nodelink => nodelink.Equals(sourcePin, dstNode, dstPin)) != -1;

        if (!result)
        {
            var newLink = new NodeLink();
            newLink.Join(sourcePin, dstNode, dstPin);
            NodeLinks.Add(newLink);
        }
    }
コード例 #31
0
        public static NodeLink ConnectEdges(ShapeNode node1, int index1, ShapeNode node2, int index2, float weighting = 0.0f)
        {
            NodeLink result;

            if (node1.LinkList[index1] != null)
            {
                result = node1.LinkList[index1];
            }
            else
            {
                NodeLink newLink = new NodeLink(node1, node2);
                newLink.weight = weighting;
                /*
                string s;
                s = "(" + ((RectNode)node1).rect.Left + ", " + ((RectNode)node1).rect.Top + ")";
                s += "(" + ((RectNode)node1).rect.Right + ", " + ((RectNode)node1).rect.Bottom + ")";
                s += " - ";
                s += "(" + ((RectNode)node2).rect.Left + ", " + ((RectNode)node2).rect.Top + ")";
                s += "(" + ((RectNode)node2).rect.Right + ", " + ((RectNode)node2).rect.Bottom + ")";

                System.Diagnostics.Trace.WriteLine(" : New Link", s);
                */

                node1.LinkList[index1] = newLink;
                node2.LinkList[index2] = newLink;

                result = newLink;
            }

            return result;
        }
コード例 #32
0
        void CreateRing(float radius, float corridorWidth, List<Node> ring, List<Node> innerRing)
        {
            float circ = radius * 2.0f * (float)Math.PI;

            uint divs = 0;

            if (circ > corridorWidth)
            {
                // Calculate how many fixed position nodes we can put on this ring
                divs = 1;
                while ((circ / ((float)(divs * 2))) > corridorWidth)
                {
                    divs *= 2;
                }

                System.Diagnostics.Trace.WriteLine("\n" + circ + " = " + divs);

                // Add nodes to ring
                for (uint i = 0; i < divs; i++)
                {
                    float angle = (((float) i) * (float)Math.PI * 2.0f )/ (float)divs;
                    PolarNode pn = new PolarNode(radius, angle);
                    pn.size = 0.0f; // ringWidth;
                    ring.Add(pn);
                    nodeDict.Add(pn, pn.LinkList);
                }

                // Connect nodes together on ring
                for(int index = 0; index < ring.Count; index++)
                {
                    int index2 = (index + 1) % ring.Count;
                    NodeLink link = new NodeLink(ring[index], ring[index2]);
                    link.weight = ringWeight;
                    ring[index].LinkList.Add(link);
                    ring[index2].LinkList.Add(link);
                }

                // Connect nodes to inner ring
                // Note: The number of nodes between the 2 rings may be different.
                if (innerRing != null)
                {
                    int step = 1;
                    while (divs > innerRing.Count)
                    {
                        step++;
                        divs /= 2;
                    }

                    int outerIndex = 0;
                    for (int innerIndex = 0; innerIndex < innerRing.Count; innerIndex++, outerIndex += step)
                    {
                        NodeLink link = new NodeLink(ring[outerIndex], innerRing[innerIndex]);
                        link.weight = spokeWeight;
                        ring[outerIndex].LinkList.Add(link);
                        innerRing[innerIndex].LinkList.Add(link);
                    }
                }
            }
        }
コード例 #33
0
ファイル: GRAPHVIS_IO.cs プロジェクト: karsten-wolfert/sones
        /// <summary>
        /// recursive function analyzing vertices and adding found links to link list
        /// <param name="myQueryResult">The query result.</param>
        /// <param name="Nodes">list of nodes containing all nodes found by GenerateNodeList previously</param>
        /// <param name="Nodes">reference to list of nodes where found nodes are added</param>
        /// </summary>
        private void GenerateLinkList_AnalyzeVertices(IEnumerable<IVertexView> vertices, List<string> Nodes, ref List<NodeLink> Links)
        {
            foreach (var aVertex in vertices)
            {
                string sourcename = null;

                foreach (var property in aVertex.GetAllProperties())
                {
                    if ((property.Item1 is String) && (property.Item1.ToString().ToUpper().IndexOf("NODE") >= 0) && (property.Item2 is String))
                    {
                        sourcename = property.Item2.ToString();
                    }
                }

                foreach (var edge in aVertex.GetAllEdges())
                {
                    foreach (var targetvertex in edge.Item2.GetTargetVertices())
                    {
                        string targetname = null;

                        foreach (var property in targetvertex.GetAllProperties())
                        {
                            if ((property.Item1 is String) && (property.Item1.ToString().ToUpper().IndexOf("NODE") >= 0) && (property.Item2 is String))
                            {
                                targetname = property.Item2.ToString();
                                break;
                            }
                        }

                        if ((sourcename != null) && (targetname != null))
                        {
                            NodeLink newlink = new NodeLink();

                            if (edge.Item1 is String) newlink.name = edge.Item1.ToString();
                            else newlink.name = "";
                            newlink.source = Nodes.IndexOf(sourcename);
                            newlink.target = Nodes.IndexOf(targetname);

                            if ((newlink.source >= 0) && (newlink.target >= 0))
                            {
                                Links.Add(newlink);
                            }
                        }
                    }

                    GenerateLinkList_AnalyzeVertices(edge.Item2.GetTargetVertices(), Nodes, ref Links);
                }
            }
        }
コード例 #34
0
        public void Initialize(int numRings, float startRadius, float inRingWidth, float spokeWidth, float weighting, float inWeavePercent)
        {
            ringWidth = inRingWidth;
            ringWeight = weighting;
            spokeWeight = 1.0f - weighting;
            weavePercent = inWeavePercent;

            networkRadius = (startRadius + ((numRings + 1) * ringWidth));

            // Add centre node
            PolarNode centreNode = new PolarNode(0.0f, 0.0f);
            centreNode.size = startRadius * 2.0f;
            nodeDict.Add(centreNode, centreNode.LinkList);

            List<Node> ringList = new List<Node>();
            List<Node> oldRingList = null;

            CreateRing(startRadius + ringWidth, spokeWidth, ringList, null);

            // Special case on first ring
            if (ringList.Count > 0)
            {
                NodeLink link = new NodeLink(centreNode, ringList[0]);
                link.weight = spokeWeight;
                centreNode.LinkList.Add(link);
                ringList[0].LinkList.Add(link);
            }
            oldRingList = ringList;

            // Create all other rings
            for (int i = 1; i < numRings; i++)
            {
                ringList = new List<Node>();
                CreateRing(startRadius + (ringWidth * (float)(i + 1)), spokeWidth, ringList, oldRingList);
                oldRingList = ringList;
            }

            /*
            if (weavePercent > 0.0f)
            {
                Random random = new Random();

                List<PolarNode> weaveNodes = new List<PolarNode>();

                // Identify all weave nodes
                foreach (Node node in nodeDict.Keys)
                {
                    PolarNode pn = (PolarNode)node;
                    if (pn.LinkList.Count == 4)
                    {
                        //TODO: And all links dont connect to null
                        weaveNodes.Add(pn);
                    }
                }

                int numWeaves = (int)(((float)weaveNodes.Count) * weavePercent * 0.01f);

                while ((numWeaves > 0) && (weaveNodes.Count > 0))
                {
                    numWeaves--;
                    float angleThreshold = (float)Math.PI * 0.5f;

                    //Remove a random node from the weave list
                    int index = random.Next(0, weaveNodes.Count);
                    PolarNode pn = weaveNodes[index];
                    weaveNodes.RemoveAt(index);

                    // First 2 links are orbital links
                    // Skip doing this weave if the angle is > threshold
                    float angle1 = ((PolarNode)pn.LinkList[0].Other(pn)).angle;
                    float angle2 = ((PolarNode)pn.LinkList[1].Other(pn)).angle;

                    if (Math.Abs(angle2 - angle1) > angleThreshold)
                    {
                        continue;
                    }

                    // Collapse orbital links
                    PolarNode orbitA = (PolarNode)pn.LinkList[0].Other(pn);
                    PolarNode orbitB = (PolarNode)pn.LinkList[1].Other(pn);
                    pn.LinkList[0].Replace(pn, orbitB);

                    // Find the link on orbitB that links to pn
                    if (orbitB.LinkList[0].Other(orbitB) == pn)
                    {
                        orbitB.LinkList[0] = pn.LinkList[0];
                    }
                    else
                    {
                        orbitB.LinkList[1] = pn.LinkList[0];
                    }

                    // Second 2 links are spoke links
                    PolarNode spokeA = (PolarNode)pn.LinkList[2].Other(pn);
                    PolarNode spokeB = (PolarNode)pn.LinkList[3].Other(pn);
                    pn.LinkList[2].Replace(pn, spokeB);

                    if (spokeB.LinkList[2].Other(spokeB) == pn)
                    {
                        spokeB.LinkList[2] = pn.LinkList[2];
                    }
                    else
                    {
                        spokeB.LinkList[3] = pn.LinkList[2];
                    }

                    pn.LinkList.Clear();
                    // Remove pn from network
                    nodeDict.Remove(pn);

                }
            }*/

            /*
            // Bias the link weights based on horizontal & vertical orientation
            foreach (List<NodeLink> linkList in nodeDict.Values)
            {
                foreach (NodeLink l1 in linkList)
                {
                    if (l1.a != null && l1.b != null)
                    {
                        PolarNode pn1 = (PolarNode)l1.a;
                        PolarNode pn2 = (PolarNode)l1.b;

                        Vector2D vec = new Vector2D(pn1.Point, pn2.Point);
                        vec = vec.Normalized();

                        l1.weight = (ringWeight * Math.Abs(vec.b.X - vec.a.X)) + (spokeWeight * (Math.Abs(vec.b.Y - vec.a.Y)));
                        l1.weight = l1.weight * l1.weight * l1.weight;
                    }
                }
            }*/
        }
コード例 #35
0
    public void AddLink(Node endNode)
    {
        AstarPath path = target as AstarPath;
        Undo.RegisterUndo (path,"Added Link");
        NodeLink link = new NodeLink ();
        link.linkType = linkType;
        link.fromVector = firstLinkNode.vectorPos;
        link.oneWay = oneWay;
        if (endNode != null) {
            link.toVector = endNode.vectorPos;
        }
        ArrayList linkArr = new ArrayList (path.links);
        linkArr.Add (link);
        path.links = linkArr.ToArray (typeof(NodeLink)) as NodeLink[];

        //Reset
        linkClickStatus = 0;
        firstLinkNode = null;
    }
コード例 #36
0
ファイル: GridNetwork.cs プロジェクト: OctoOsmo/MazeGenerator
        public virtual void Initialize(int gridWidth, int gridHeight, int weavePercent, float weighting)
        {
            horizontalWeighting = weighting;
            verticalWeighting = 1.0f - weighting;

            // Create grid
            RectNode[,] basicGrid = new RectNode[gridWidth, gridHeight];

            // Create square nodes
            SizeF cellSize = new SizeF(1, 1);
            Point p = new Point();
            for (p.X = 0; p.X < gridWidth; p.X++)
            {
                for (p.Y = 0; p.Y < gridHeight; p.Y++)
                {
                    RectNode node = new RectNode(p, cellSize);
                    nodeDict.Add(node, node.LinkList);
                    basicGrid[p.X, p.Y] = node;
                }
            }

            // Connect nodes
            for (p.X = 1; p.X < gridWidth; p.X++)
            {
                for (p.Y = 0; p.Y < gridHeight; p.Y++)
                {
                    ShapeNode.ConnectEdges(basicGrid[p.X - 1, p.Y], RectNode.RightIndex, basicGrid[p.X, p.Y], RectNode.LeftIndex, horizontalWeighting);
                }
            }

            for (p.X = 0; p.X < gridWidth; p.X++)
            {
                for (p.Y = 1; p.Y < gridHeight; p.Y++)
                {
                    ShapeNode.ConnectEdges(basicGrid[p.X, p.Y - 1], RectNode.BottomIndex, basicGrid[p.X, p.Y], RectNode.TopIndex, verticalWeighting);
                }
            }

            boundingBox.ptMin.X = 0;
            boundingBox.ptMin.Y = 0;
            boundingBox.ptMax.X = gridWidth;
            boundingBox.ptMax.Y = gridHeight;

            // Add Weaves
            int numWeaveNodes = (gridWidth - 2) * (gridHeight - 2);
            if (numWeaveNodes > 0)
            {
                for (p.X = 1; p.X < (gridWidth - 1); p.X++)
                {
                    for (p.Y = 1; p.Y < (gridHeight - 1); p.Y++)
                    {
                        int chance = _random.Next(0, 100);
                        if (chance < weavePercent)
                        {
                            NodeLink link;

                            Node gridNode = basicGrid[p.X, p.Y];
                            Node upperNode = gridNode.LinkList[0].Other(gridNode);
                            Node leftNode = gridNode.LinkList[1].Other(gridNode);
                            Node lowerNode = gridNode.LinkList[2].Other(gridNode);
                            Node rightNode = gridNode.LinkList[3].Other(gridNode);

                            RectNode weaveNode = new RectNode(p, cellSize);
                            nodeDict.Add(weaveNode, weaveNode.LinkList);

                            weaveNode.LinkList[0] = gridNode.LinkList[0];
                            gridNode.LinkList[0] = null;

                            weaveNode.LinkList[2] = gridNode.LinkList[2];
                            gridNode.LinkList[2] = null;

                            link = weaveNode.LinkList[0];
                            if (link.a == gridNode)
                            {
                                link.a = weaveNode;
                            }
                            else
                            {
                                link.b = weaveNode;
                            }

                            link = weaveNode.LinkList[2];
                            if (link.a == gridNode)
                            {
                                link.a = weaveNode;
                            }
                            else
                            {
                                link.b = weaveNode;
                            }

                            link = new NodeLink(upperNode, lowerNode);
                            upperNode.LinkList[2] = link;
                            lowerNode.LinkList[0] = link;
                            link.visited = true;

                            link = new NodeLink(leftNode, rightNode);
                            leftNode.LinkList[3] = link;
                            rightNode.LinkList[1] = link;
                            link.visited = true;

                            gridNode.LinkList[1].visited = true;
                            gridNode.LinkList[3].visited = true;
                            weaveNode.LinkList[0].visited = true;
                            weaveNode.LinkList[2].visited = true;
                        }
                    }
                }
            }

            // Add start and end nodes
            Node startNode = basicGrid[0,0];
            startNode.LinkList[3] = new NodeLink(startNode, null);
            startNode.LinkList[3].visited = true;

            Node endNode = basicGrid[gridWidth - 1, gridHeight - 1];
            endNode.LinkList[1] = new NodeLink(endNode, null);
            endNode.LinkList[1].visited = true;

            // Display some metrics
            System.Diagnostics.Trace.WriteLine("\n\n");
            System.Diagnostics.Trace.WriteLine("GridMaze : Nodes = " + nodeDict.Count);
            System.Diagnostics.Trace.WriteLine("GridMaze : NodeLinks = " + Network.CountNodeLinks(nodeDict));
            System.Diagnostics.Trace.WriteLine("\n\n");
        }
コード例 #37
0
ファイル: Story.cs プロジェクト: QuentinLB/rpg_engine
 public void add_link(NodeLink n)
 {
     links.Add(n);
 }