void PrepareGraph(VSGraphModel graphModel)
        {
            var entityTypeHandle = typeof(Entity).GenerateTypeHandle(graphModel.Stencil);

            // Component creation
            var scale = typeof(Scale).GenerateTypeHandle(Stencil);
            var group = graphModel.CreateComponentQuery("g");

            group.AddComponent(graphModel.Stencil, scale, ComponentDefinitionFlags.None);


            // On update
            var groupInstance = graphModel.CreateVariableNode(group, Vector2.zero);

            m_OnUpdateEntities = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);
            graphModel.CreateEdge(m_OnUpdateEntities.InstancePort, groupInstance.OutputPort);

            m_CreateEntityModel = m_OnUpdateEntities.CreateStackedNode <CreateEntityNodeModel>("instantiate");

            // Variable containing the new entity
            m_OnUpdateEntities.CreateFunctionVariableDeclaration("newEntity", entityTypeHandle);
            m_NewEntityVariable = graphModel.CreateVariableNode(
                m_OnUpdateEntities.FunctionParameterModels.Single(p => p.DataType == entityTypeHandle),
                Vector2.zero);

            m_FloatConstantNode       = (FloatConstantModel)graphModel.CreateConstantNode("float", TypeHandle.Float, Vector2.zero);
            m_FloatConstantNode.value = 10f;

            graphModel.CreateEdge(m_CreateEntityModel.InstancePort, m_NewEntityVariable.OutputPort);
        }
        static State CreateVariableNodes(State previousState, CreateVariableNodesAction action)
        {
            if (action.VariablesToCreate.Count > 0)
            {
                if (action.ConnectAfterCreation != null)
                {
                    // Delete previous connections
                    if (action.EdgeModelsToDelete.Any())
                    {
                        ((VSGraphModel)previousState.CurrentGraphModel).DeleteEdges(action.EdgeModelsToDelete);
                    }
                }

                foreach (Tuple <IVariableDeclarationModel, Vector2> tuple in action.VariablesToCreate)
                {
                    VSGraphModel vsGraphModel = ((VSGraphModel)previousState.CurrentGraphModel);

                    IVariableModel newVariable = vsGraphModel.CreateVariableNode(tuple.Item1, tuple.Item2);

                    if (action.ConnectAfterCreation != null)
                    {
                        var newEdge = ((VSGraphModel)previousState.CurrentGraphModel).CreateEdge(action.ConnectAfterCreation, newVariable.OutputPort);
                        if (action.AutoAlign)
                        {
                            vsGraphModel.LastChanges.ModelsToAutoAlign.Add(newEdge);
                        }
                    }
                }
            }

            return(previousState);
        }
Beispiel #3
0
        [Test] // TODO: fix jobs
        public void OnExitWorks([Values(CodeGenMode.NoJobs)] CodeGenMode mode)
        {
            SetupTestGraphMultipleFrames(mode, graphModel =>
            {
                var group        = graphModel.CreateComponentQuery("g");
                var positionType = typeof(Translation).GenerateTypeHandle(Stencil);
                group.AddComponent(graphModel.Stencil, positionType, ComponentDefinitionFlags.None);
                group.AddComponent(graphModel.Stencil, typeof(Rotation).GenerateTypeHandle(Stencil), ComponentDefinitionFlags.None);
                var groupInstance = graphModel.CreateVariableNode(group, Vector2.zero);
                var update        = graphModel.CreateNode <OnEndEntitiesNodeModel>("update", Vector2.zero);
                graphModel.CreateEdge(update.InstancePort, groupInstance.OutputPort);

                var log = update.CreateFunctionCallNode(typeof(Debug).GetMethod("Log", new[] { typeof(object) }), 0);
                IVariableModel entityVariable = GraphModel.CreateVariableNode(update.FunctionParameterModels.Single(p => p.DataType == typeof(Entity).GenerateTypeHandle(Stencil)), Vector2.zero);
                GraphModel.CreateEdge(log.GetParameterPorts().First(), entityVariable.OutputPort);
            },
                                         EachEntity((manager, i, e) => manager.AddComponent(e, typeof(Rotation))),
                                         EachEntity((manager, i, e) => manager.AddComponent(e, typeof(Translation))),
                                         EachEntity((manager, i, e) =>
            {
                LogAssert.NoUnexpectedReceived();
                LogAssert.Expect(LogType.Log, $"Entity({i}:1)");
                manager.RemoveComponent <Rotation>(e);
            }),
                                         EachEntity((manager, i, e) => {})
                                         );
        }
        public void OneGroupIterationSystem([Values] CodeGenMode mode)
        {
            SetupTestGraph(mode, g =>
            {
                ComponentQueryDeclarationModel query = GraphModel.CreateComponentQuery("g1");
                TypeHandle positionType = typeof(Translation).GenerateTypeHandle(Stencil);
                query.AddComponent(Stencil, positionType, ComponentDefinitionFlags.None);
                IVariableModel queryInstance = GraphModel.CreateVariableNode(query, Vector2.zero);

                OnUpdateEntitiesNodeModel onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);

                GraphModel.CreateEdge(onUpdateModel.InstancePort, queryInstance.OutputPort);

                SetPropertyGroupNodeModel set = onUpdateModel.CreateStackedNode <SetPropertyGroupNodeModel>("set");
                var member = new TypeMember(TypeHandle.Float, new List <string> {
                    nameof(Translation.Value), nameof(Translation.Value.x)
                });
                set.AddMember(member);

                IVariableModel posComponent = GraphModel.CreateVariableNode(onUpdateModel.FunctionParameterModels.Single(p => p.DataType == positionType), Vector2.zero);
                GraphModel.CreateEdge(set.InstancePort, posComponent.OutputPort);

                ((FloatConstantModel)set.InputConstantsById[member.GetId()]).value = 2f;
            },
                           (manager, entityIndex, e) => manager.AddComponentData(e, new Translation {
                Value = { x = entityIndex }
            }),
                           (manager, entityIndex, e) => Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(2f)));
        }
