Skip to content

Commit db51cb9

Browse files
committed
Completes additional generic overloads feature mentioned in #20
1 parent cbdbce6 commit db51cb9

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Arch.SourceGenerator/Fundamentals/StructuralChangesExtensions.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,56 @@ public static StringBuilder AppendWorldRemove(this StringBuilder sb, int amount)
9090
9191
Move(in entity, oldArchetype, newArchetype);
9292
}}
93+
";
94+
95+
return sb.AppendLine(template);
96+
}
97+
98+
public static StringBuilder AppendEntityAdds(this StringBuilder sb, int amount)
99+
{
100+
for (var index = 1; index < amount; index++)
101+
sb.AppendEntityAdd(index);
102+
103+
return sb;
104+
}
105+
106+
public static StringBuilder AppendEntityAdd(this StringBuilder sb, int amount)
107+
{
108+
109+
var generics = new StringBuilder().GenericWithoutBrackets(amount);
110+
var parameters = new StringBuilder().GenericInDefaultParams(amount);
111+
112+
var template = $@"
113+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
114+
public static void Add<{generics}>(this in Entity entity, {parameters})
115+
{{
116+
var world = World.Worlds[entity.WorldId];
117+
world.Add<{generics}>(in entity);
118+
}}
119+
";
120+
121+
return sb.AppendLine(template);
122+
}
123+
124+
public static StringBuilder AppendEntityRemoves(this StringBuilder sb, int amount)
125+
{
126+
for (var index = 1; index < amount; index++)
127+
sb.AppendEntityRemove(index);
128+
129+
return sb;
130+
}
131+
132+
public static StringBuilder AppendEntityRemove(this StringBuilder sb, int amount)
133+
{
134+
135+
var generics = new StringBuilder().GenericWithoutBrackets(amount);
136+
var template = $@"
137+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
138+
public static void Remove<{generics}>(this in Entity entity)
139+
{{
140+
var world = World.Worlds[entity.WorldId];
141+
world.Remove<{generics}>(in entity);
142+
}}
93143
";
94144

95145
return sb.AppendLine(template);

Arch.SourceGenerator/QueryGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public static partial class EntityExtensions{{
104104
{new StringBuilder().AppendEntityHases(10)}
105105
{new StringBuilder().AppendEntitySets(10)}
106106
{new StringBuilder().AppendEntityGets(10)}
107+
{new StringBuilder().AppendEntityAdds(10)}
108+
{new StringBuilder().AppendEntityRemoves(10)}
107109
}}
108110
");
109111

0 commit comments

Comments
 (0)