public static IEnumerable <SyntaxNode> BuildSetVariable(this RoslynTranslator translator, SetVariableNodeModel statement, IPortModel portModel) { var decl = translator.BuildPort(statement.InstancePort).SingleOrDefault(); var value = translator.BuildPort(statement.ValuePort).SingleOrDefault(); yield return(decl == null || value == null ? null : RoslynBuilder.Assignment(decl, value)); }
protected override StatementSyntax OnPopContext() { var coroutineParameterName = RoslynEcsBuilder.BuildCoroutineParameterName(m_ComponentTypeName); // Build Coroutine MoveNext call statement var block = Block(); // Assign times fields block = block.AddStatements(ExpressionStatement(RoslynBuilder.Assignment( RoslynBuilder.MemberReference( IdentifierName(coroutineParameterName), nameof(ICoroutine.DeltaTime)), Parent.GetOrDeclareDeltaTime()))); // Call MoveNext block = block.AddStatements(IfStatement( RoslynBuilder.MethodInvocation( k_MoveNext, IdentifierName(coroutineParameterName), m_Parameters.Keys, Enumerable.Empty <TypeSyntax>()), ReturnStatement())); // Remove component when coroutine is completed var removeStatement = Parent.GetEntityManipulationTranslator().RemoveComponent( Parent, IdentifierName(Parent.EntityName), m_ComponentTypeName); block = removeStatement.Aggregate(block, (current, syntax) => current.AddStatements(syntax)); return(block); }
protected override IEnumerable <StatementSyntax> OnPopContext() { var thenStatement = ExpressionStatement(RoslynBuilder.Assignment( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, GetNestedCoroutineField(), IdentifierName(k_CoroutineStateVariableName)), PrefixUnaryExpression( SyntaxKind.UnaryMinusExpression, LiteralExpression( SyntaxKind.NumericLiteralExpression, Literal(1))))); var ifStatement = IfStatement( PrefixUnaryExpression( SyntaxKind.LogicalNotExpression, RoslynBuilder.MethodInvocation( UpdateMethodName, IdentifierName(GetSystemClassName()), m_Parameters.Keys, Enumerable.Empty <TypeSyntax>())), thenStatement); yield return(ifStatement); }
public static IEnumerable <SyntaxNode> BuildSetVariable(this RoslynEcsTranslator translator, SetVariableNodeModel statement, IPortModel portModel) { if (statement.InstancePort.ConnectionPortModels.First().NodeModel is VariableNodeModel variableNode && variableNode.ReferencedObject is IVariableDeclarationModel && variableNode.DeclarationModel.VariableType == VariableType.GraphVariable) { translator.context.RequestSingletonUpdate(); } var decl = translator.BuildPort(statement.InstancePort).SingleOrDefault(); var value = translator.BuildPort(statement.ValuePort).SingleOrDefault(); yield return(decl == null || value == null ? null : RoslynBuilder.Assignment(decl, value)); }
public ClassDeclarationSyntax Build(RoslynTranslator translator, VSGraphModel graphModel) { var baseClass = m_NeedToCompleteDependenciesFirst ? nameof(ComponentSystem) : nameof(JobComponentSystem); m_ClassDeclaration = m_ClassDeclaration.WithBaseList( BaseList( SingletonSeparatedList <BaseTypeSyntax>( SimpleBaseType( IdentifierName(baseClass))))); foreach (var queryTracking in m_QueryHasStateTracking) { var trackingMembers = new List <MemberDeclarationSyntax>(); if (queryTracking.Value.Tracking) { trackingMembers.Add( FieldDeclaration( VariableDeclaration( PredefinedType( Token(SyntaxKind.BoolKeyword))) .WithVariables( SingletonSeparatedList( VariableDeclarator( Identifier("Processed"))))) .WithModifiers( TokenList( Token(SyntaxKind.InternalKeyword)))); } DeclareComponent <ISystemStateComponentData>(queryTracking.Value.ComponentName, trackingMembers); } foreach (var eventSystem in m_EventSystems) { // ClearEvents<TestEvent2>.Initialize(World); InitializationStatements.Add(ExpressionStatement(InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, GenericName( Identifier("EventSystem")) .WithTypeArgumentList( TypeArgumentList( SingletonSeparatedList <TypeSyntax>( IdentifierName(eventSystem.FullName)))), IdentifierName("Initialize"))) .WithArgumentList( ArgumentList( SingletonSeparatedList( Argument( IdentifierName("World"))))))); } if ((TranslationOptions & RoslynEcsTranslator.TranslationOptions.Tracing) != 0) { DeclareAndInitField(typeof(TracingRecorderSystem), nameof(TracingRecorderSystem), initValue: InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName("World"), GenericName( Identifier(nameof(World.GetExistingSystem))) .WithTypeArgumentList( TypeArgumentList( SingletonSeparatedList <TypeSyntax>( IdentifierName(nameof(TracingRecorderSystem)))))))); } HashSet <string> declaredQueries = new HashSet <string>(); foreach (var group in m_WrittenComponentsPerGroup) { declaredQueries.Add(group.Key.Query.ComponentQueryDeclarationModel.GetId()); DeclareEntityQueries(group.Value); } // declare unused queries in case there's a Count Entities In Query node somewhere foreach (var graphVariable in graphModel.GraphVariableModels.OfType <ComponentQueryDeclarationModel>().Where(q => !declaredQueries.Contains(q.GetId()))) { var args = graphVariable.Components.Select(c => SyntaxFactory.Argument( InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName("ComponentType"), GenericName( Identifier("ReadOnly")) .WithTypeArgumentList( TypeArgumentList( SingletonSeparatedList <TypeSyntax>( IdentifierName(c.Component.TypeHandle.Resolve(graphModel.Stencil) .FullName)))))) )); var initValue = MakeInitQueryExpression(args); DeclareAndInitField(typeof(EntityQuery), graphVariable.VariableName, initValue: initValue); } var singletonMembers = new List <FieldDeclarationSyntax>(); var initArguments = new List <AssignmentExpressionSyntax>(); foreach (var graphVariable in graphModel.GraphVariableModels .Where(g => g.VariableType == VariableType.GraphVariable)) { singletonMembers.Add(graphVariable.DeclareField(translator, false) .WithAdditionalAnnotations(new SyntaxAnnotation(Annotations.VariableAnnotationKind))); initArguments.Add(RoslynBuilder.Assignment( IdentifierName(graphVariable.VariableName), translator.Constant(graphVariable.InitializationModel.ObjectValue, m_Stencil))); } if (singletonMembers.Any()) { DeclareComponent <IComponentData>(SingletonComponentTypeName, singletonMembers); InitializationStatements.Add(ExpressionStatement( RoslynBuilder.MethodInvocation( nameof(EntityManager.CreateEntity), IdentifierName(nameof(EntityManager)), new[] { Argument(TypeOfExpression(IdentifierName(SingletonComponentTypeName))) }, Enumerable.Empty <TypeSyntax>()))); InitializationStatements.Add( ExpressionStatement( RoslynBuilder.MethodInvocation( SafeGuardNamingSystem.SetSingletonName, null, new[] { Argument(RoslynBuilder.DeclareNewObject( IdentifierName(SingletonComponentTypeName), Enumerable.Empty <ArgumentSyntax>(), initArguments)) }, Enumerable.Empty <TypeSyntax>()))); } // TODO : Remove this once there is real Systems' dependency tool var attributes = new List <AttributeListSyntax>(); foreach (var assetModel in m_Stencil.UpdateAfter.Where(a => a.GraphModel.Stencil is EcsStencil)) { RegisterAttributes <UpdateAfterAttribute>(attributes, assetModel.Name); } foreach (var assetModel in m_Stencil.UpdateBefore.Where(a => a.GraphModel.Stencil is EcsStencil)) { RegisterAttributes <UpdateBeforeAttribute>(attributes, assetModel.Name); } m_ClassDeclaration = m_ClassDeclaration .AddAttributeLists(attributes.ToArray()) .AddMembers(m_ClassMembers.OrderBy(x => x is FieldDeclarationSyntax ? 0 : 1).ToArray()); if (m_InitializationStatements != null) { var onCreateManagerOverride = RoslynBuilder.DeclareMethod( SafeGuardNamingSystem.OnCreateManagerName, AccessibilityFlags.Protected | AccessibilityFlags.Override, typeof(void)); m_ClassDeclaration = m_ClassDeclaration .AddMembers( onCreateManagerOverride.WithBody( Block(m_InitializationStatements))); } if (m_SingletonUpdateSyntax != null) { AddStatement(m_SingletonUpdateSyntax); } var onUpdateBlock = Block(m_UpdateStatements); return(m_ClassDeclaration.AddMembers( RoslynEcsTranslator.MakeOnUpdateOverride( onUpdateBlock, m_NeedToCompleteDependenciesFirst, m_CreatedManagers))); }