Beispiel #5
0
        public void SendEventNestedTest([Values] CodeGenMode mode)
        {
            SetupTestGraphMultipleFrames(mode, graphModel =>
            {
                // group1 - Position
                var group1 = graphModel.CreateComponentQuery("g1");
                group1.AddComponent(graphModel.Stencil, typeof(Translation).GenerateTypeHandle(Stencil), ComponentDefinitionFlags.None);
                var group1Instance = graphModel.CreateVariableNode(group1, Vector2.zero);

                // group2 - Scale (will add RenderMesh)
                var group2 = graphModel.CreateComponentQuery("g2");
                group2.AddComponent(graphModel.Stencil, typeof(Scale).GenerateTypeHandle(Stencil), ComponentDefinitionFlags.None);
                var group2Instance = graphModel.CreateVariableNode(group2, Vector2.zero);

                // update group 1
                var onUpdateEntities = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);
                graphModel.CreateEdge(onUpdateEntities.InstancePort, group1Instance.OutputPort);

                // nested update group 2
                var forAllStack = GraphModel.CreateLoopStack <ForAllEntitiesStackModel>(Vector2.zero);
                var forAllNode  = forAllStack.CreateLoopNode(onUpdateEntities, 0) as ForAllEntitiesNodeModel;
                graphModel.CreateEdge(forAllNode.InputPort, group2Instance.OutputPort);
                graphModel.CreateEdge(forAllStack.InputPort, forAllNode.OutputPort);

                TypeHandle eventTypeHandle = typeof(UnitTestEvent).GenerateTypeHandle(Stencil);
                SendEventNodeModel set     = forAllStack.CreateStackedNode <SendEventNodeModel>("set", 0, SpawnFlags.Default, n => n.EventType = eventTypeHandle);

                TypeHandle entityType    = typeof(Entity).GenerateTypeHandle(Stencil);
                IVariableModel entityVar = GraphModel.CreateVariableNode(forAllStack.FunctionParameterModels.Single(p => p.DataType == entityType), Vector2.zero);
                var firstFieldInput      = set.EntityPort;
                GraphModel.CreateEdge(firstFieldInput, entityVar.OutputPort);
            }
                                         );
        }
Beispiel #6
0
        [Test] // TODO: fix jobs
        public void OnEnterWorks([Values(CodeGenMode.NoJobs)] CodeGenMode mode)
        {
            SetupTestGraphMultipleFrames(mode, graphModel =>
            {
                var group        = graphModel.CreateComponentQuery("g");
                var positionType = typeof(Translation).GenerateTypeHandle(Stencil);
                group.AddComponent(graphModel.Stencil, positionType, ComponentDefinitionFlags.None);
                group.AddComponent(graphModel.Stencil, typeof(Rotation).GenerateTypeHandle(Stencil), ComponentDefinitionFlags.None);
                var groupInstance = graphModel.CreateVariableNode(group, Vector2.zero);
                var update        = graphModel.CreateNode <OnStartEntitiesNodeModel>("update", Vector2.zero);
                graphModel.CreateEdge(update.InstancePort, groupInstance.OutputPort);

                var set = update.CreateStackedNode <SetPositionNodeModel>("set", 0, SpawnFlags.Default, n => n.Mode = SetPositionNodeModel.TranslationMode.Float3);
                set.Add = true;     // increment so we can detect multiple runs if they happen
                ((Float3ConstantModel)set.InputConstantsById["Value"]).value = new Vector3(1f, 0.0f, 0.0f);

                IVariableModel posComponent = GraphModel.CreateVariableNode(update.FunctionParameterModels.Single(p => p.DataType == positionType), Vector2.zero);
                GraphModel.CreateEdge(set.InstancePort, posComponent.OutputPort);
            },
                                         EachEntity((manager, i, e) => manager.AddComponent(e, typeof(Rotation))),
                                         EachEntity((manager, i, e) =>
            {
                manager.AddComponent(e, typeof(Translation));     // will make the entity enter the query
                Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(0));
            }),
                                         EachEntity((manager, i, e) => Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(1))), // translate ran once
                                         EachEntity((manager, i, e) => Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(1)))  // not twice
                                         );
        }
Beispiel #7
0
        VisualElement SetupConstantEditor(IVariableModel criterionValue)
        {
            EnableInClassList("constant", true);
            VisualElement propertyField = this.CreateEditorForNodeModel((IConstantNodeModel)criterionValue, _ => Store.Dispatch(new RefreshUIAction(UpdateFlags.RequestCompilation)));

            propertyField.name = "criterionRowValue";
            return(propertyField);
        }
