Added player control example base

This commit is contained in:
2021-06-11 20:55:42 +12:00
parent 21513f69ed
commit 8082817860
15 changed files with 332 additions and 45 deletions
@@ -18,7 +18,12 @@ public final class App {
*/
public static void main(String[] args) {
int nEntities = 1_000_000;
double startTime = System.nanoTime();
Engine engine = new Engine(nEntities);
double endTime = System.nanoTime();
System.out.println("Constructor Time taken: " + (endTime - startTime) / 1e6+ " ms " + "("+ (endTime - startTime) / 1e9 + " seconds )");
engine.registerComponent(ComflabulationComponent.class);
engine.registerComponent(DirectionComponent.class);
@@ -29,7 +34,9 @@ public final class App {
MovementSystem movementSystem = new MovementSystem(engine);
engine.registerSystem(MovementSystem.class, movementSystem);
double startTime = System.nanoTime();
startTime = System.nanoTime();
for (int i = 0; i < nEntities; i++) {
Entity entity = engine.createEntity();
engine.addComponent(entity, PositionComponent.class, new PositionComponent());
@@ -39,17 +46,17 @@ public final class App {
engine.addComponent(entity, ComflabulationComponent.class, new ComflabulationComponent());
}
}
double endTime = System.nanoTime();
endTime = System.nanoTime();
System.out.println("Entity creation Time taken: " + (endTime - startTime) / 1e6+ " ms " + "("+ (endTime - startTime) / 1e9 + "seconds )");
System.out.println("Entity creation Time taken: " + (endTime - startTime) / 1e6+ " ms " + "("+ (endTime - startTime) / 1e9 + " seconds )");
Float dt = 1.0f/60.0f;
double 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("Single Loop Time taken: " + (endTime - startTime) / 1e6+ " ms " + "("+ (endTime - startTime) / 1e9 + " seconds )");
System.out.println("Hello World!");
}
@@ -1,12 +1,12 @@
package nz.ac.massey.javaecs.examples.Components;
public class ComflabulationComponent {
public Float thingy;
public Integer dingy;
public double thingy;
public int dingy;
public boolean mingy;
public String stringy;
public ComflabulationComponent(Float thingy, Integer dingy, boolean mingy, String stringy){
public ComflabulationComponent(double thingy, int dingy, boolean mingy, String stringy){
this.thingy = thingy;
this.dingy = dingy;
this.mingy = mingy;
@@ -1,10 +1,10 @@
package nz.ac.massey.javaecs.examples.Components;
public class DirectionComponent {
public Float x;
public Float y;
public double x;
public double y;
public DirectionComponent(Float x, Float y){
public DirectionComponent(double x, double y){
this.x = x;
this.y = y;
}
@@ -1,10 +1,10 @@
package nz.ac.massey.javaecs.examples.Components;
public class PositionComponent {
public Float x;
public Float y;
public double x;
public double y;
public PositionComponent(Float x, Float y){
public PositionComponent(double x, double y){
this.x = x;
this.y = y;
}
@@ -26,10 +26,10 @@ public class ComflabSystem extends ECSSystem {
public void update() {
}
public void update(Float dt) {
public void update(double dt) {
for (Entity entity : entities) {
ComflabulationComponent comflab = (ComflabulationComponent)ecs.getComponentData(entity, ComflabulationComponent.class);
comflab.thingy *= 1.000001f;
comflab.thingy *= 1.000001;
comflab.mingy = !comflab.mingy;
comflab.dingy++;
}
@@ -29,7 +29,7 @@ public class MovementSystem extends ECSSystem {
public void update() {
}
public void update(Float dt) {
public void update(double dt) {
for (Entity entity : entities) {
PositionComponent position = (PositionComponent)ecs.getComponentData(entity, PositionComponent.class);
DirectionComponent direction = (DirectionComponent)ecs.getComponentData(entity, DirectionComponent.class);