Beispiel #1
0
        void ProcessNodeLinks(PWNode node)
        {
            var links = node.GetLinks();

            foreach (var link in links)
            {
                if (!nodesDictionary.ContainsKey(link.distantNodeId))
                {
                    continue;
                }

                if (link.mode == PWNodeProcessMode.RequestForProcess)
                {
                    continue;
                }

                var target = nodesDictionary[link.distantNodeId];

                if (target == null)
                {
                    continue;
                }

                // Debug.Log("local: " + link.localClassAQName + " / " + node.GetType() + " / " + node.nodeId);
                // Debug.Log("distant: " + link.distantClassAQName + " / " + target.GetType() + " / " + target.nodeId);

                //ignore old links not removed cause of property removed in a script at compilation
                if (!realMode)
                {
                    if (!bakedNodeFields.ContainsKey(link.localClassAQName) ||
                        !bakedNodeFields[link.localClassAQName].ContainsKey(link.localName) ||
                        !bakedNodeFields[link.distantClassAQName].ContainsKey(link.distantName))
                    {
                        Debug.LogError("Can't find field: " + link.localName + " in " + link.localClassAQName + " OR " + link.distantName + " in " + link.distantClassAQName);
                        continue;
                    }
                }

                var val = bakedNodeFields[link.localClassAQName][link.localName].GetValue(node);
                if (val == null)
                {
                    Debug.Log("null value of node: " + node.GetType() + " of field: " + link.localName);
                }
                var prop = bakedNodeFields[link.distantClassAQName][link.distantName];

                // Debug.Log("set value: " + val.GetHashCode() + "(" + val + ")" + " to " + target.GetHashCode() + "(" + target + ")");

                // simple assignation, without multi-anchor
                if (link.distantIndex == -1 && link.localIndex == -1)
                {
                    if (realMode)
                    {
                        prop.SetValue(target, val);
                    }
                    else
                    {
                        try {
                            prop.SetValue(target, val);
                        } catch (Exception e) {
                            Debug.LogError(e);
                        }
                    }
                }
                else if (link.distantIndex != -1 && link.localIndex == -1)                 //distant link is a multi-anchor
                {
                    PWValues values = (PWValues)prop.GetValue(target);

                    if (values != null)
                    {
                        if (!values.AssignAt(link.distantIndex, val, link.localName))
                        {
                            Debug.Log("failed to set distant indexed field value: " + link.distantName);
                        }
                    }
                }
                else if (link.distantIndex == -1 && link.localIndex != -1 && val != null)                 //local link is a multi-anchor
                {
                    object localVal = ((PWValues)val).At(link.localIndex);

                    if (realMode)
                    {
                        prop.SetValue(target, localVal);
                    }
                    else
                    {
                        try {
                            prop.SetValue(target, localVal);
                        } catch {
                            Debug.LogWarning("can't assign " + link.localName + " to " + link.distantName);
                        }
                    }
                }
                else if (val != null)                 // both are multi-anchors
                {
                    PWValues values   = (PWValues)prop.GetValue(target);
                    object   localVal = ((PWValues)val).At(link.localIndex);

                    if (values != null)
                    {
                        // Debug.Log("assigned total multi");
                        if (!values.AssignAt(link.distantIndex, localVal, link.localName))
                        {
                            Debug.Log("failed to set distant indexed field value: " + link.distantName);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        void BakeGraphParts(bool threaded = true)
        {
            //TODO: thread this, can be long

            ForeachAllNodes((n) => {
                if (!n)
                {
                    return;
                }

                var links = n.GetLinks();
                var deps  = n.GetDependencies();

                if (links.Count > 0 && links.All(l => l.mode == PWNodeProcessMode.RequestForProcess))
                {
                    List <PWNodeProcessInfo> toComputeList;

                    if (bakedGraphParts.ContainsKey(n.nodeId))
                    {
                        toComputeList = bakedGraphParts[n.nodeId];
                    }
                    else
                    {
                        toComputeList = bakedGraphParts[n.nodeId] = new List <PWNodeProcessInfo>();
                    }

                    //analyze of "extern groups" (group of node with only one RequestForProcess link at the end)
                    if (deps.Any(d => FindNodebyId(d.nodeId).processMode == PWNodeProcessMode.RequestForProcess))
                    {
                        TryBuildGraphPart(n, toComputeList);

                        return;
                    }

                    //go back to the farest node dependency with the RequestForProcess links:
                    foreach (var depNodeId in n.GetDependencies().Select(d => d.nodeId).Distinct())
                    {
                        var node = FindNodebyId(depNodeId);

                        if (node == null)
                        {
                            continue;
                        }

                        if (node.GetLinks().All(dl => dl.mode == PWNodeProcessMode.RequestForProcess))
                        {
                            InsertNodeIfNotExists(toComputeList, node);
                        }
                    }
                    InsertNodeIfNotExists(toComputeList, n);

                    foreach (var link in links.Where(l => l.mode == PWNodeProcessMode.RequestForProcess).GroupBy(l => l.localNodeId).Select(g => g.First()))
                    {
                        PWNode node = FindNodebyId(link.distantNodeId);

                        //if the node goes nowhere, add it
                        if (node.GetLinks().Count == 0)
                        {
                            List <PWNodeProcessInfo> subToComputeList;
                            if (bakedGraphParts.ContainsKey(node.nodeId))
                            {
                                subToComputeList = bakedGraphParts[node.nodeId];
                            }
                            else
                            {
                                subToComputeList = bakedGraphParts[node.nodeId] = new List <PWNodeProcessInfo>();
                            }

                            subToComputeList.RemoveAll(nodeInfo => toComputeList.Any(ni => ni.node.nodeId == nodeInfo.node.nodeId));

                            subToComputeList.InsertRange(0, toComputeList);
                            if (!subToComputeList.Any(ni => ni.node.nodeId == node.nodeId))
                            {
                                subToComputeList.Insert(subToComputeList.Count, new PWNodeProcessInfo(node, FindGraphNameFromExternalNode(node)));
                            }
                        }
                    }
                }
            }, true, true);

            /*Debug.Log("created graph parts: " + bakedGraphParts.Count);
             * foreach (var kp in bakedGraphParts)
             * {
             *      Debug.Log("to compute list for node " + kp.Key);
             *      foreach (var ne in kp.Value)
             *              Debug.Log("\tne: " + ne.node.nodeId);
             * }*/
        }