Esempio n. 1
0
        public void Test_RemoveNodesAction([Values] TestingMode mode)
        {
            var        constantA  = GraphModel.CreateConstantNode("constantA", typeof(int).GenerateTypeHandle(Stencil), Vector2.zero);
            var        binary0    = GraphModel.CreateNode <Type0FakeNodeModel>("Node1", Vector2.zero);
            var        binary1    = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            IPortModel outputPort = constantA.OutputPort;

            GraphModel.CreateEdge(binary0.Input0, outputPort);
            IPortModel outputPort1 = binary0.Output0;

            GraphModel.CreateEdge(binary1.InputPortA, outputPort1);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                var nodeToDeleteAndBypass = GraphModel.NodeModels.OfType <Type0FakeNodeModel>().First();

                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(2));
                Assert.That(nodeToDeleteAndBypass.Input0, Is.ConnectedTo(constantA.OutputPort));
                Assert.That(binary1.InputPortA, Is.ConnectedTo(nodeToDeleteAndBypass.Output0));
                return(new RemoveNodesAction(new INodeModel[] { nodeToDeleteAndBypass }, new INodeModel[] { nodeToDeleteAndBypass }));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(binary1.InputPortA, Is.ConnectedTo(constantA.OutputPort));
            });
        }
Esempio n. 2
0
        public void MacroPortsRemainConnectedAfterMacroAssetDeletion()
        {
            FunctionCallNodeModel[] log;
            CreateStackAndLogs(out _, out log);
            var binOp = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var varA  = GraphModel.CreateVariableNode(m_ADecl, Vector2.zero);

            GraphModel.CreateEdge(log[0].GetParameterPorts().First(), binOp.OutputPort);
            GraphModel.CreateEdge(binOp.InputPortA, varA.OutputPort);
            GraphModel.CreateEdge(binOp.InputPortB, varA.OutputPort);

            TestPrereqActionPostreq(TestingMode.Action, () =>
            {
                binOp = GraphModel.NodeModels.OfType <BinaryOperatorNodeModel>().Single();
                Assert.That(GraphModel.NodeModels.Count, Is.EqualTo(3));
                Assert.That(GraphModel.NodeModels.OfType <MacroRefNodeModel>().Count(), Is.Zero);
                Assert.That(binOp.InputPortA, Is.ConnectedTo(varA.OutputPort));
                Assert.That(binOp.InputPortB, Is.ConnectedTo(varA.OutputPort));
                Assert.That(binOp.OutputPort, Is.ConnectedTo(log[0].GetParameterPorts().First()));
                return(new RefactorExtractMacroAction(new List <IGraphElementModel> {
                    binOp
                }, Vector2.zero, null));
            }, () =>
            {
                Assert.That(GraphModel.NodeModels.Count, Is.EqualTo(3));

                var macroRef             = GraphModel.NodeModels.OfType <MacroRefNodeModel>().Single();
                macroRef.GraphAssetModel = null;
                macroRef.DefineNode();

                Assert.That(macroRef, Is.Not.Null);
                Assert.That(macroRef.InputVariablePorts.First(), Is.ConnectedTo(varA.OutputPort));
                Assert.That(macroRef.OutputVariablePorts.First(), Is.ConnectedTo(log[0].GetParameterPorts().First()));
            });
        }
Esempio n. 3
0
        public void Test_ConvertConstantNodeToVariableNodeAction([Values] TestingMode mode)
        {
            var        binary     = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var        constant   = GraphModel.CreateConstantNode("const0", typeof(int).GenerateTypeHandle(Stencil), Vector2.zero);
            IPortModel outputPort = constant.OutputPort;

            GraphModel.CreateEdge(binary.InputPortA, outputPort);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                var c = GraphModel.GetAllNodes().OfType <IConstantNodeModel>().First();
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0));
                Assert.That(GetNode(1), Is.TypeOf <IntConstantModel>());

                var n0 = (BinaryOperatorNodeModel)GetNode(0);
                var n1 = (IntConstantModel)GetNode(1);
                Assert.That(n0.InputPortA, Is.ConnectedTo(n1.OutputPort));
                return(new ConvertConstantNodesToVariableNodesAction(c));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1));
                Assert.That(GetNode(1), Is.TypeOf <VariableNodeModel>());

                var n0 = (BinaryOperatorNodeModel)GetNode(0);
                var n1 = (VariableNodeModel)GetNode(1);
                Assert.That(n0.InputPortA, Is.ConnectedTo(n1.OutputPort));
                Assert.That(n1.DataType, Is.EqualTo(typeof(int).GenerateTypeHandle(Stencil)));
            });
        }
Esempio n. 4
0
        public void Test_ConvertVariableNodeToConstantNodeAction([Values] TestingMode mode)
        {
            var        declaration0 = GraphModel.CreateGraphVariableDeclaration("decl0", typeof(int).GenerateTypeHandle(Stencil), true);
            var        node0        = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var        node1        = GraphModel.CreateVariableNode(declaration0, Vector2.zero);
            IPortModel outputPort   = node1.OutputPort;

            GraphModel.CreateEdge(node0.InputPortA, outputPort);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1));
                Assert.That(GetNode(1), Is.TypeOf <VariableNodeModel>());
                var n0 = (BinaryOperatorNodeModel)GetNode(0);
                var n1 = (VariableNodeModel)GetNode(1);
                Assert.That(n0.InputPortA, Is.ConnectedTo(n1.OutputPort));
                return(new ConvertVariableNodesToConstantNodesAction(node1));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1));
                Assert.That(GetNode(1), Is.TypeOf <IntConstantModel>());

                var n0 = (BinaryOperatorNodeModel)GetNode(0);
                var n1 = (IntConstantModel)GetNode(1);
                Assert.That(n0.InputPortA, Is.ConnectedTo(n1.OutputPort));
            });
        }