Beispiel #8
0
        public void Test_RemoveSetPropertyMemberKeepsEdges([Values] TestingMode mode)
        {
            // test that removing a SetProperty member doesn't break the edge with it's Instance
            // i.e. here: check that removing Position keeps the link with Transform

            //               |_TestFunction_____|
            // (Transform)---+-o Set Property   |
            //               | o   Position     |

            VariableDeclarationModel trDecl = GraphModel.CreateGraphVariableDeclaration("tr", typeof(Transform).GenerateTypeHandle(Stencil), true);
            IVariableModel           trVar  = GraphModel.CreateVariableNode(trDecl, Vector2.left);

            FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero);

            SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0);

            GraphModel.CreateEdge(setters.InstancePort, trVar.OutputPort);

            PropertyInfo propertyToAdd = typeof(Transform).GetProperty("position");

            var newMember = new TypeMember
            {
                Path = new List <string> {
                    propertyToAdd?.Name
                },
                Type = propertyToAdd.GetUnderlyingType().GenerateTypeHandle(Stencil)
            };

            setters.AddMember(newMember);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                RefreshReference(ref method);
                RefreshReference(ref setters);
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(method.NodeModels.Count(), Is.EqualTo(1));
                Assert.That(setters.InputsByDisplayOrder.Count, Is.EqualTo(2));
                Assert.That(setters.Members.Count, Is.EqualTo(1));
                return(new EditPropertyGroupNodeAction(
                           EditPropertyGroupNodeAction.EditType.Remove, setters, newMember));
            },
                                    () =>
            {
                RefreshReference(ref method);
                RefreshReference(ref setters);
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(method.NodeModels.Count(), Is.EqualTo(1));
                Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>());
                Assert.That(setters.InputsByDisplayOrder.Count, Is.EqualTo(1));
                Assert.That(setters.Members.Count, Is.EqualTo(0));
            });
        }
        public void TestExcludedComponentQuery_RootContext([Values] CodeGenMode mode)
        {
            var defaultValue  = new quaternion(0, 0, 0, 0);
            var modifiedValue = new quaternion(1, 1, 1, 1);

            SetupTestGraph(mode, CreateGraphNodes, AddComponentsToEntities, ValidateSubtractive);

            void CreateGraphNodes(VSGraphModel graphModel)
            {
                var scaleType    = typeof(Scale).GenerateTypeHandle(Stencil);
                var rotationType = typeof(Rotation).GenerateTypeHandle(Stencil);
                var group        = graphModel.CreateComponentQuery("g");

                group.AddComponent(graphModel.Stencil, scaleType, ComponentDefinitionFlags.Subtract);
                group.AddComponent(graphModel.Stencil, rotationType, ComponentDefinitionFlags.None);

                IVariableModel            groupInstance         = graphModel.CreateVariableNode(group, Vector2.zero);
                OnUpdateEntitiesNodeModel onOnEntitiesNodeModel = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("loop", Vector2.zero);

                graphModel.CreateEdge(onOnEntitiesNodeModel.InstancePort, groupInstance.OutputPort);

                SetComponentNodeModel setRotationNode = graphModel.CreateNode <SetComponentNodeModel>("SetComponent", Vector2.zero);

                setRotationNode.ComponentType = typeof(Rotation).GenerateTypeHandle(Stencil);
                onOnEntitiesNodeModel.AddStackedNode(setRotationNode, -1);
                setRotationNode.DefineNode();
                var entityVarDeclaration = onOnEntitiesNodeModel.FunctionParameterModels.Single(p => p.DataType == typeof(Entity).GenerateTypeHandle(graphModel.Stencil));
                var entityInstance       = graphModel.CreateVariableNode(entityVarDeclaration, Vector2.zero);
                var float4ConstantNode   = (Float4ConstantModel)graphModel.CreateConstantNode("float4", typeof(float4).GenerateTypeHandle(graphModel.Stencil), Vector2.zero);

                float4ConstantNode.value = modifiedValue.value;

                graphModel.CreateEdge(setRotationNode.EntityPort, entityInstance.OutputPort);
                graphModel.CreateEdge(setRotationNode.InputsById[nameof(Rotation.Value)], float4ConstantNode.OutputPort);
            }

            void AddComponentsToEntities(EntityManager manager, int entityIndex, Entity e)
            {
                manager.AddComponent(e, typeof(Rotation));
                if (entityIndex % 2 == 1)
                {
                    manager.AddComponent(e, typeof(Scale));
                }
            }

            void ValidateSubtractive(EntityManager manager, int entityIndex, Entity e)
            {
                var expectedValue = manager.HasComponent <Scale>(e) ? defaultValue : modifiedValue;

                Assert.That(manager.GetComponentData <Rotation>(e).Value, Is.EqualTo(expectedValue));
            }
        }
        public void NestedIterationSystem_DifferentGroups_DifferentComponents([Values] CodeGenMode mode)
        {
            SetupTestGraph(mode, g =>
            {
                TypeHandle translationType = typeof(Translation).GenerateTypeHandle(Stencil);
                TypeHandle rotationType    = typeof(Rotation).GenerateTypeHandle(Stencil);

                // query1 - Position
                ComponentQueryDeclarationModel query1 = GraphModel.CreateComponentQuery("g1");
                query1.AddComponent(Stencil, translationType, ComponentDefinitionFlags.None);
                IVariableModel query1Instance = GraphModel.CreateVariableNode(query1, Vector2.zero);

                // query2 - Rotation too
                ComponentQueryDeclarationModel query2 = GraphModel.CreateComponentQuery("g2");
                query2.AddComponent(Stencil, rotationType, ComponentDefinitionFlags.None);
                IVariableModel query2Instance = GraphModel.CreateVariableNode(query2, Vector2.zero);

                // update query 1
                OnUpdateEntitiesNodeModel onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);
                GraphModel.CreateEdge(onUpdateModel.InstancePort, query1Instance.OutputPort);

                // nested update query 2
                var forAllStack = GraphModel.CreateLoopStack <ForAllEntitiesStackModel>(Vector2.zero);
                var forAllNode  = forAllStack.CreateLoopNode(onUpdateModel, 0) as ForAllEntitiesNodeModel;
                Assert.That(forAllNode, Is.Not.Null);
                GraphModel.CreateEdge(forAllNode.InputPort, query2Instance.OutputPort);
                GraphModel.CreateEdge(forAllStack.InputPort, forAllNode.OutputPort);

                // set  query1.translation = ...
                SetPropertyGroupNodeModel set = forAllStack.CreateStackedNode <SetPropertyGroupNodeModel>("set");
                var member = new TypeMember(TypeHandle.Float, new List <string> {
                    nameof(Translation.Value), nameof(Translation.Value.x)
                });
                set.AddMember(member);

                IVariableModel posComponent = GraphModel.CreateVariableNode(onUpdateModel.FunctionParameterModels.Single(p => p.DataType == translationType), Vector2.zero);
                GraphModel.CreateEdge(set.InstancePort, posComponent.OutputPort);

                ((FloatConstantModel)set.InputConstantsById[member.GetId()]).value = 2f;
            },
                           (manager, entityIndex, e) =>
            {
                manager.AddComponentData(e, new Translation {
                    Value = { x = entityIndex }
                });
                manager.AddComponentData(e, new Rotation());
            },
                           (manager, entityIndex, e) => Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(2f)));
        }
