Skip to content

Commit 8e9d679

Browse files
committed
CodeGen - use generate Query code
1 parent 32b8d49 commit 8e9d679

File tree

17 files changed

+319
-315
lines changed

17 files changed

+319
-315
lines changed

src/CodeGen/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ public static void Main(string[] args)
1414
for (int n = 2; n <= 5; n++)
1515
{
1616
var iEach = QueryGen.IEach_generator(n);
17-
Write(dir, $"Query/Arg.{n}/IEach.txt", iEach);
17+
Write(dir, $"Query/Arg.{n}/IEach.cs", iEach);
1818

1919
var query = QueryGen.Query_generator(n);
20-
Write(dir, $"Query/Arg.{n}/Query.txt", query);
20+
Write(dir, $"Query/Arg.{n}/Query.cs", query);
2121

2222
var queryChunks = QueryGen.Query_Chunks_generator(n);
23-
Write(dir, $"Query/Arg.{n}/Query.Chunks.txt", queryChunks);
23+
Write(dir, $"Query/Arg.{n}/Query.Chunks.cs", queryChunks);
2424

2525
var queryJob = QueryGen.QueryJob_generator(n);
26-
Write(dir, $"Query/Arg.{n}/QueryJob.txt", queryJob);
26+
Write(dir, $"Query/Arg.{n}/QueryJob.cs", queryJob);
2727
}
2828
}
2929

src/ECS/Query/Arg.2/IEach.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// ReSharper disable once CheckNamespace
66
namespace Friflo.Engine.ECS;
77

8-
public interface IEach<T1, T2>
8+
public interface IEach<T1,T2>
99
{
1010
void Execute(ref T1 c1, ref T2 c2);
1111
}
1212

13-
public interface IEachEntity<T1, T2>
13+
public interface IEachEntity<T1,T2>
1414
{
1515
void Execute(ref T1 c1, ref T2 c2, int id);
1616
}