Esempio n. 5
0
        public void Test_SplitEdgeAndInsertNodeAction([Values] TestingMode mode)
        {
            var constant = GraphModel.CreateConstantNode("Constant", typeof(int).GenerateTypeHandle(Stencil), Vector2.zero);
            var binary0  = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var binary1  = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var edge     = GraphModel.CreateEdge(binary0.InputPortA, constant.OutputPort);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                RefreshReference(ref constant);
                RefreshReference(ref binary0);
                RefreshReference(ref binary1);
                edge = GetEdge(0);
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(binary0.InputPortA, Is.ConnectedTo(constant.OutputPort));
                return(new SplitEdgeAndInsertNodeAction(edge, binary1));
            },
                                    () =>
            {
                RefreshReference(ref constant);
                RefreshReference(ref binary0);
                RefreshReference(ref binary1);
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(2));
                Assert.That(binary1.InputPortA, Is.ConnectedTo(constant.OutputPort));
                Assert.That(binary0.InputPortA, Is.ConnectedTo(binary1.OutputPort));
            });
        }
Esempio n. 6
0
        public void ExtractLinkedThreeNodesWithOneSharedInput()
        {
            // a > b && a < c

            FunctionCallNodeModel[] log;
            CreateStackAndLogs(out _, out log);
            var greater = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.GreaterThan, Vector2.zero);
            var lower   = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.LessThan, Vector2.zero);
            var and     = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.LogicalAnd, Vector2.zero);
            var varA    = GraphModel.CreateVariableNode(m_ADecl, Vector2.zero);
            var varB    = GraphModel.CreateVariableNode(m_BDecl, Vector2.zero);
            var varC    = GraphModel.CreateVariableNode(m_CDecl, Vector2.zero);

            List <IGraphElementModel> extract = new List <IGraphElementModel>
            {
                greater, lower, and,
            };

            GraphModel.CreateEdge(log[0].GetParameterPorts().First(), and.OutputPort);
            extract.Add(GraphModel.CreateEdge(and.InputPortA, greater.OutputPort));
            extract.Add(GraphModel.CreateEdge(and.InputPortB, lower.OutputPort));

            GraphModel.CreateEdge(greater.InputPortA, varA.OutputPort);
            GraphModel.CreateEdge(greater.InputPortB, varB.OutputPort);

            GraphModel.CreateEdge(lower.InputPortA, varA.OutputPort);
            GraphModel.CreateEdge(lower.InputPortB, varC.OutputPort);

            TestExtractMacro(extract,
                             new IO(varA.OutputPort, varB.OutputPort, varC.OutputPort),
                             new IO(log[0].GetParameterPorts().First()));
        }