Beispiel #11
0
        public void SendEventTest([Values] CodeGenMode mode)
        {
            SetupTestGraphMultipleFrames(mode, g =>
            {
                ComponentQueryDeclarationModel query = GraphModel.CreateComponentQuery("g1");
                TypeHandle positionType = typeof(Translation).GenerateTypeHandle(Stencil);
                query.AddComponent(Stencil, positionType, ComponentDefinitionFlags.None);
                IVariableModel queryInstance = GraphModel.CreateVariableNode(query, Vector2.zero);

                OnUpdateEntitiesNodeModel onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);

                GraphModel.CreateEdge(onUpdateModel.InstancePort, queryInstance.OutputPort);

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

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

                TypeHandle entityType    = typeof(Entity).GenerateTypeHandle(Stencil);
                IVariableModel entityVar = GraphModel.CreateVariableNode(onUpdateModel.FunctionParameterModels.Single(p => p.DataType == entityType), Vector2.zero);

                GraphModel.CreateEdge(set.EntityPort, entityVar.OutputPort);
                var firstFieldInput = set.FieldInputs.First();
                ((FloatConstantModel)set.InputConstantsById[firstFieldInput.UniqueId]).value = 2f;
            },

                                         // Add translation to even entities
                                         EachEntity((manager, i, e) =>
            {
                manager.AddComponent(e, typeof(Translation));
                manager.World.CreateSystem <InitializationSystemGroup>();
            }),
                                         (manager, entities) =>
            {
                EventSystem <UnitTestEvent> eventSystem = manager.World.GetExistingSystem <EventSystem <UnitTestEvent> >();
                Assert.That(eventSystem, Is.Not.Null);
                eventSystem.Update();
            },

                                         // OnUpdate should have added a buffer and one event
                                         EachEntity((manager, i, e) =>
            {
                DynamicBuffer <UnitTestEvent> buffer = default;
                Assert.DoesNotThrow(() => buffer     = manager.GetBuffer <UnitTestEvent>(e));
                Assert.That(buffer.IsCreated, Is.True);
                Assert.That(buffer.Length, Is.EqualTo(1));
                Assert.That(buffer[0].i, Is.EqualTo(2f));
            })
                                         );
        }
Beispiel #12
0
        static State CreateVariableNodes(State previousState, CreateVariableNodesAction action)
        {
            if (action.VariablesToCreate.Count > 0)
            {
                if (action.ConnectAfterCreation != null)
                {
                    // Delete previous connections
                    if (action.EdgeModelsToDelete.Any())
                    {
                        ((VSGraphModel)previousState.CurrentGraphModel).DeleteEdges(action.EdgeModelsToDelete);
                    }
                }

                bool needToGroup = action.GroupModel != null;
                List <INodeModel> nodesToGroup = needToGroup ? new List <INodeModel>(action.VariablesToCreate.Count) : null;

                foreach (Tuple <IVariableDeclarationModel, Vector2> tuple in action.VariablesToCreate)
                {
                    VSGraphModel   vsGraphModel = ((VSGraphModel)previousState.CurrentGraphModel);
                    IVariableModel newVariable  = vsGraphModel.CreateVariableNode(tuple.Item1, tuple.Item2);

                    if (action.ConnectAfterCreation != null)
                    {
                        var newEdge = ((VSGraphModel)previousState.CurrentGraphModel).CreateEdge(action.ConnectAfterCreation, newVariable.OutputPort);
                        if (action.AutoAlign)
                        {
                            vsGraphModel.LastChanges.ModelsToAutoAlign.Add(newEdge);
                        }
                    }

                    if (needToGroup)
                    {
                        nodesToGroup.Add(newVariable);
                    }
                }

                if (needToGroup)
                {
                    GroupNodeModel.Ungroup(nodesToGroup);

                    ((GroupNodeModel)action.GroupModel).AddNodes(nodesToGroup);
                }
            }

            return(previousState);
        }
        static void CreateUpdateAndLogEntity(VSGraphModel graphModel, IVariableModel variable)
        {
            // update entities
            var update = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);

            graphModel.CreateEdge(update.InstancePort, variable.OutputPort);

            // Create entity from update
            var entity = graphModel.CreateVariableNode(
                update.FunctionParameterModels.Single(
                    p => p.DataType == typeof(Entity).GenerateTypeHandle(graphModel.Stencil)),
                Vector2.zero);

            // Log the entity
            var log = update.CreateFunctionCallNode(typeof(Debug).GetMethod("Log", new[] { typeof(object) }), 0);

            graphModel.CreateEdge(log.GetParameterPorts().First(), entity.OutputPort);
        }
