Fix systems not implying [DependsOn<OnUpdate>]

wip/source-generators
copygirl 12 months ago
parent d51c0331bb
commit 58989e949f
  1. 6
      src/gaemstone.SourceGen/ModuleGenerator.cs
  2. 4
      src/gaemstone.SourceGen/Structure/BaseEntityInfo.cs
  3. 8
      src/gaemstone.SourceGen/Structure/MethodEntityInfo.cs

@ -242,7 +242,7 @@ public class ModuleGenerator
sb.Append(p.Kind switch {
ParameterKind.Has => ".None",
ParameterKind.Not => ".None.Not",
ParameterKind.Not => ".Not",
ParameterKind.Ref => ".InOut",
ParameterKind.Out => ".Out",
_ when !p.IsValueType => ".InOut", // Reference types always imply writability.
@ -289,6 +289,10 @@ public class ModuleGenerator
sb.AppendLine($"\t\t{@var}.Add<{a.GetFullName()}>();");
foreach (var (r, t) in e.RelationsToAdd)
sb.AppendLine($"\t\t{@var}.Add<{r.GetFullName()}, {t.GetFullName()}>();");
// If system doesn't have an explicit phase set, default to OnUpdate.
if (e is MethodEntityInfo { IsSystem: true, HasPhaseSet: false })
sb.AppendLine($"\t\t{@var}.Add<gaemstone.Flecs.Core.DependsOn, gaemstone.Flecs.Pipeline.OnUpdate>();");
}
}

@ -13,8 +13,8 @@ public abstract class BaseEntityInfo : BaseInfo
public string? EntitySymbol { get; }
public List<INamedTypeSymbol> EntitiesToAdd { get; } = new();
public List<(INamedTypeSymbol, INamedTypeSymbol)> RelationsToAdd { get; } = new();
public bool HasEntitiesToAdd => (EntitiesToAdd.Count > 0) || (RelationsToAdd.Count > 0);
public List<(INamedTypeSymbol Relation, INamedTypeSymbol Target)> RelationsToAdd { get; } = new();
public virtual bool HasEntitiesToAdd => (EntitiesToAdd.Count > 0) || (RelationsToAdd.Count > 0);
public BaseEntityInfo(ISymbol symbol)
: base(symbol)

@ -22,6 +22,9 @@ public class MethodEntityInfo : BaseEntityInfo
public bool IsStatic => Symbol.IsStatic;
public bool IsGeneric => Symbol.IsGenericMethod;
public bool HasPhaseSet { get; private set; }
public override bool HasEntitiesToAdd => base.HasEntitiesToAdd || !HasPhaseSet;
public MethodEntityInfo(ISymbol symbol)
: base(symbol)
{
@ -79,6 +82,11 @@ public class MethodEntityInfo : BaseEntityInfo
if (param.HasTerm)
param.TermIndex = termIndex++;
// See if we have any [DependsOn<...>] attributes for this system.
// If not, ModuleGenerator will add [DependsOn<Flecs.Pipeline.OnUpdate>].
HasPhaseSet = IsSystem && RelationsToAdd.Any(entry => entry.Relation
.GetFullName(FullNameStyle.NoGeneric) == "gaemstone.ECS.DependsOnAttribute");
// TODO: Handle systems with [Source].
// TODO: Validate ObserverEvents.
}

Loading…
Cancel
Save