Esempio n. 7
0
        public void TestCreateNodeOnEdge_WithOutputNodeConnectedToUnknown([Values] TestingMode mode)
        {
            var constantNode = GraphModel.CreateConstantNode("int1", typeof(int).GenerateTypeHandle(Stencil), Vector2.zero);
            var addNode      = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

            GraphModel.CreateEdge(addNode.InputPortA, constantNode.OutputPort);
            GraphModel.CreateEdge(addNode.InputPortB, constantNode.OutputPort);

            var db   = new GraphElementSearcherDatabase(Stencil).AddBinaryOperators().Build();
            var item = (GraphNodeModelSearcherItem)db.Search("multiply", out _)[0];

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(2));

                Assert.That(addNode, Is.Not.Null);
                Assert.That(addNode.InputPortA, Is.ConnectedTo(constantNode.OutputPort));
                var edge = GraphModel.EdgeModels.First();
                return(new CreateNodeOnEdgeAction(edge, Vector2.zero, item));
            },
                                    () =>
            {
                var multiplyNode = GraphModel.NodeModels.OfType <BinaryOperatorNodeModel>().ToList()[1];

                Assert.IsNotNull(multiplyNode);
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(3));
                Assert.That(constantNode.OutputPort, Is.ConnectedTo(multiplyNode.InputPortA));
                Assert.That(multiplyNode.OutputPort, Is.ConnectedTo(addNode.InputPortA));
                Assert.That(constantNode.OutputPort, Is.Not.ConnectedTo(addNode.InputPortA));
            }
                                    );
        }
        public void Test_ItemizeSystemConstantNodeAction([Values] TestingMode mode)
        {
            void PreDefineSetup(SystemConstantNodeModel m)
            {
                m.ReturnType    = typeof(float).GenerateTypeHandle(Stencil);
                m.DeclaringType = typeof(Mathf).GenerateTypeHandle(Stencil);
                m.Identifier    = "PI";
            }

            var constant = GraphModel.CreateNode <SystemConstantNodeModel>("Constant", Vector2.zero, SpawnFlags.Default, PreDefineSetup);

            var binary0 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var binary1 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

            IPortModel outputPort = constant.OutputPort;

            GraphModel.CreateEdge(binary0.InputPortA, outputPort);
            IPortModel outputPort1 = constant.OutputPort;

            GraphModel.CreateEdge(binary0.InputPortB, outputPort1);
            IPortModel outputPort2 = constant.OutputPort;

            GraphModel.CreateEdge(binary1.InputPortA, outputPort2);
            IPortModel outputPort3 = constant.OutputPort;

            GraphModel.CreateEdge(binary1.InputPortB, outputPort3);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                RefreshReference(ref constant);
                RefreshReference(ref binary0);
                RefreshReference(ref binary1);
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(4));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0));
                Assert.That(GetAllNodes().OfType <SystemConstantNodeModel>().Count(), Is.EqualTo(1));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary0.InputPortA));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary0.InputPortB));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary0.InputPortA));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary1.InputPortB));
                return(new ItemizeSystemConstantNodeAction(constant));
            },
                                    () =>
            {
                RefreshReference(ref constant);
                RefreshReference(ref binary0);
                RefreshReference(ref binary1);
                Assert.That(GetNodeCount(), Is.EqualTo(6));
                Assert.That(GetEdgeCount(), Is.EqualTo(4));
                Assert.That(GetAllNodes().OfType <SystemConstantNodeModel>().Count(), Is.EqualTo(4));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary0.InputPortA));
                Assert.That(constant.OutputPort, Is.Not.ConnectedTo(binary0.InputPortB));
                Assert.That(constant.OutputPort, Is.Not.ConnectedTo(binary1.InputPortA));
                Assert.That(constant.OutputPort, Is.Not.ConnectedTo(binary1.InputPortB));
            });
        }
        public void TestWaitUntilCoroutine([Values] CodeGenMode mode)
        {
            float yBeforeWait = 0f;
            float yAfterWait  = 10f;

            SetupTestGraphMultipleFrames(mode, graph =>
            {
                var query = SetupQuery(graph, "query", new[] { typeof(Translation) });

                var onUpdate  = SetupOnUpdate(graph, query);
                var waitUntil = onUpdate.CreateStackedNode <CoroutineNodeModel>("Wait Until", setup: n =>
                {
                    n.CoroutineType = typeof(WaitUntil).GenerateTypeHandle(Stencil);
                });
                var translation = graph.CreateVariableNode(onUpdate.FunctionParameterModels.Single(p =>
                                                                                                   p.DataType == typeof(Translation).GenerateTypeHandle(Stencil)), Vector2.zero);
                var getProperty        = GraphModel.CreateGetPropertyGroupNode(Vector2.zero);
                var translationXMember = new TypeMember(TypeHandle.Float, new List <string>
                {
                    nameof(Translation.Value), nameof(Translation.Value.x)
                });
                getProperty.AddMember(translationXMember);
                GraphModel.CreateEdge(getProperty.InstancePort, translation.OutputPort);
                var equalNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.GreaterThan, Vector2.zero);
                GraphModel.CreateEdge(equalNode.InputPortA, getProperty.GetPortsForMembers().Single());
                ((FloatConstantModel)equalNode.InputConstantsById[equalNode.InputPortB.UniqueId]).value = 0f;
                var moveNextParam = typeof(WaitUntil).GetMethod(nameof(WaitUntil.MoveNext))?.GetParameters().Single();
                Assert.That(moveNextParam, Is.Not.Null);
                GraphModel.CreateEdge(waitUntil.GetParameterPort(moveNextParam), equalNode.OutputPort);

                var setProperty        = onUpdate.CreateSetPropertyGroupNode(-1);
                var translationYMember = new TypeMember(TypeHandle.Float, new List <string>
                {
                    nameof(Translation.Value), nameof(Translation.Value.y)
                });
                setProperty.AddMember(translationYMember);
                GraphModel.CreateEdge(setProperty.InstancePort, translation.OutputPort);
                ((FloatConstantModel)setProperty.InputConstantsById[translationYMember.GetId()]).value = yAfterWait;
            },
                                         EachEntity((manager, i, e) =>
            {
                manager.AddComponentData(e, new Translation());
            }),
                                         EachEntity((manager, i, e) =>
            {
                Assert.That(manager.GetComponentData <Translation>(e).Value.y, Is.EqualTo(yBeforeWait));
                manager.SetComponentData(e, new Translation {
                    Value = { x = 10f }
                });                                                 // any x > 0 should stop this WaitUntil
            }),
                                         (manager, entities) => {}, // Skip Frame where WaitUntil is done and component gets set
                                         EachEntity((manager, i, e) =>
            {
                Assert.That(manager.GetComponentData <Translation>(e).Value.y, Is.EqualTo(yAfterWait));
            })
                                         );
        }
        public void DeleteNodeDoesRemoveTheDependency()
        {
            var mgr = new PositionDependenciesManager(GraphView, GraphView.window.Preferences);
            BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100));
            IConstantNodeModel      intModel      = GraphModel.CreateConstantNode("int", typeof(int).GenerateTypeHandle(GraphModel.Stencil), new Vector2(-150, -100));
            var edge = GraphModel.CreateEdge(operatorModel.InputPortA, intModel.OutputPort);

            mgr.AddPositionDependency(edge);
            mgr.Remove(operatorModel.Guid, intModel.Guid);
            Assert.That(mgr.GetDependencies(operatorModel), Is.Null);
        }
        public IEnumerator MovingAFloatingNodeMovesConnectedToken([Values] TestingMode mode)
        {
            BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100));
            IConstantNodeModel      intModel      = GraphModel.CreateConstantNode("int", typeof(int).GenerateTypeHandle(GraphModel.Stencil), new Vector2(-150, -100));

            GraphModel.CreateEdge(operatorModel.InputPortA, intModel.OutputPort);

            yield return(TestMove(mode,
                                  mouseDelta: new Vector2(20, 10),
                                  movedNodes: new INodeModel[] { operatorModel },
                                  expectedMovedDependencies: new INodeModel[] { intModel }
                                  ));
        }
        public void Test_ItemizeVariableNodeAction([Values] TestingMode mode)
        {
            var declaration = GraphModel.CreateGraphVariableDeclaration("decl0", typeof(int).GenerateTypeHandle(Stencil), true);
            var variable    = GraphModel.CreateVariableNode(declaration, Vector2.zero);
            var binary0     = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var binary1     = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

            IPortModel outputPort = variable.OutputPort;

            GraphModel.CreateEdge(binary0.InputPortA, outputPort);
            IPortModel outputPort1 = variable.OutputPort;

            GraphModel.CreateEdge(binary0.InputPortB, outputPort1);
            IPortModel outputPort2 = variable.OutputPort;

            GraphModel.CreateEdge(binary1.InputPortA, outputPort2);
            IPortModel outputPort3 = variable.OutputPort;

            GraphModel.CreateEdge(binary1.InputPortB, outputPort3);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                RefreshReference(ref variable);
                RefreshReference(ref binary0);
                RefreshReference(ref binary1);
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(4));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1));
                Assert.That(GetAllNodes().OfType <VariableNodeModel>().Count(), Is.EqualTo(1));
                Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.InputPortA));
                Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.InputPortB));
                Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.InputPortA));
                Assert.That(variable.OutputPort, Is.ConnectedTo(binary1.InputPortB));
                return(new ItemizeVariableNodeAction(variable));
            },
                                    () =>
            {
                RefreshReference(ref variable);
                RefreshReference(ref binary0);
                RefreshReference(ref binary1);
                Assert.That(GetNodeCount(), Is.EqualTo(6));
                Assert.That(GetEdgeCount(), Is.EqualTo(4));
                Assert.That(GetAllNodes().OfType <VariableNodeModel>().Count(), Is.EqualTo(4));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1));
                Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.InputPortA));
                Assert.That(variable.OutputPort, Is.Not.ConnectedTo(binary0.InputPortB));
                Assert.That(variable.OutputPort, Is.Not.ConnectedTo(binary1.InputPortA));
                Assert.That(variable.OutputPort, Is.Not.ConnectedTo(binary1.InputPortB));
            });
        }
        public void Test_DeleteElementsAction_VariableUsage([Values] TestingMode mode)
        {
            var declaration0 = GraphModel.CreateGraphVariableDeclaration("decl0", typeof(int).GenerateTypeHandle(Stencil), true);
            var declaration1 = GraphModel.CreateGraphVariableDeclaration("decl1", typeof(int).GenerateTypeHandle(Stencil), true);

            var node0 = GraphModel.CreateVariableNode(declaration0, Vector2.zero);
            var node1 = GraphModel.CreateVariableNode(declaration0, Vector2.zero);
            var node2 = GraphModel.CreateVariableNode(declaration1, Vector2.zero);
            var node3 = GraphModel.CreateVariableNode(declaration1, Vector2.zero);
            var node4 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var node5 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

            GraphModel.CreateEdge(node4.InputPortA, node0.OutputPort);
            GraphModel.CreateEdge(node4.InputPortB, node2.OutputPort);
            GraphModel.CreateEdge(node5.InputPortA, node1.OutputPort);
            GraphModel.CreateEdge(node5.InputPortB, node3.OutputPort);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                declaration0 = GetVariableDeclaration(0);
                declaration1 = GetVariableDeclaration(1);
                Assert.That(GetNodeCount(), Is.EqualTo(6), "GetNodeCount1");
                Assert.That(GetEdgeCount(), Is.EqualTo(4));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(2), "GetVariableDeclarationCount");
                return(new DeleteElementsAction(declaration0));
            },
                                    () =>
            {
                declaration1 = GetVariableDeclaration(0);
                Assert.That(GetNodeCount(), Is.EqualTo(4), "GetNodeCount2");
                Assert.That(GetEdgeCount(), Is.EqualTo(2), "EdgeCount");
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1), "GetVariableDeclarationCount");
            });

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                declaration1 = GetVariableDeclaration(0);
                Assert.That(GetNodeCount(), Is.EqualTo(4), "GetNodeCount3");
                Assert.That(GetEdgeCount(), Is.EqualTo(2), "EdgeCount");
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1), "GetVariableDeclarationCount");
                return(new DeleteElementsAction(declaration1));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2), "GetNodeCount");
                Assert.That(GetEdgeCount(), Is.EqualTo(0), "EdgeCount");
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0));
            });
        }