Beispiel #14
0
        public void Test_DisconnectSetPropertyKeepsPortType([Values] TestingMode mode)
        {
            VariableDeclarationModel trDecl = GraphModel.CreateGraphVariableDeclaration("tr", typeof(Transform).GenerateTypeHandle(Stencil), true);
            IVariableModel           trVar  = GraphModel.CreateVariableNode(trDecl, Vector2.left);

            FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero);

            SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0);

            GraphModel.CreateEdge(setters.InstancePort, trVar.OutputPort);

            setters.AddMember(
                new TypeMember
            {
                Path = new List <string> {
                    "position"
                },
                Type = Stencil.GenerateTypeHandle(typeof(Vector3))
            }
                );

            IConstantNodeModel constToken = GraphModel.CreateConstantNode("v3", typeof(Vector3).GenerateTypeHandle(Stencil), Vector2.left * 200);
            IEdgeModel         edge       = GraphModel.CreateEdge(setters.GetPortsForMembers().First(), constToken.OutputPort);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(2));
                Assert.That(method.NodeModels.Count(), Is.EqualTo(1));
                Assert.That(setters.GetPortsForMembers().First().DataType.Resolve(Stencil), Is.EqualTo(typeof(Vector3)));
                return(new DeleteElementsAction(edge));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(method.NodeModels.Count(), Is.EqualTo(1));
                Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>());
                Assert.That(setters.GetPortsForMembers().First().DataType.Resolve(Stencil), Is.EqualTo(typeof(Vector3)));
            });
        }
Beispiel #15
0
        public void Test_DisconnectSetPropertyInstanceSetsRightPortType(TestingMode mode, int inputIndex, Type expectedPortType)
        {
            VariableDeclarationModel goDecl = GraphModel.CreateGraphVariableDeclaration("go", typeof(GameObject).GenerateTypeHandle(Stencil), true);
            IVariableModel           goVar  = GraphModel.CreateVariableNode(goDecl, Vector2.left);

            FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero);

            SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0);
            IEdgeModel edge = GraphModel.CreateEdge(setters.InstancePort, goVar.OutputPort);

            PropertyInfo propertyInfo = typeof(Transform).GetProperty("position");

            var newMember = new TypeMember
            {
                Path = new List <string> {
                    propertyInfo?.Name
                },
                Type = typeof(Transform).GenerateTypeHandle(Stencil)
            };

            setters.AddMember(newMember);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(method.NodeModels.Count(), Is.EqualTo(1));
                Assert.That(setters.GetPortsForMembers().First().DataType, Is.EqualTo(typeof(Transform).GenerateTypeHandle(Stencil)));
                return(new DeleteElementsAction(edge));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));
                Assert.That(method.NodeModels.Count(), Is.EqualTo(1));
                Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>());
                Assert.That(setters.InstancePort.DataType, Is.EqualTo(TypeHandle.Unknown));
                Assert.That(setters.GetPortsForMembers().First().DataType, Is.EqualTo(typeof(Transform).GenerateTypeHandle(Stencil)));
            });
        }
        public void OneGroupIterationSystem_LocalVariable([Values] CodeGenMode mode)
        {
            SetupTestGraph(mode, g =>
            {
                ComponentQueryDeclarationModel query = GraphModel.CreateComponentQuery("g1");
                TypeHandle translationType           = typeof(Translation).GenerateTypeHandle(Stencil);
                query.AddComponent(Stencil, translationType, ComponentDefinitionFlags.None);
                IVariableModel queryInstance = GraphModel.CreateVariableNode(query, Vector2.zero);

                OnUpdateEntitiesNodeModel onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);
                GraphModel.CreateEdge(onUpdateModel.InstancePort, queryInstance.OutputPort);

                var localDeclaration = onUpdateModel.CreateFunctionVariableDeclaration("local", TypeHandle.Float);
                var local            = GraphModel.CreateVariableNode(localDeclaration, Vector2.zero);

                var log = onUpdateModel.CreateFunctionCallNode(typeof(Debug).GetMethod("Log", new[] { typeof(object) }), 0);

                GraphModel.CreateEdge(log.GetParameterPorts().First(), local.OutputPort);
            },
                           (manager, entityIndex, e) => {},
                           (manager, entityIndex, e) => Assert.Pass());
        }
