Skip to content

Commit d7ee11a

Browse files
committed
generate many impl of each(Component..*) for Query, System and Observer
1 parent f14ea79 commit d7ee11a

137 files changed

Lines changed: 38505 additions & 33 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle.kts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,24 @@ val validateGeneratedBindings by tasks.registering {
224224
}
225225
}
226226

227+
val generatorSourcesDir = file("src/generator/java")
228+
229+
val generateEachBase by tasks.registering(JavaExec::class) {
230+
description = "Generate QueryBase, SystemBuilderBase, ObserverBuilderBase and all typed each callback interfaces"
231+
group = "flecs"
232+
classpath = sourceSets["generator"].runtimeClasspath
233+
mainClass.set("com.github.elebras1.flecs.EachBaseGenerator")
234+
args(generatedSourcesDir.absolutePath)
235+
outputs.dir(generatedSourcesDir)
236+
doFirst {
237+
generatedSourcesDir.mkdirs()
238+
}
239+
}
240+
227241
sourceSets {
242+
create("generator") {
243+
java.srcDir(generatorSourcesDir)
244+
}
228245
main {
229246
java {
230247
srcDir(generatedSourcesDir)
@@ -236,6 +253,9 @@ sourceSets {
236253
}
237254
}
238255

256+
configurations["generatorCompileClasspath"].extendsFrom(configurations["compileClasspath"])
257+
configurations["generatorRuntimeClasspath"].extendsFrom(configurations["runtimeClasspath"])
258+
239259
tasks.named("processResources") {
240260
dependsOn(copyFlecsNative)
241261
}

examples/src/main/java/com/github/elebras1/flecs/examples/SimpleQueryBenchmark.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public static void main(String[] args) {
3939
System.out.println("Query matches " + query.count() + " entities");
4040
System.out.println();
4141

42-
System.out.println("--- Benchmark 1: each() + entity.get(Component.class) ---");
43-
runBenchmark("each+get", () -> benchmarkEachGet(world, query));
42+
System.out.println("--- Benchmark 1: each(Component.class, Component.class, ...) ---");
43+
runBenchmark("each+get", () -> benchmarkEach(query));
4444

45-
System.out.println("--- Benchmark 2: each() + entity.getMutView(Component.class) ---");
46-
runBenchmark("each+getMutView", () -> benchmarkEachGetMutView(world, query));
45+
System.out.println("--- Benchmark 2: eachView(Component.class, Component.class, ...) ---");
46+
runBenchmark("each+getMutView", () -> benchmarkEachMutView(query));
4747

4848
System.out.println("--- Benchmark 3: iter() + Field<T>.get(i) ---");
4949
runBenchmark("iter+Field+get", () -> benchmarkIterFieldGet(query));
@@ -57,28 +57,20 @@ public static void main(String[] args) {
5757
}
5858
}
5959

60-
private static float benchmarkEachGet(World world, Query query) {
60+
private static float benchmarkEach(Query query) {
6161
final float[] sum = {0.0f};
6262

63-
query.each(entityId -> {
64-
Entity entity = world.obtainEntity(entityId);
65-
Position pos = entity.get(Position.class);
66-
Velocity vel = entity.get(Velocity.class);
67-
sum[0] += pos.x() + pos.y() + vel.dx() + vel.dy();
68-
});
63+
query.each(Position.class, Velocity.class, (pos, vel)
64+
-> sum[0] += pos.x() + pos.y() + vel.dx() + vel.dy());
6965

7066
return sum[0];
7167
}
7268

73-
private static float benchmarkEachGetMutView(World world, Query query) {
69+
private static float benchmarkEachMutView(Query query) {
7470
final float[] sum = {0.0f};
7571

76-
query.each(entityId -> {
77-
Entity entity = world.obtainEntity(entityId);
78-
PositionView pos = entity.getMutView(Position.class);
79-
VelocityView vel = entity.getMutView(Velocity.class);
80-
sum[0] += pos.x() + pos.y() + vel.dx() + vel.dy();
81-
});
72+
query.eachView(Position.class, Velocity.class, (PositionView posView, VelocityView velView)
73+
-> sum[0] += posView.x() + posView.y() + velView.dx() + velView.dy());
8274

8375
return sum[0];
8476
}

0 commit comments

Comments
 (0)