Esempio n. 14
0
        public void Test_ChangeNodeColorAction([Values] TestingMode mode)
        {
            var node0 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var node1 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var node2 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var node3 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(4));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));
                Assert.That(node0.Color, Is.EqualTo(Color.clear));
                Assert.That(node1.Color, Is.EqualTo(Color.clear));
                Assert.That(node2.Color, Is.EqualTo(Color.clear));
                Assert.That(node3.Color, Is.EqualTo(Color.clear));
                return(new ChangeNodeColorAction(Color.red, node0));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(4));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));
                Assert.That(node0.Color, Is.EqualTo(Color.red));
                Assert.That(node1.Color, Is.EqualTo(Color.clear));
                Assert.That(node2.Color, Is.EqualTo(Color.clear));
                Assert.That(node3.Color, Is.EqualTo(Color.clear));
            });

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(4));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));
                Assert.That(node0.Color, Is.EqualTo(Color.red));
                Assert.That(node1.Color, Is.EqualTo(Color.clear));
                Assert.That(node2.Color, Is.EqualTo(Color.clear));
                Assert.That(node3.Color, Is.EqualTo(Color.clear));
                return(new ChangeNodeColorAction(Color.blue, node1, node2));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(4));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));
                Assert.That(node0.Color, Is.EqualTo(Color.red));
                Assert.That(node1.Color, Is.EqualTo(Color.blue));
                Assert.That(node2.Color, Is.EqualTo(Color.blue));
                Assert.That(node3.Color, Is.EqualTo(Color.clear));
            });
        }
Esempio n. 15
0
        public void Test_DisconnectNodeAction([Values] TestingMode mode)
        {
            var const0  = GraphModel.CreateConstantNode("const0", typeof(float).GenerateTypeHandle(Stencil), Vector2.zero);
            var const1  = GraphModel.CreateConstantNode("const1", typeof(float).GenerateTypeHandle(Stencil), Vector2.zero);
            var const2  = GraphModel.CreateConstantNode("const2", typeof(float).GenerateTypeHandle(Stencil), Vector2.zero);
            var const3  = GraphModel.CreateConstantNode("const3", typeof(float).GenerateTypeHandle(Stencil), Vector2.zero);
            var const4  = GraphModel.CreateConstantNode("const4", typeof(float).GenerateTypeHandle(Stencil), Vector2.zero);
            var const5  = GraphModel.CreateConstantNode("const5", typeof(float).GenerateTypeHandle(Stencil), Vector2.zero);
            var binary0 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var binary1 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var binary2 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var binary3 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

            GraphModel.CreateEdge(binary0.InputPortA, const0.OutputPort);
            GraphModel.CreateEdge(binary0.InputPortB, const1.OutputPort);
            GraphModel.CreateEdge(binary1.InputPortA, binary0.OutputPort);
            GraphModel.CreateEdge(binary1.InputPortB, const0.OutputPort);
            GraphModel.CreateEdge(binary2.InputPortA, const2.OutputPort);
            GraphModel.CreateEdge(binary2.InputPortB, const3.OutputPort);
            GraphModel.CreateEdge(binary3.InputPortA, const4.OutputPort);
            GraphModel.CreateEdge(binary3.InputPortB, const5.OutputPort);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(10));
                Assert.That(GetEdgeCount(), Is.EqualTo(8));
                return(new DisconnectNodeAction(binary0));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(10));
                Assert.That(GetEdgeCount(), Is.EqualTo(5));
            });

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(10));
                Assert.That(GetEdgeCount(), Is.EqualTo(5));
                return(new DisconnectNodeAction(binary2, binary3));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(10));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
            });
        }
        public IEnumerator MovingAStackMovesStackedNodeConnectedFloatingNode([Values] TestingMode mode)
        {
            var stackModel0 = GraphModel.CreateStack(string.Empty, new Vector2(-100, -100));
            UnaryOperatorNodeModel  unary         = stackModel0.CreateStackedNode <UnaryOperatorNodeModel>("postDecr", setup: n => n.kind = UnaryOperatorKind.PostDecrement);
            BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100));
            IConstantNodeModel      intModel      = GraphModel.CreateConstantNode("int", typeof(int).GenerateTypeHandle(GraphModel.Stencil), new Vector2(-150, -100));

            GraphModel.CreateEdge(unary.InputPort, operatorModel.OutputPort);
            GraphModel.CreateEdge(operatorModel.InputPortA, intModel.OutputPort);

            yield return(TestMove(mode,
                                  mouseDelta: new Vector2(20, 10),
                                  movedNodes: new INodeModel[] { stackModel0 },
                                  expectedMovedDependencies: new INodeModel[] { operatorModel, intModel }
                                  ));
        }