Beispiel #17
0
        [Test] // TODO: fix jobs
        public void OnEnterAndExitWorks([Values(CodeGenMode.NoJobs)] CodeGenMode mode)
        {
            SetupTestGraphMultipleFrames(mode, graphModel =>
            {
                var query        = graphModel.CreateComponentQuery("g");
                var positionType = typeof(Translation).GenerateTypeHandle(Stencil);
                query.AddComponent(graphModel.Stencil, positionType, ComponentDefinitionFlags.None);
                query.AddComponent(graphModel.Stencil, typeof(Rotation).GenerateTypeHandle(Stencil), ComponentDefinitionFlags.None);
                var queryInstance = graphModel.CreateVariableNode(query, Vector2.zero);
                var update        = graphModel.CreateNode <OnStartEntitiesNodeModel>("update", Vector2.zero);
                graphModel.CreateEdge(update.InstancePort, queryInstance.OutputPort);

                var set = update.CreateStackedNode <SetPositionNodeModel>("set", 0, SpawnFlags.Default, n => n.Mode = SetPositionNodeModel.TranslationMode.Float3);
                set.Add = true;     // increment so we can detect multiple runs if they happen
                ((Float3ConstantModel)set.InputConstantsById["Value"]).value = new Vector3(1f, 0.0f, 0.0f);

                IVariableModel posComponent = GraphModel.CreateVariableNode(update.FunctionParameterModels.Single(p => p.DataType == positionType), Vector2.zero);
                GraphModel.CreateEdge(set.InstancePort, posComponent.OutputPort);

                var log = update.CreateFunctionCallNode(typeof(Debug).GetMethod("Log", new[] { typeof(object) }), 0);
                IVariableModel entityVariable = GraphModel.CreateVariableNode(update.FunctionParameterModels.Single(p => p.DataType == typeof(Entity).GenerateTypeHandle(Stencil)), Vector2.zero);
                GraphModel.CreateEdge(log.GetParameterPorts().First(), entityVariable.OutputPort);
            },
                                         EachEntity((manager, i, e) => manager.AddComponent(e, typeof(Rotation))),
                                         EachEntity((manager, i, e) =>
            {
                manager.AddComponent(e, typeof(Translation));     // will make the entity enter the query
                Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(0));
            }),
                                         EachEntity((manager, i, e) => Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(1))), // translate ran once
                                         EachEntity((manager, i, e) => Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(1))), // not twice
                                         EachEntity((manager, i, e) =>
            {
                LogAssert.Expect(LogType.Log, $"Entity({i}:1)");
                manager.RemoveComponent <Rotation>(e);
            }),
                                         EachEntity((manager, i, e) => {})
                                         );
        }
        // 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);
        }
        public void OneGroupIterationSystem_ReadOnly([Values] CodeGenMode mode)
        {
            SetupTestGraph(mode, g =>
            {
                ComponentQueryDeclarationModel query = GraphModel.CreateComponentQuery("g1");
                TypeHandle translationType           = typeof(Translation).GenerateTypeHandle(Stencil);
                TypeHandle rotationType = typeof(Rotation).GenerateTypeHandle(Stencil);
                query.AddComponent(Stencil, translationType, ComponentDefinitionFlags.None);
                query.AddComponent(Stencil, rotationType, ComponentDefinitionFlags.None);
                IVariableModel queryInstance = GraphModel.CreateVariableNode(query, Vector2.zero);

                OnUpdateEntitiesNodeModel onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);

                GraphModel.CreateEdge(onUpdateModel.InstancePort, queryInstance.OutputPort);

                var log = onUpdateModel.CreateFunctionCallNode(typeof(Debug).GetMethod("Log", new[] { typeof(object) }), 0);

                IVariableModel posComponent = GraphModel.CreateVariableNode(onUpdateModel.FunctionParameterModels.Single(p => p.DataType == translationType), Vector2.zero);
                GraphModel.CreateEdge(log.GetParameterPorts().First(), posComponent.OutputPort);
            },
                           (manager, entityIndex, e) => manager.AddComponents(e,
                                                                              new ComponentTypes(ComponentType.ReadWrite <Translation>(), ComponentType.ReadWrite <Rotation>())),
                           (manager, entityIndex, e) => Assert.Pass());
        }
        public void NestedIterationSystem_DifferentGroups_NestedLocalVariable([Values] CodeGenMode mode)
        {
            SetupTestGraphMultipleFrames(mode, g =>
            {
                TypeHandle translationType = typeof(Translation).GenerateTypeHandle(Stencil);
                TypeHandle rotationType    = typeof(Rotation).GenerateTypeHandle(Stencil);

                // query1 - Position
                ComponentQueryDeclarationModel query1 = GraphModel.CreateComponentQuery("g1");
                query1.AddComponent(Stencil, translationType, ComponentDefinitionFlags.None);
                IVariableModel query1Instance = GraphModel.CreateVariableNode(query1, Vector2.zero);

                // query2 - Rotation too
                ComponentQueryDeclarationModel query2 = GraphModel.CreateComponentQuery("g2");
                query2.AddComponent(Stencil, rotationType, ComponentDefinitionFlags.None);
                IVariableModel query2Instance = GraphModel.CreateVariableNode(query2, Vector2.zero);

                // update query 1
                OnUpdateEntitiesNodeModel onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);
                GraphModel.CreateEdge(onUpdateModel.InstancePort, query1Instance.OutputPort);

                // nested update query 2
                var forAllStack = GraphModel.CreateLoopStack <ForAllEntitiesStackModel>(Vector2.zero);
                var forAllNode  = forAllStack.CreateLoopNode(onUpdateModel, 0) as ForAllEntitiesNodeModel;
                Assert.That(forAllNode, Is.Not.Null);
                GraphModel.CreateEdge(forAllNode.InputPort, query2Instance.OutputPort);
                GraphModel.CreateEdge(forAllStack.InputPort, forAllNode.OutputPort);

                var decl = forAllStack.CreateFunctionVariableDeclaration("x", TypeHandle.Int);
                // set  query1.translation = ...
                SetVariableNodeModel set = forAllStack.CreateStackedNode <SetVariableNodeModel>("set");

                IVariableModel posComponent = GraphModel.CreateVariableNode(decl, Vector2.zero);
                GraphModel.CreateEdge(set.InstancePort, posComponent.OutputPort);
            });
        }
