diff --git a/perftest/.gitignore b/perftest/.gitignore
index 7194620..5837de0 100644
--- a/perftest/.gitignore
+++ b/perftest/.gitignore
@@ -26,3 +26,6 @@ buildNumber.properties
.factorypath
.project
.vscode/
+
+# Ignore logs, these came from an error in the VM
+*.log
diff --git a/perftest/pom.xml b/perftest/pom.xml
index e972c79..9ce7a7d 100644
--- a/perftest/pom.xml
+++ b/perftest/pom.xml
@@ -35,6 +35,11 @@
${junit.version}
test
+
+ nz.ac.massey.javaecs
+ javaecs
+ 0.9.2-PRERELEASE
+
diff --git a/perftest/src/main/java/nz/ac/massey/javaecs/examples/App.java b/perftest/src/main/java/nz/ac/massey/javaecs/examples/App.java
index 664e4aa..9c79f6b 100644
--- a/perftest/src/main/java/nz/ac/massey/javaecs/examples/App.java
+++ b/perftest/src/main/java/nz/ac/massey/javaecs/examples/App.java
@@ -17,7 +17,40 @@ public final class App {
* @param args The arguments of the program.
*/
public static void main(String[] args) {
- Engine engine = new Engine();
+ int nEntities = 1_000_000;
+ Engine engine = new Engine(nEntities);
+
+ engine.registerComponent(ComflabulationComponent.class);
+ engine.registerComponent(DirectionComponent.class);
+ engine.registerComponent(PositionComponent.class);
+
+ ComflabSystem comflabSystem = new ComflabSystem(engine);
+ engine.registerSystem(ComflabSystem.class, comflabSystem);
+
+ MovementSystem movementSystem = new MovementSystem(engine);
+ engine.registerSystem(MovementSystem.class, movementSystem);
+ double startTime = System.nanoTime();
+ for (int i = 0; i < nEntities; i++) {
+ Entity entity = engine.createEntity();
+ engine.addComponent(entity, PositionComponent.class, new PositionComponent());
+ engine.addComponent(entity, DirectionComponent.class, new DirectionComponent());
+
+ if (i % 2 != 0){
+ engine.addComponent(entity, ComflabulationComponent.class, new ComflabulationComponent());
+ }
+ }
+ double endTime = System.nanoTime();
+
+ System.out.println("Entity creation Time taken: " + (endTime - startTime) / 1e6+ " ms " + "("+ (endTime - startTime) / 1e9 + "seconds )");
+
+ Float dt = 1.0f/60.0f;
+ startTime = System.nanoTime();
+ movementSystem.update(dt);
+ comflabSystem.update(dt);
+ endTime = System.nanoTime();
+
+ System.out.println("Time taken: " + (endTime - startTime) / 1e6+ " ms " + "("+ (endTime - startTime) / 1e9 + "seconds )");
+
System.out.println("Hello World!");
}
}
diff --git a/perftest/src/main/java/nz/ac/massey/javaecs/examples/Components/ComflabulationComponent.java b/perftest/src/main/java/nz/ac/massey/javaecs/examples/Components/ComflabulationComponent.java
new file mode 100644
index 0000000..64b1648
--- /dev/null
+++ b/perftest/src/main/java/nz/ac/massey/javaecs/examples/Components/ComflabulationComponent.java
@@ -0,0 +1,22 @@
+package nz.ac.massey.javaecs.examples.Components;
+
+public class ComflabulationComponent {
+ public Float thingy;
+ public Integer dingy;
+ public boolean mingy;
+ public String stringy;
+
+ public ComflabulationComponent(Float thingy, Integer dingy, boolean mingy, String stringy){
+ this.thingy = thingy;
+ this.dingy = dingy;
+ this.mingy = mingy;
+ this.stringy = stringy;
+ }
+
+ public ComflabulationComponent(){
+ thingy = 0.0f;
+ dingy = 0;
+ mingy = false;
+ stringy = "";
+ }
+}
diff --git a/perftest/src/main/java/nz/ac/massey/javaecs/examples/Components/DirectionComponent.java b/perftest/src/main/java/nz/ac/massey/javaecs/examples/Components/DirectionComponent.java
new file mode 100644
index 0000000..9b6937d
--- /dev/null
+++ b/perftest/src/main/java/nz/ac/massey/javaecs/examples/Components/DirectionComponent.java
@@ -0,0 +1,16 @@
+package nz.ac.massey.javaecs.examples.Components;
+
+public class DirectionComponent {
+ public Float x;
+ public Float y;
+
+ public DirectionComponent(Float x, Float y){
+ this.x = x;
+ this.y = y;
+ }
+
+ public DirectionComponent(){
+ x = 0.0f;
+ y = 0.0f;
+ }
+}
diff --git a/perftest/src/main/java/nz/ac/massey/javaecs/examples/Components/PositionComponent.java b/perftest/src/main/java/nz/ac/massey/javaecs/examples/Components/PositionComponent.java
new file mode 100644
index 0000000..eeaf643
--- /dev/null
+++ b/perftest/src/main/java/nz/ac/massey/javaecs/examples/Components/PositionComponent.java
@@ -0,0 +1,16 @@
+package nz.ac.massey.javaecs.examples.Components;
+
+public class PositionComponent {
+ public Float x;
+ public Float y;
+
+ public PositionComponent(Float x, Float y){
+ this.x = x;
+ this.y = y;
+ }
+
+ public PositionComponent(){
+ x = 0.0f;
+ y = 0.0f;
+ }
+}
diff --git a/perftest/src/main/java/nz/ac/massey/javaecs/examples/Systems/ComflabSystem.java b/perftest/src/main/java/nz/ac/massey/javaecs/examples/Systems/ComflabSystem.java
new file mode 100644
index 0000000..2c78fc5
--- /dev/null
+++ b/perftest/src/main/java/nz/ac/massey/javaecs/examples/Systems/ComflabSystem.java
@@ -0,0 +1,37 @@
+package nz.ac.massey.javaecs.examples.Systems;
+
+import java.util.BitSet;
+
+import nz.ac.massey.javaecs.ECSSystem;
+import nz.ac.massey.javaecs.Engine;
+import nz.ac.massey.javaecs.Entity;
+import nz.ac.massey.javaecs.examples.Components.ComflabulationComponent;
+
+public class ComflabSystem extends ECSSystem {
+ Engine ecs;
+
+ public ComflabSystem(Engine ecs){
+ this.ecs = ecs;
+ registrationSet = new BitSet();
+ registrationSet.set(ecs.getComponentIndex(ComflabulationComponent.class));
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void update() {
+ }
+
+ public void update(Float dt) {
+ for (Entity entity : entities) {
+ ComflabulationComponent comflab = (ComflabulationComponent)ecs.getComponentData(entity, ComflabulationComponent.class);
+ comflab.thingy *= 1.000001f;
+ comflab.mingy = !comflab.mingy;
+ comflab.dingy++;
+ }
+ }
+}
diff --git a/perftest/src/main/java/nz/ac/massey/javaecs/examples/Systems/MovementSystem.java b/perftest/src/main/java/nz/ac/massey/javaecs/examples/Systems/MovementSystem.java
new file mode 100644
index 0000000..865541c
--- /dev/null
+++ b/perftest/src/main/java/nz/ac/massey/javaecs/examples/Systems/MovementSystem.java
@@ -0,0 +1,43 @@
+package nz.ac.massey.javaecs.examples.Systems;
+
+import java.lang.management.ThreadInfo;
+import java.util.BitSet;
+
+import nz.ac.massey.javaecs.ECSSystem;
+import nz.ac.massey.javaecs.Engine;
+import nz.ac.massey.javaecs.Entity;
+import nz.ac.massey.javaecs.examples.Components.DirectionComponent;
+import nz.ac.massey.javaecs.examples.Components.PositionComponent;
+
+public class MovementSystem extends ECSSystem {
+ Engine ecs;
+
+ public MovementSystem(Engine ecs){
+ this.ecs = ecs;
+ registrationSet = new BitSet();
+ registrationSet.set(ecs.getComponentIndex(PositionComponent.class));
+ registrationSet.set(ecs.getComponentIndex(DirectionComponent.class));
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void update() {
+ }
+
+ public void update(Float dt) {
+ for (Entity entity : entities) {
+ PositionComponent position = (PositionComponent)ecs.getComponentData(entity, PositionComponent.class);
+ DirectionComponent direction = (DirectionComponent)ecs.getComponentData(entity, DirectionComponent.class);
+ position.x += direction.x * dt;
+ position.y += direction.y * dt;
+ }
+
+
+ }
+
+}