Esempio n. 17
0
        public IEnumerator PanToNodeChangesViewTransform()
        {
            BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100));
            var stackModel0 = GraphModel.CreateStack("Stack 1", new Vector2(100, -100));
            var stackModel1 = GraphModel.CreateStack("Stack 2", new Vector2(100, 100));

            GraphModel.CreateEdge(stackModel1.InputPorts[0], stackModel0.OutputPorts[0]);
            var nodeA = stackModel0.CreateStackedNode <Type0FakeNodeModel>("A");
            var nodeB = stackModel0.CreateStackedNode <Type0FakeNodeModel>("B");

            Store.Dispatch(new RefreshUIAction(UpdateFlags.All));
            yield return(null);

            GraphView.viewTransformChanged += view => m_Changed = true;

            yield return(SendPanToNodeAndRefresh(stackModel0));

            yield return(SendPanToNodeAndRefresh(stackModel1));

            yield return(SendPanToNodeAndRefresh(operatorModel));

            yield return(SendPanToNodeAndRefresh(nodeA));

            yield return(SendPanToNodeAndRefresh(nodeB));

            IEnumerator SendPanToNodeAndRefresh(NodeModel nodeModel)
            {
                m_Changed = false;

                Store.Dispatch(new PanToNodeAction(nodeModel.Guid));
                yield return(null);

                Store.Dispatch(new RefreshUIAction(UpdateFlags.All));
                yield return(null);

                Assert.IsTrue(m_Changed, "ViewTransform didn't change");
                Assert.That(GraphView.selection.
                            OfType <IHasGraphElementModel>().
                            Where(x => x.GraphElementModel is INodeModel n && n.Guid == nodeModel.Guid).Any,
                            () =>
                {
                    var graphViewSelection = String.Join(",", GraphView.selection);
                    return($"Selection doesn't contain {nodeModel} {nodeModel.Title} but {graphViewSelection}");
                });
            }
        }
Esempio n. 18
0
        public void ExtractSingleNodeWithSameInputsCreatesOnlyOneMacroInput()
        {
            // a + a

            FunctionCallNodeModel[] log;
            CreateStackAndLogs(out _, out log);
            var binOp = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var varA  = GraphModel.CreateVariableNode(m_ADecl, Vector2.zero);

            GraphModel.CreateEdge(log[0].GetParameterPorts().First(), binOp.OutputPort);
            GraphModel.CreateEdge(binOp.InputPortA, varA.OutputPort);
            GraphModel.CreateEdge(binOp.InputPortB, varA.OutputPort);

            TestExtractMacro(new[] { binOp },
                             inputs: new IO(varA.OutputPort),
                             outputs: new IO(log[0].GetParameterPorts().First()));
        }
Esempio n. 19
0
        public void Test_ItemizeConstantNodeAction([Values] TestingMode mode)
        {
            var constant = GraphModel.CreateConstantNode("Constant", typeof(int).GenerateTypeHandle(Stencil), Vector2.zero);
            var binary0  = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var binary1  = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

            IPortModel outputPort = constant.OutputPort;

            GraphModel.CreateEdge(binary0.InputPortA, outputPort);
            IPortModel outputPort1 = constant.OutputPort;

            GraphModel.CreateEdge(binary0.InputPortB, outputPort1);
            IPortModel outputPort2 = constant.OutputPort;

            GraphModel.CreateEdge(binary1.InputPortA, outputPort2);
            IPortModel outputPort3 = constant.OutputPort;

            GraphModel.CreateEdge(binary1.InputPortB, outputPort3);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(4));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0));
                Assert.That(GetAllNodes().OfType <IntConstantModel>().Count(), Is.EqualTo(1));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary0.InputPortA));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary0.InputPortB));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary0.InputPortA));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary1.InputPortB));
                return(new ItemizeConstantNodeAction(constant));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(6));
                Assert.That(GetEdgeCount(), Is.EqualTo(4));
                Assert.That(GetAllNodes().OfType <IntConstantModel>().Count(), Is.EqualTo(4));
                Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary0.InputPortA));
                Assert.That(constant.OutputPort, Is.Not.ConnectedTo(binary0.InputPortB));
                Assert.That(constant.OutputPort, Is.Not.ConnectedTo(binary1.InputPortA));
                Assert.That(constant.OutputPort, Is.Not.ConnectedTo(binary1.InputPortB));
            });
        }
Esempio n. 20
0
        public IEnumerator PanToNodeChangesViewTransform()
        {
            BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100));
            var stackModel0 = GraphModel.CreateStack(string.Empty, new Vector2(100, -100));
            var stackModel1 = GraphModel.CreateStack(string.Empty, new Vector2(100, 100));

            GraphModel.CreateEdge(stackModel1.InputPorts[0], stackModel0.OutputPorts[0]);
            var nodeA = stackModel0.CreateStackedNode <Type0FakeNodeModel>("A");
            var nodeB = stackModel0.CreateStackedNode <Type0FakeNodeModel>("B");

            Store.Dispatch(new RefreshUIAction(UpdateFlags.All));
            yield return(null);

            GraphView.viewTransformChanged += view => m_Changed = true;

            yield return(SendPanToNodeAndRefresh(stackModel0));

            yield return(SendPanToNodeAndRefresh(stackModel1));

            yield return(SendPanToNodeAndRefresh(operatorModel));

            yield return(SendPanToNodeAndRefresh(nodeA));

            yield return(SendPanToNodeAndRefresh(nodeB));

            IEnumerator SendPanToNodeAndRefresh(NodeModel nodeModel)
            {
                m_Changed = false;

                Store.Dispatch(new PanToNodeAction(nodeModel.Guid));
                yield return(null);

                Store.Dispatch(new RefreshUIAction(UpdateFlags.All));
                yield return(null);

                Assert.IsTrue(m_Changed);
                Assert.That(GraphView.selection.
                            OfType <IHasGraphElementModel>().
                            ToList().
                            Where(x => ReferenceEquals(x.GraphElementModel, nodeModel)).Any);
            }
        }