Beispiel #21
0
 public void AddVariable(IVariableModel variable)
 {
     TfVariables.Add(variable);
 }
        static bool HandleVariable(GraphBuilder builder, out INode node,
                                   out PortMapper portToOffsetMapping, out uint?preAllocatedDataIndex, IVariableModel variableModel)
        {
            if (variableModel.DeclarationModel.IsInputOrOutputTrigger())
            {
                preAllocatedDataIndex = null;
                portToOffsetMapping   = new PortMapper();
                if (variableModel.DeclarationModel.Modifiers == ModifierFlags.ReadOnly) // Input
                {
                    var trigger = builder.DeclareInputTrigger(variableModel.DeclarationModel.VariableName);
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort, ref trigger.Output.Port, trigger);
                }
                else
                {
                    var trigger = builder.DeclareOutputTrigger(variableModel.DeclarationModel.VariableName);
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort, ref trigger.Input.Port, trigger);
                }
                return(true);
            }

            var valueType = variableModel.DeclarationModel.DataType.ToValueType();
            var type      = GraphBuilder.GetVariableType(variableModel.DeclarationModel);

            switch (type)
            {
            case GraphBuilder.VariableType.ObjectReference:
                switch (valueType)
                {
                case ValueType.Entity:
                    preAllocatedDataIndex = builder.GetVariableDataIndex(variableModel.DeclarationModel).DataIndex;
                    portToOffsetMapping   = new PortMapper();
                    var cf = new ConstantEntity();
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort, ref cf.ValuePort.Port, cf);
                    return(true);
                }
                break;

            case GraphBuilder.VariableType.Variable:     // Data
                throw new NotImplementedException();

            case GraphBuilder.VariableType.InputOutput:
                // Just create an edge later
                node = default;
                portToOffsetMapping   = null;
                preAllocatedDataIndex = null;
                return(false);

            default:
                throw new ArgumentOutOfRangeException("Variable type not supported: " + type);
            }

            throw new ArgumentOutOfRangeException(valueType.ToString());
        }
        public static IEnumerable <SyntaxNode> BuildVariable(this RoslynTranslator translator, IVariableModel v, IPortModel portModel)
        {
            if (v is IConstantNodeModel constantNodeModel)
            {
                if (constantNodeModel.ObjectValue != null)
                {
                    if (constantNodeModel is IStringWrapperConstantModel)
                    {
                        yield return(translator.Constant(constantNodeModel.ObjectValue.ToString(), translator.Stencil));
                    }
                    else
                    {
                        yield return(translator.Constant(constantNodeModel.ObjectValue, translator.Stencil));
                    }
                }

                yield break;
            }

            if (translator.InMacro.Count > 0 && v.DeclarationModel.VariableType == VariableType.GraphVariable && v.DeclarationModel.Modifiers == ModifierFlags.ReadOnly)
            {
                MacroRefNodeModel oldValue = translator.InMacro.Pop();

                var syntaxNodes = translator.BuildPort(oldValue.InputsById[v.DeclarationModel.VariableName]);
                translator.InMacro.Push(oldValue);
                foreach (var syntaxNode in syntaxNodes)
                {
                    yield return(syntaxNode);
                }
                yield break;
            }

            switch (v.DeclarationModel.VariableType)
            {
            case VariableType.FunctionVariable:
            case VariableType.GraphVariable:
            case VariableType.ComponentQueryField:
                yield return(RoslynBuilder.LocalVariableReference(v.DeclarationModel.Name));

                break;

            case VariableType.FunctionParameter:
                yield return(RoslynBuilder.ArgumentReference(v.DeclarationModel.Name));

                break;

//                case VariableType.Literal:
//                case VariableType.InlineExpression:
            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public static GraphElement CreateToken(this INodeBuilder builder, Store store, IVariableModel model)
        {
            var       isExposed = model.DeclarationModel?.IsExposed;
            Texture2D icon      = (isExposed != null && isExposed.Value)
                ? VisualScriptingIconUtility.LoadIconRequired("GraphView/Nodes/BlackboardFieldExposed.png")
                : null;

            GetTokenPorts(store, model, out var input, out var output, Orientation.Horizontal);

            var token = new Token(model, store, input, output, builder.GraphView, icon);

            if (model.DeclarationModel != null && model.DeclarationModel is LoopVariableDeclarationModel loopVariableDeclarationModel)
            {
                VseUtility.AddTokenIcon(token, loopVariableDeclarationModel.TitleComponentIcon);
            }
            return(token);
        }
        static bool HandleVariable(GraphBuilder builder, out INode node,
                                   out Dictionary <string, uint> portToOffsetMapping, out uint?preAllocatedDataIndex, IVariableModel variableModel)
        {
            if (variableModel.DeclarationModel.IsInputOrOutputTrigger())
            {
                preAllocatedDataIndex = null;
                portToOffsetMapping   = new Dictionary <string, uint>();
                if (variableModel.DeclarationModel.Modifiers == ModifierFlags.ReadOnly) // Input
                {
                    var trigger = builder.DeclareInputTrigger(variableModel.DeclarationModel.VariableName);
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort.UniqueId, ref trigger.Output.Port, trigger);
                }
                else
                {
                    var trigger = builder.DeclareOutputTrigger(variableModel.DeclarationModel.VariableName);
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort.UniqueId, ref trigger.Input.Port, trigger);
                }
                return(true);
            }

            var valueType = variableModel.DeclarationModel.DataType.TypeHandleToValueType();

            Assert.AreEqual(VariableType.GraphVariable, variableModel.DeclarationModel.VariableType);
            var type = GraphBuilder.GetVariableType(variableModel.DeclarationModel);

            switch (type)
            {
            case GraphBuilder.VariableType.ObjectReference:
                switch (valueType)
                {
                case ValueType.Entity:
                    preAllocatedDataIndex = builder.GetVariableDataIndex(variableModel.DeclarationModel).DataIndex;
                    portToOffsetMapping   = new Dictionary <string, uint>();
                    var cf = new ConstantEntity();
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort.UniqueId, ref cf.ValuePort.Port, cf);
                    return(true);
                }
                break;

            case GraphBuilder.VariableType.Variable:     // Data
                // Just create an edge later
                node = default;
                portToOffsetMapping   = null;
                preAllocatedDataIndex = null;
                return(false);

            case GraphBuilder.VariableType.InputOutput:
                Assert.IsFalse(variableModel.DeclarationModel.IsDataOutput());     // TODO check legit
                portToOffsetMapping   = new Dictionary <string, uint>();
                preAllocatedDataIndex = null;
                var inputData = builder.DeclareInputData(variableModel.DeclarationModel.VariableName, variableModel.DeclarationModel.DataType.TypeHandleToValueType());
                node = MapPort(portToOffsetMapping, variableModel.OutputPort.UniqueId, ref inputData.Output.Port, inputData);
                return(true);

            default:
                throw new ArgumentOutOfRangeException("Variable type not supported: " + type);
            }

            throw new ArgumentOutOfRangeException(valueType.ToString());
        }