src/ECS/Query/Arg.2/Query.Chunks.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ namespace Friflo.Engine.ECS;
1616
/// Contains the components returned by a component query.
1717
/// See <a href="https://friflo.gitbook.io/friflo.engine.ecs/documentation/query-optimization#enumerate-query-chunks">Example.</a>
1818
/// </summary>
19-
public readonly struct Chunks<T1, T2>
20-
where T1 : struct
21-
where T2 : struct
19+
public readonly struct Chunks<T1,T2>
20+
where T1 : struct
21+
where T2 : struct
2222
{
2323
public int Length => Chunk1.Length;
2424
public readonly Chunk<T1> Chunk1; // 16
@@ -28,12 +28,12 @@ public readonly struct Chunks<T1, T2>
2828
public override string ToString() => Entities.GetChunksString();
2929

3030
internal Chunks(Chunk<T1> chunk1, Chunk<T2> chunk2, in ChunkEntities entities) {
31-
Chunk1 = chunk1;
31+
Chunk1 = chunk1;
3232
Chunk2 = chunk2;
3333
Entities = entities;
3434
}
3535

36-
internal Chunks(in Chunks<T1, T2> chunks, int start, int length, int taskIndex) {
36+
internal Chunks(in Chunks<T1,T2> chunks, int start, int length, int taskIndex) {
3737
Chunk1 = new Chunk<T1> (chunks.Chunk1, start, length);
3838
Chunk2 = new Chunk<T2> (chunks.Chunk2, start, length);
3939
Entities = new ChunkEntities(chunks.Entities, start, length, taskIndex);
@@ -54,11 +54,11 @@ public void Deconstruct(out Chunk<T1> chunk1, out Chunk<T2> chunk2, out ChunkEnt
5454
/// Contains the component chunks returned by a component query.
5555
/// See <a href="https://friflo.gitbook.io/friflo.engine.ecs/documentation/query-optimization#enumerate-query-chunks">Example.</a>
5656
/// </summary>
57-
public readonly struct QueryChunks<T1, T2> : IEnumerable <Chunks<T1,T2>>
58-
where T1 : struct
59-
where T2 : struct
57+
public readonly struct QueryChunks<T1,T2> : IEnumerable <Chunks<T1,T2>>
58+
where T1 : struct
59+
where T2 : struct
6060
{
61-
private readonly ArchetypeQuery<T1, T2> query;
61+
private readonly ArchetypeQuery<T1,T2> query;
6262

6363
public int Count => query.Count;
6464

@@ -68,26 +68,26 @@ public void Deconstruct(out Chunk<T1> chunk1, out Chunk<T2> chunk2, out ChunkEnt
6868

6969
public override string ToString() => query.GetQueryChunksString();
7070

71-
internal QueryChunks(ArchetypeQuery<T1, T2> query) {
71+
internal QueryChunks(ArchetypeQuery<T1,T2> query) {
7272
this.query = query;
7373
}
7474

7575
// --- IEnumerable<>
7676
[ExcludeFromCodeCoverage]
7777
IEnumerator<Chunks<T1,T2>>
78-
IEnumerable<Chunks<T1,T2>>.GetEnumerator() => new ChunkEnumerator<T1, T2> (query);
78+
IEnumerable<Chunks<T1,T2>>.GetEnumerator() => new ChunkEnumerator<T1,T2> (query);
7979

8080
// --- IEnumerable
8181
[ExcludeFromCodeCoverage]
82-
IEnumerator IEnumerable.GetEnumerator() => new ChunkEnumerator<T1, T2> (query);
82+
IEnumerator IEnumerable.GetEnumerator() => new ChunkEnumerator<T1,T2> (query);
8383

8484
// --- IEnumerable
85-
public ChunkEnumerator<T1, T2> GetEnumerator() => new (query);
85+
public ChunkEnumerator<T1,T2> GetEnumerator() => new (query);
8686
}
8787

88-
public struct ChunkEnumerator<T1, T2> : IEnumerator<Chunks<T1,T2>>
89-
where T1 : struct
90-
where T2 : struct
88+
public struct ChunkEnumerator<T1,T2> : IEnumerator<Chunks<T1,T2>>
89+
where T1 : struct
90+
where T2 : struct
9191
{
9292
private readonly int structIndex1; // 4
9393
private readonly int structIndex2; // 4
@@ -96,10 +96,10 @@ public struct ChunkEnumerator<T1, T2> : IEnumerator<Chunks<T1,T2>>
9696
private readonly Archetypes archetypes; // 16
9797
//
9898
private int archetypePos; // 4
99-
private Chunks<T1, T2> chunks; // 46
99+
private Chunks<T1,T2> chunks;
100100

101101

102-
internal ChunkEnumerator(ArchetypeQuery<T1, T2> query)
102+
internal ChunkEnumerator(ArchetypeQuery<T1,T2> query)
103103
{
104104
structIndex1 = query.signatureIndexes.T1;
105105
structIndex2 = query.signatureIndexes.T2;
@@ -153,7 +153,7 @@ public bool MoveNext()
153153
var chunk1 = new Chunk<T1>(chunks1.components, count, start);
154154
var chunk2 = new Chunk<T2>(chunks2.components, count, start);
155155
var entities = new ChunkEntities(archetype, count, start);
156-
chunks = new Chunks<T1, T2>(chunk1, chunk2, entities);
156+
chunks = new Chunks<T1,T2>(chunk1, chunk2, entities);
157157
return true;
158158
SingleEntity:
159159
if (pos >= types.last) {

src/ECS/Query/Arg.2/Query.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,52 @@ namespace Friflo.Engine.ECS;
99
/// <summary>
1010
/// Provide the state of an <paramref name="entity"/> within <see cref="ArchetypeQuery{T1,T2}.ForEachEntity"/>.
1111
/// </summary>
12-
public delegate void ForEachEntity<T1, T2>(ref T1 component1, ref T2 component2, Entity entity)
13-
where T1 : struct
14-
where T2 : struct;
12+
public delegate void ForEachEntity<T1,T2>(ref T1 component1, ref T2 component2, Entity entity)
13+
where T1 : struct
14+
where T2 : struct;
1515

1616

1717
/// <summary>
1818
/// A query instance use to retrieve the given component types.
1919
/// See <a href="https://friflo.gitbook.io/friflo.engine.ecs/documentation/query">Example.</a>
2020
/// </summary>
21-
public sealed class ArchetypeQuery<T1, T2> : ArchetypeQuery // : IEnumerable <> // <- not implemented to avoid boxing
22-
where T1 : struct
23-
where T2 : struct
21+
public sealed class ArchetypeQuery<T1,T2> : ArchetypeQuery // : IEnumerable <> // <- not implemented to avoid boxing
22+
where T1 : struct
23+
where T2 : struct
2424
{
2525
/// <inheritdoc cref="ArchetypeQuery.AllTags"/>
26-
public new ArchetypeQuery<T1, T2> AllTags (in Tags tags) { SetHasAllTags(tags); return this; }
26+
public new ArchetypeQuery<T1,T2> AllTags (in Tags tags) { SetHasAllTags(tags); return this; }
2727
/// <inheritdoc cref="ArchetypeQuery.AnyTags"/>
28-
public new ArchetypeQuery<T1, T2> AnyTags (in Tags tags) { SetHasAnyTags(tags); return this; }
28+
public new ArchetypeQuery<T1,T2> AnyTags (in Tags tags) { SetHasAnyTags(tags); return this; }
2929
/// <inheritdoc cref="ArchetypeQuery.WithDisabled"/>
30-
public new ArchetypeQuery<T1, T2> WithDisabled () { SetWithDisabled(); return this; }
30+
public new ArchetypeQuery<T1,T2> WithDisabled () { SetWithDisabled(); return this; }
3131
/// <inheritdoc cref="ArchetypeQuery.WithoutAllTags"/>
32-
public new ArchetypeQuery<T1, T2> WithoutAllTags(in Tags tags) { SetWithoutAllTags(tags); return this; }
32+
public new ArchetypeQuery<T1,T2> WithoutAllTags(in Tags tags) { SetWithoutAllTags(tags); return this; }
3333
/// <inheritdoc cref="ArchetypeQuery.WithoutAnyTags"/>
34-
public new ArchetypeQuery<T1, T2> WithoutAnyTags(in Tags tags) { SetWithoutAnyTags(tags); return this; }
34+
public new ArchetypeQuery<T1,T2> WithoutAnyTags(in Tags tags) { SetWithoutAnyTags(tags); return this; }
3535

3636
/// <inheritdoc cref="ArchetypeQuery.AllComponents"/>
37-
public new ArchetypeQuery<T1, T2> AllComponents (in ComponentTypes componentTypes) { SetHasAllComponents(componentTypes); return this; }
37+
public new ArchetypeQuery<T1,T2> AllComponents (in ComponentTypes componentTypes) { SetHasAllComponents(componentTypes); return this; }
3838
/// <inheritdoc cref="ArchetypeQuery.AnyComponents"/>
39-
public new ArchetypeQuery<T1, T2> AnyComponents (in ComponentTypes componentTypes) { SetHasAnyComponents(componentTypes); return this; }
39+
public new ArchetypeQuery<T1,T2> AnyComponents (in ComponentTypes componentTypes) { SetHasAnyComponents(componentTypes); return this; }
4040
/// <inheritdoc cref="ArchetypeQuery.WithoutAllComponents"/>
41-
public new ArchetypeQuery<T1, T2> WithoutAllComponents(in ComponentTypes componentTypes) { SetWithoutAllComponents(componentTypes); return this; }
41+
public new ArchetypeQuery<T1,T2> WithoutAllComponents(in ComponentTypes componentTypes) { SetWithoutAllComponents(componentTypes); return this; }
4242
/// <inheritdoc cref="ArchetypeQuery.WithoutAnyComponents"/>
43-
public new ArchetypeQuery<T1, T2> WithoutAnyComponents(in ComponentTypes componentTypes) { SetWithoutAnyComponents(componentTypes); return this; }
43+
public new ArchetypeQuery<T1,T2> WithoutAnyComponents(in ComponentTypes componentTypes) { SetWithoutAnyComponents(componentTypes); return this; }
4444

4545
/// <inheritdoc cref="QueryFilter.HasValue{TComponent,TValue}"/>
46-
public new ArchetypeQuery<T1, T2> HasValue <TComponent,TValue>(TValue value) where TComponent : struct, IIndexedComponent<TValue>
46+
public new ArchetypeQuery<T1,T2> HasValue <TComponent,TValue>(TValue value) where TComponent : struct, IIndexedComponent<TValue>
4747
{ base.HasValue <TComponent, TValue>(value); return this; }
4848

4949
/// <inheritdoc cref="QueryFilter.ValueInRange{TComponent,TValue}"/>
50-
public new ArchetypeQuery<T1, T2> ValueInRange<TComponent,TValue>(TValue min, TValue max) where TComponent : struct, IIndexedComponent<TValue> where TValue : IComparable<TValue>
50+
public new ArchetypeQuery<T1,T2> ValueInRange<TComponent,TValue>(TValue min, TValue max) where TComponent : struct, IIndexedComponent<TValue> where TValue : IComparable<TValue>
5151
{ base.ValueInRange<TComponent, TValue>(min, max); return this; }
5252

5353

5454
/// <inheritdoc cref="ArchetypeQuery.FreezeFilter"/>
55-
public new ArchetypeQuery<T1, T2> FreezeFilter() { SetFreezeFilter(); return this; }
55+
public new ArchetypeQuery<T1,T2> FreezeFilter() { SetFreezeFilter(); return this; }
5656

57-
internal ArchetypeQuery(EntityStoreBase store, in Signature<T1, T2> signature, QueryFilter filter)
57+
internal ArchetypeQuery(EntityStoreBase store, in Signature<T1,T2> signature, QueryFilter filter)
5858
: base(store, signature.signatureIndexes, filter, null) {
5959
}
6060

@@ -67,12 +67,12 @@ internal ArchetypeQuery(EntityStoreBase store, in Signature<T1, T2> signature, Q
6767
/// <summary>
6868
/// Returns a <see cref="QueryJob"/> that enables <see cref="JobExecution.Parallel"/> query execution.
6969
/// </summary>
70-
public QueryJob<T1, T2> ForEach(Action<Chunk<T1>, Chunk<T2>, ChunkEntities> action) => new (this, action);
70+
public QueryJob<T1,T2> ForEach(Action<Chunk<T1>, Chunk<T2>, ChunkEntities> action) => new (this, action);
7171

7272
/// <summary>
7373
/// Executes the given <paramref name="lambda"/> for each entity in the query result.
7474
/// </summary>
75-
public void ForEachEntity(ForEachEntity<T1, T2> lambda)
75+
public void ForEachEntity(ForEachEntity<T1,T2> lambda)
7676
{
7777
var localStore = Store;
7878
var nodes = localStore.nodes;

src/ECS/Query/Arg.2/QueryJob.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ namespace Friflo.Engine.ECS;
1414
/// Enables <see cref="JobExecution.Parallel"/> query execution returning the specified components.
1515
/// See <a href="https://friflo.gitbook.io/friflo.engine.ecs/documentation/query-optimization#parallel-query-job">Example.</a>
1616
/// </summary>
17-
public sealed class QueryJob<T1, T2> : QueryJob
18-
where T1 : struct
19-
where T2 : struct
17+
public sealed class QueryJob<T1,T2> : QueryJob
18+
where T1 : struct
19+
where T2 : struct
2020
{
21-
internal QueryChunks<T1, T2> Chunks => new (query); // only for debugger
21+
internal QueryChunks<T1,T2> Chunks => new (query); // only for debugger
2222
internal QueryEntities Entities => query.Entities; // only for debugger
2323
public override string ToString() => query.GetQueryJobString();
2424

2525
[Browse(Never)]
26-
private readonly ArchetypeQuery<T1, T2> query; // 8
26+
private readonly ArchetypeQuery<T1,T2> query; // 8
2727
private readonly Action<Chunk<T1>, Chunk<T2>, ChunkEntities> action; // 8
2828
[Browse(Never)]
2929
private QueryJobTask[] jobTasks; // 8
3030

3131

3232
private class QueryJobTask : JobTask {
3333
internal Action<Chunk<T1>, Chunk<T2>, ChunkEntities> action;
34-
internal Chunks<T1, T2> chunks;
34+
internal Chunks<T1,T2> chunks;
3535

3636
internal override void ExecuteTask() => action(chunks.Chunk1, chunks.Chunk2, chunks.Entities);
3737
}
3838

3939
internal QueryJob(
40-
ArchetypeQuery<T1, T2> query,
40+
ArchetypeQuery<T1,T2> query,
4141
Action<Chunk<T1>, Chunk<T2>, ChunkEntities> action)
4242
{
4343
this.query = query;
@@ -47,7 +47,7 @@ internal QueryJob(
4747

4848
public override void Run()
4949
{
50-
foreach (Chunks<T1, T2> chunks in query.Chunks) {
50+
foreach (Chunks<T1,T2> chunks in query.Chunks) {
5151
action(chunks.Chunk1, chunks.Chunk2, chunks.Entities);
5252
}
5353
}
@@ -62,7 +62,7 @@ public override void RunParallel()
6262
if (jobRunner == null) throw JobRunnerIsNullException();
6363
var taskCount = jobRunner.workerCount + 1;
6464

65-
foreach (Chunks<T1, T2> chunks in query.Chunks)
65+
foreach (Chunks<T1,T2> chunks in query.Chunks)
6666
{
6767
var chunkLength = chunks.Length;
6868
if (ExecuteSequential(taskCount, chunkLength)) {
@@ -82,12 +82,12 @@ public override void RunParallel()
8282
{
8383
var length = GetSectionLength (chunkLength, start, sectionSize);
8484
if (length > 0) {
85-
tasks[taskIndex].chunks = new Chunks<T1, T2>(chunks, start, length, taskIndex);
85+
tasks[taskIndex].chunks = new Chunks<T1,T2>(chunks, start, length, taskIndex);
8686
start += sectionSize;
8787
continue;
8888
}
8989
for (; taskIndex < taskCount; taskIndex++) {
90-
tasks[taskIndex].chunks = new Chunks<T1, T2>(chunks.Entities, taskIndex);
90+
tasks[taskIndex].chunks = new Chunks<T1,T2>(chunks.Entities, taskIndex);
9191
}
9292
break;
9393
}

src/ECS/Query/Arg.3/IEach.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// ReSharper disable once CheckNamespace
66
namespace Friflo.Engine.ECS;
77

8-
public interface IEach<T1, T2, T3>
8+
public interface IEach<T1,T2,T3>
99
{
1010
void Execute(ref T1 c1, ref T2 c2, ref T3 c3);
1111
}
1212

13-
public interface IEachEntity<T1, T2, T3>
13+
public interface IEachEntity<T1,T2,T3>
1414
{
1515
void Execute(ref T1 c1, ref T2 c2, ref T3 c3, int id);
1616
}

0 commit comments

Comments
 (0)