Esempio n. 21
0
        public void ExtractTwoUnrelatedNodes()
        {
            // a/b and a%b

            FunctionCallNodeModel[] log;
            CreateStackAndLogs(out _, out log, 2);
            var divide = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Divide, Vector2.zero);
            var modulo = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Modulo, Vector2.zero);
            var varA   = GraphModel.CreateVariableNode(m_ADecl, Vector2.zero);
            var varB   = GraphModel.CreateVariableNode(m_BDecl, Vector2.zero);

            GraphModel.CreateEdge(log[0].GetParameterPorts().First(), divide.OutputPort);
            GraphModel.CreateEdge(log[1].GetParameterPorts().First(), modulo.OutputPort);
            GraphModel.CreateEdge(divide.InputPortA, varA.OutputPort);
            GraphModel.CreateEdge(modulo.InputPortA, varA.OutputPort);
            GraphModel.CreateEdge(divide.InputPortB, varB.OutputPort);
            GraphModel.CreateEdge(modulo.InputPortB, varB.OutputPort);

            TestExtractMacro(new[] { divide, modulo },
                             inputs: new IO(varA.OutputPort, varB.OutputPort),
                             outputs: new IO(log[0].GetParameterPorts().First(), log[1].GetParameterPorts().First()));
        }
Esempio n. 22
0
        // create a function bool IsIntEven(int i)
        //      if ((i % 2) == 0) { return true; } else { return false; }
        // the goal is to have 2 different return nodes depending on a parameter
        FunctionModel CreateIsIntEvenFunction()
        {
            // define function
            FunctionModel method = GraphModel.CreateFunction("IsIntEven", Vector2.zero);

            method.ReturnType = typeof(bool).GenerateTypeHandle(GraphModel.Stencil);
            VariableDeclarationModel paramI = method.CreateAndRegisterFunctionParameterDeclaration("i", typeof(int).GenerateTypeHandle(GraphModel.Stencil));

            // add if/then/else structure
            IfConditionNodeModel if0 = CreateIfThenElseStacks(method, out var then0, out var else0);

            // if (i % 2 == 0)
            var            binOpNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Modulo, Vector2.zero);
            IVariableModel varI      = GraphModel.CreateVariableNode(paramI, Vector2.left);
            var            const2    = CreateConstantIntNode(2);

            GraphModel.CreateEdge(binOpNode.InputPortA, varI.OutputPort);
            GraphModel.CreateEdge(binOpNode.InputPortB, const2.OutputPort);
            var equalNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Equals, Vector2.zero);
            var const0    = CreateConstantIntNode(0);

            GraphModel.CreateEdge(equalNode.InputPortA, binOpNode.OutputPort);
            GraphModel.CreateEdge(equalNode.InputPortB, const0.OutputPort);
            GraphModel.CreateEdge(if0.IfPort, equalNode.OutputPort);

            // then return true
            var returnTrue = then0.CreateStackedNode <ReturnNodeModel>("return true");
            var constTrue  = CreateConstantBoolNode(true);

            GraphModel.CreateEdge(returnTrue.InputPort, constTrue.OutputPort);

            // else return false
            var returnFalse = else0.CreateStackedNode <ReturnNodeModel>("return false");
            var constFalse  = CreateConstantBoolNode(false);

            GraphModel.CreateEdge(returnFalse.InputPort, constFalse.OutputPort);
            return(method);
        }
Esempio n. 23
0
        public void ExtractMacroIsUndoable()
        {
            FunctionCallNodeModel[] log;
            CreateStackAndLogs(out _, out log);
            var binOp = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var varA  = GraphModel.CreateVariableNode(m_ADecl, Vector2.zero);

            GraphModel.CreateEdge(log[0].GetParameterPorts().First(), binOp.OutputPort);
            GraphModel.CreateEdge(binOp.InputPortA, varA.OutputPort);
            GraphModel.CreateEdge(binOp.InputPortB, varA.OutputPort);
            Undo.IncrementCurrentGroup();
            TestPrereqActionPostreq(TestingMode.UndoRedo, () =>
            {
                RefreshReference(ref binOp);
                RefreshReference(ref varA);
                RefreshReference(ref log[0]);
                Assert.That(GraphModel.NodeModels.Count, Is.EqualTo(3));
                Assert.That(GraphModel.NodeModels.OfType <MacroRefNodeModel>().Count(), Is.Zero);
                Assert.That(binOp.InputPortA, Is.ConnectedTo(varA.OutputPort));
                Assert.That(binOp.InputPortB, Is.ConnectedTo(varA.OutputPort));
                Assert.That(binOp.OutputPort, Is.ConnectedTo(log[0].GetParameterPorts().First()));
                return(new RefactorExtractMacroAction(new List <IGraphElementModel> {
                    binOp
                }, Vector2.zero, null));
            }, () =>
            {
                RefreshReference(ref binOp);
                RefreshReference(ref varA);
                RefreshReference(ref log[0]);
                Assert.That(GraphModel.NodeModels.Count, Is.EqualTo(3));
                var macroRef = GraphModel.NodeModels.OfType <MacroRefNodeModel>().Single();
                Assert.That(macroRef, Is.Not.Null);
                Assert.That(macroRef.InputVariablePorts.First(), Is.ConnectedTo(varA.OutputPort));
                Assert.That(macroRef.OutputVariablePorts.First(), Is.ConnectedTo(log[0].GetParameterPorts().First()));
            });
        }