Beispiel #26
0
        public void OnEventTest([Values] CodeGenMode mode)
        {
            SetupTestGraphMultipleFrames(mode, g =>
            {
                ComponentQueryDeclarationModel query = GraphModel.CreateComponentQuery("g1");
                TypeHandle positionType = typeof(Translation).GenerateTypeHandle(Stencil);
                query.AddComponent(Stencil, positionType, ComponentDefinitionFlags.None);
                IVariableModel queryInstance = GraphModel.CreateVariableNode(query, Vector2.zero);

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

                OnEventNodeModel onUpdateModel = GraphModel.CreateNode <OnEventNodeModel>("update", Vector2.zero, SpawnFlags.Default, n => n.EventTypeHandle = eventTypeHandle);

                GraphModel.CreateEdge(onUpdateModel.InstancePort, queryInstance.OutputPort);

                SetPropertyGroupNodeModel set = onUpdateModel.CreateStackedNode <SetPropertyGroupNodeModel>("set", 0);
                var member = new TypeMember(TypeHandle.Float, new List <string> {
                    nameof(Translation.Value), nameof(Translation.Value.x)
                });
                set.AddMember(member);

                IVariableModel posComponent = GraphModel.CreateVariableNode(onUpdateModel.FunctionParameterModels.Single(p => p.DataType == positionType), Vector2.zero);
                GraphModel.CreateEdge(set.InstancePort, posComponent.OutputPort);

                ((FloatConstantModel)set.InputConstantsById[member.GetId()]).value = 2f;
            },

                                         // Add translation to even entities
                                         EachEntity((manager, i, e) =>
            {
                if (e.Index % 2 == 0)
                {
                    manager.AddComponent(e, typeof(Translation));
                }
            }),

                                         // Send event on these
                                         EachEntity(del: (manager, i, e) =>
            {
                if (e.Index % 2 == 0)
                {
                    Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(0f));
                }
                else
                {
                    Assert.IsFalse(manager.HasComponent <Translation>(e));
                }

                // Add event on all entities
                manager.AddBuffer <UnitTestEvent>(e).Add(new UnitTestEvent());
            }),

                                         // Event handler should set t.x to 2
                                         EachEntity((manager, i, e) =>
            {
                if (e.Index % 2 == 0)
                {
                    Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(2f));
                }
            }),

                                         // Reset translation
                                         EachEntity((manager, i, e) =>
            {
                if (e.Index % 2 == 0)
                {
                    var t     = manager.GetComponentData <Translation>(e);
                    t.Value.x = 0;
                    manager.SetComponentData(e, t);
                }
            }),

                                         // As we send events manually, the event system is not running and won't cleanup events.
                                         // Event handler should set t.x to 2 again
                                         EachEntity((manager, i, e) =>
            {
                if (e.Index % 2 == 0)
                {
                    Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(2f));
                }
            })
                                         );
        }
Beispiel #27
0
        public static IGraphElement CreateToken(this ElementBuilder elementBuilder, IStore store, IVariableModel model)
        {
            var       isExposed = model.DeclarationModel?.IsExposed;
            Texture2D icon      = (isExposed != null && isExposed.Value)
                ? GraphViewStaticBridge.LoadIconRequired("GraphView/Nodes/BlackboardFieldExposed.png")
                : null;

            var ui = new Token();

            ui.Setup(model, store, elementBuilder.GraphView, icon);
            return(ui);
        }
Beispiel #28
0
        public static IEnumerable <SyntaxNode> BuildVariable(this RoslynEcsTranslator translator, IVariableModel v, IPortModel portModel)
        {
            if (v is IConstantNodeModel model)
            {
                if (model.ObjectValue != null)
                {
                    yield return(translator.Constant(model.ObjectValue, translator.Stencil, model.Type));
                }

                yield break;
            }

            if (translator.InMacro.Count > 0 && v.DeclarationModel.VariableType == VariableType.GraphVariable && v.DeclarationModel.Modifiers == ModifierFlags.ReadOnly)
            {
                MacroRefNodeModel oldValue = translator.InMacro.Pop();

                var syntaxNodes = translator.BuildPort(oldValue.InputsById[v.DeclarationModel.VariableName]);
                translator.InMacro.Push(oldValue);
                foreach (var syntaxNode in syntaxNodes)
                {
                    yield return(syntaxNode);
                }
                yield break;
            }

            switch (v.DeclarationModel.VariableType)
            {
            case VariableType.GraphVariable:
                yield return(translator.context.GetSingletonVariable(v.DeclarationModel));

                break;

            case VariableType.FunctionVariable:
            case VariableType.ComponentGroupField:
                yield return(RoslynBuilder.LocalVariableReference(v.DeclarationModel.VariableName));

                break;

            case VariableType.FunctionParameter:
                var variableDeclarationModel = v.DeclarationModel;
                if (variableDeclarationModel.VariableIsAGeneratedEcsComponent(out var groupDeclaration))
                {
                    var relevantContext = translator.FindContext(groupDeclaration);
                    translator.context.RecordComponentAccess(relevantContext, v.DeclarationModel.DataType, translator.IsRecordingComponentAccesses);
                    yield return(RoslynBuilder.ArgumentReference(translator.context.GetComponentVariableName(groupDeclaration, variableDeclarationModel.DataType)));
                }
                else
                {
                    yield return(RoslynBuilder.ArgumentReference(v.DeclarationModel.VariableName));
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #29
0
        public static IEnumerable <SyntaxNode> BuildVariable(this RoslynTranslator translator, IVariableModel v, IPortModel portModel)
        {
            if (v is IConstantNodeModel constantNodeModel)
            {
                if (constantNodeModel.ObjectValue != null)
                {
                    if (constantNodeModel is IStringWrapperConstantModel)
                    {
                        yield return(translator.Constant(constantNodeModel.ObjectValue.ToString(), translator.Stencil));
                    }
                    else
                    {
                        yield return(translator.Constant(constantNodeModel.ObjectValue, translator.Stencil));
                    }
                }

                yield break;
            }

            switch (v.DeclarationModel.VariableType)
            {
            case VariableType.GraphVariable:
            case VariableType.ComponentQueryField:
                yield return(RoslynBuilder.LocalVariableReference(v.DeclarationModel.Name));

                break;

            //                case VariableType.Literal:
            //                case VariableType.InlineExpression:
            default:
                throw new ArgumentOutOfRangeException();
            }
        }