Esempio n. 24
0
        public void Test_CreateEdgeAction_Itemize(TestingMode testingMode, ItemizeOptions options, ItemizeTestType itemizeTest, Func <VSGraphModel, IHasMainOutputPort> makeNode)
        {
            // save initial itemize options
            VSPreferences  pref           = ((TestState)m_Store.GetState()).Preferences;
            ItemizeOptions initialOptions = pref.CurrentItemizeOptions;

            try
            {
                // create int node
                IHasMainOutputPort node0 = makeNode(GraphModel);

                // create Addition node
                BinaryOperatorNodeModel opNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

                // enable Itemize depending on the test case
                var itemizeOptions = ItemizeOptions.Nothing;
                pref.CurrentItemizeOptions = (itemizeTest == ItemizeTestType.Enabled) ? options : itemizeOptions;

                // connect int to first input
                m_Store.Dispatch(new CreateEdgeAction(opNode.InputPortA, node0.OutputPort));
                m_Store.Update();

                // test how the node reacts to getting connected a second time
                TestPrereqActionPostreq(testingMode,
                                        () =>
                {
                    RefreshReference(ref node0);
                    RefreshReference(ref opNode);
                    var binOp            = GraphModel.GetAllNodes().OfType <BinaryOperatorNodeModel>().First();
                    IPortModel input0    = binOp.InputPortA;
                    IPortModel input1    = binOp.InputPortB;
                    IPortModel binOutput = binOp.OutputPort;
                    Assert.That(GetNodeCount(), Is.EqualTo(2));
                    Assert.That(GetEdgeCount(), Is.EqualTo(1));
                    Assert.That(input0, Is.ConnectedTo(node0.OutputPort));
                    Assert.That(input1, Is.Not.ConnectedTo(node0.OutputPort));
                    Assert.That(binOutput.Connected, Is.False);
                    return(new CreateEdgeAction(input1, node0.OutputPort));
                },
                                        () =>
                {
                    RefreshReference(ref node0);
                    RefreshReference(ref opNode);
                    var binOp            = GraphModel.GetAllNodes().OfType <BinaryOperatorNodeModel>().First();
                    IPortModel input0    = binOp.InputPortA;
                    IPortModel input1    = binOp.InputPortB;
                    IPortModel binOutput = binOp.OutputPort;
                    Assert.That(GetEdgeCount(), Is.EqualTo(2));
                    Assert.That(input0, Is.ConnectedTo(node0.OutputPort));
                    Assert.That(binOutput.Connected, Is.False);

                    if (itemizeTest == ItemizeTestType.Enabled)
                    {
                        Assert.That(GetNodeCount(), Is.EqualTo(3));
                        IHasMainOutputPort newNode = GetNode(2) as IHasMainOutputPort;
                        Assert.NotNull(newNode);
                        Assert.That(newNode, Is.TypeOf(node0.GetType()));
                        IPortModel output1 = newNode.OutputPort;
                        Assert.That(input1, Is.ConnectedTo(output1));
                    }
                    else
                    {
                        Assert.That(GetNodeCount(), Is.EqualTo(2));
                    }
                });
            }
            finally
            {
                // restore itemize options
                pref.CurrentItemizeOptions = initialOptions;
            }
        }
Esempio n. 25
0
        public void Test_BypassNodeAction([Values] TestingMode mode)
        {
            var constantA = GraphModel.CreateConstantNode("constantA", typeof(float).GenerateTypeHandle(Stencil), Vector2.zero);
            var binary0   = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var binary1   = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

            GraphModel.CreateEdge(binary0.InputPortA, constantA.OutputPort);
            GraphModel.CreateEdge(binary1.InputPortA, binary0.OutputPort);

            var constantB = GraphModel.CreateConstantNode("constantB", typeof(float).GenerateTypeHandle(Stencil), Vector2.zero);
            var binary2   = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var binary3   = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

            GraphModel.CreateEdge(binary2.InputPortA, constantB.OutputPort);
            GraphModel.CreateEdge(binary3.InputPortA, binary2.OutputPort);

            var constantC = GraphModel.CreateConstantNode("constantC", typeof(float).GenerateTypeHandle(Stencil), Vector2.zero);
            var binary4   = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            var binary5   = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

            GraphModel.CreateEdge(binary4.InputPortA, constantC.OutputPort);
            GraphModel.CreateEdge(binary5.InputPortA, binary4.OutputPort);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(9));
                Assert.That(GetEdgeCount(), Is.EqualTo(6));
                Assert.That(binary0.InputPortA, Is.ConnectedTo(constantA.OutputPort));
                Assert.That(binary1.InputPortA, Is.ConnectedTo(binary0.OutputPort));
                Assert.That(binary2.InputPortA, Is.ConnectedTo(constantB.OutputPort));
                Assert.That(binary3.InputPortA, Is.ConnectedTo(binary2.OutputPort));
                Assert.That(binary4.InputPortA, Is.ConnectedTo(constantC.OutputPort));
                Assert.That(binary5.InputPortA, Is.ConnectedTo(binary4.OutputPort));
                return(new BypassNodeAction(binary0));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(9));
                Assert.That(GetEdgeCount(), Is.EqualTo(5));
                Assert.That(binary1.InputPortA, Is.ConnectedTo(constantA.OutputPort));
                Assert.That(binary2.InputPortA, Is.ConnectedTo(constantB.OutputPort));
                Assert.That(binary3.InputPortA, Is.ConnectedTo(binary2.OutputPort));
                Assert.That(binary4.InputPortA, Is.ConnectedTo(constantC.OutputPort));
                Assert.That(binary5.InputPortA, Is.ConnectedTo(binary4.OutputPort));
            });

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(9));
                Assert.That(GetEdgeCount(), Is.EqualTo(5));
                Assert.That(binary1.InputPortA, Is.ConnectedTo(constantA.OutputPort));
                Assert.That(binary2.InputPortA, Is.ConnectedTo(constantB.OutputPort));
                Assert.That(binary3.InputPortA, Is.ConnectedTo(binary2.OutputPort));
                Assert.That(binary4.InputPortA, Is.ConnectedTo(constantC.OutputPort));
                Assert.That(binary5.InputPortA, Is.ConnectedTo(binary4.OutputPort));
                return(new BypassNodeAction(binary2, binary4));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(9));
                Assert.That(GetEdgeCount(), Is.EqualTo(3));
                Assert.That(binary1.InputPortA, Is.ConnectedTo(constantA.OutputPort));
                Assert.That(binary3.InputPortA, Is.ConnectedTo(constantB.OutputPort));
                Assert.That(binary5.InputPortA, Is.ConnectedTo(constantC.OutputPort));
            });
        }
Esempio n. 26
0
        void SpawnAllNodeModelsInGraph(VSGraphModel graphModel)
        {
            StackModel    stack;
            FunctionModel funcModel;

            //--Floating Nodes--

            //Stack-Derived NodeModels
            stack     = GraphModel.CreateNode <StackModel>("StackModel");
            funcModel = GraphModel.CreateNode <FunctionModel>("FunctionModel");
            var methodInfo = TypeSystem.GetMethod(typeof(Debug), nameof(Debug.Log), true);

            GraphModel.CreateEventFunction(methodInfo, Vector2.zero);
            GraphModel.CreateNode <OnEndEntitiesNodeModel>("OnEndEntitiesNodeModel");
            GraphModel.CreateNode <OnEventNodeModel>("OnEventNodeModel");
            GraphModel.CreateNode <OnStartEntitiesNodeModel>("OnStartEntitiesNodeModel");
            var onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("OnUpdateEntitiesNodeModel");

            GraphModel.CreateNode <PostUpdate>("PostUpdate");
            GraphModel.CreateNode <PreUpdate>("PreUpdate");
            GraphModel.CreateNode <KeyDownEventModel>("KeyDownEventModel");
            GraphModel.CreateLoopStack(typeof(ForEachHeaderModel), Vector2.zero);
            GraphModel.CreateLoopStack(typeof(WhileHeaderModel), Vector2.zero);
            GraphModel.CreateLoopStack(typeof(ForAllEntitiesStackModel), Vector2.zero);

            //Constant-typed NodeModels
            GraphModel.CreateNode <BooleanConstantNodeModel>("BooleanConstantNodeModel");
            GraphModel.CreateNode <ColorConstantModel>("ColorConstantModel");
            GraphModel.CreateNode <CurveConstantNodeModel>("CurveConstantNodeModel");
            GraphModel.CreateNode <DoubleConstantModel>("DoubleConstantModel");
            GraphModel.CreateNode <EnumConstantNodeModel>("EnumConstantNodeModel");
            GraphModel.CreateNode <FloatConstantModel>("FloatConstantModel");
            GraphModel.CreateNode <GetPropertyGroupNodeModel>("GetPropertyGroupNodeModel");
            GraphModel.CreateNode <InputConstantModel>("InputConstantModel");
            GraphModel.CreateNode <IntConstantModel>("IntConstantModel");
            GraphModel.CreateNode <LayerConstantModel>("LayerConstantModel");
            GraphModel.CreateNode <LayerMaskConstantModel>("LayerMaskConstantModel");
            GraphModel.CreateNode <ObjectConstantModel>("ObjectConstantModel");
            GraphModel.CreateNode <QuaternionConstantModel>("QuaternionConstantModel");
            GraphModel.CreateNode <StringConstantModel>("StringConstantModel");
            GraphModel.CreateNode <TagConstantModel>("TagConstantModel");
            GraphModel.CreateNode <TypeConstantModel>("TypeConstantModel");
            GraphModel.CreateNode <Vector2ConstantModel>("Vector2ConstantModel");
            GraphModel.CreateNode <Vector3ConstantModel>("Vector3ConstantModel");
            GraphModel.CreateNode <Vector4ConstantModel>("Vector4ConstantModel");
            GraphModel.CreateNode <ConstantSceneAssetNodeModel>("ConstantSceneAssetNodeModel");
            GraphModel.CreateNode <Float2ConstantModel>("Float2ConstantModel");
            GraphModel.CreateNode <Float3ConstantModel>("Float3ConstantModel");
            GraphModel.CreateNode <Float4ConstantModel>("Float4ConstantModel");

            //Misc
            void DefineSystemConstant(SystemConstantNodeModel m)
            {
                m.ReturnType    = typeof(float).GenerateTypeHandle(Stencil);
                m.DeclaringType = typeof(Mathf).GenerateTypeHandle(Stencil);
                m.Identifier    = "PI";
            }

            GraphModel.CreateNode <SystemConstantNodeModel>("SystemConstantNodeModel", Vector2.zero, SpawnFlags.Default, DefineSystemConstant);
            GraphModel.CreateNode <GroupNodeModel>("GroupNodeModel");
            GraphModel.CreateNode <GetInputNodeModel>("GetInputNodeModel");
            GraphModel.CreateNode <GetOrCreateComponentNodeModel>("GetOrCreateComponentNodeModel");
            GraphModel.CreateNode <GetSingletonNodeModel>("GetSingletonNodeModel");
            GraphModel.CreateNode <ThisNodeModel>("ThisNodeModel");
            VariableDeclarationModel decl = graphModel.CreateGraphVariableDeclaration("MyVariableName", typeof(int).GenerateTypeHandle(graphModel.Stencil), true);

            GraphModel.CreateVariableNode(decl, Vector2.zero);
            GraphModel.CreateNode <MacroRefNodeModel>("MacroRefNodeModel");
            GraphModel.CreateInlineExpressionNode("2+2", Vector2.zero);
            GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            GraphModel.CreateUnaryOperatorNode(UnaryOperatorKind.PostIncrement, Vector2.zero);

            //--Stack-Contained Nodes--
            stack.CreateStackedNode <AddComponentNodeModel>();
            stack.CreateStackedNode <DestroyEntityNodeModel>();
            stack.CreateStackedNode <ForAllEntitiesNodeModel>();
            stack.CreateStackedNode <ForEachNodeModel>();
            stack.CreateFunctionCallNode(TypeSystem.GetMethod(typeof(Debug), nameof(Debug.Log), true));
            stack.CreateFunctionRefCallNode(funcModel);
            stack.CreateStackedNode <InstantiateNodeModel>();
            stack.CreateStackedNode <IfConditionNodeModel>();
            stack.CreateStackedNode <LogNodeModel>();
            stack.CreateStackedNode <RemoveComponentNodeModel>();
            stack.CreateStackedNode <SetComponentNodeModel>();
            stack.CreateStackedNode <SetPositionNodeModel>();
            stack.CreateStackedNode <SetRotationNodeModel>();
            stack.CreateStackedNode <WhileNodeModel>();
            stack.CreateStackedNode <SetPropertyGroupNodeModel>();
            stack.CreateStackedNode <SetVariableNodeModel>();
            funcModel.CreateStackedNode <ReturnNodeModel>();

            TypeHandle eventTypeHandle = typeof(UnitTestEvent).GenerateTypeHandle(Stencil);

            onUpdateModel.CreateStackedNode <SendEventNodeModel>("SendEventNodeModel", 0, SpawnFlags.Default, n => n.EventType = eventTypeHandle);
        }