Added player control example base

This commit is contained in:
Brychan Dempsey 2021-06-11 20:55:42 +12:00
parent 21513f69ed
commit 8082817860
15 changed files with 332 additions and 45 deletions

View File

@ -70,28 +70,28 @@ public final class App {
// Bottom boundary // Bottom boundary
Entity newEnt = gameEngine.createEntity(); Entity newEnt = gameEngine.createEntity();
gameEngine.addComponent(newEnt, Vec2D.class, new Vec2D(-50., -50.,0)); gameEngine.addComponent(newEnt, Vec2D.class, new Vec2D(-50., -50.,0));
gameEngine.addComponent(newEnt, RidgidBody.class, new RidgidBody(0., 0., 0., 0., 0.f, 0., -1.)); gameEngine.addComponent(newEnt, RidgidBody.class, new RidgidBody(0., 0., 0., 0., 0.f, 0.25, -1.));
gameEngine.addComponent(newEnt, Collider.class, new Collider(200., 50.)); // 200 along, 50 up gameEngine.addComponent(newEnt, Collider.class, new Collider(200., 50.)); // 200 along, 50 up
gameEngine.addComponent(newEnt, Render.class, new Render(BoxRender.class)); gameEngine.addComponent(newEnt, Render.class, new Render(BoxRender.class));
gameEngine.addComponent(newEnt, BoxRender.class, new BoxRender(200, 50, 64, 64, 64)); gameEngine.addComponent(newEnt, BoxRender.class, new BoxRender(200, 50, 64, 64, 64));
// Left boundary // Left boundary
newEnt = gameEngine.createEntity(); newEnt = gameEngine.createEntity();
gameEngine.addComponent(newEnt, Vec2D.class, new Vec2D(-50., -50.,0)); gameEngine.addComponent(newEnt, Vec2D.class, new Vec2D(-50., -50.,0));
gameEngine.addComponent(newEnt, RidgidBody.class, new RidgidBody(0., 0., 0., 0., 0.f, 0., -1.)); gameEngine.addComponent(newEnt, RidgidBody.class, new RidgidBody(0., 0., 0., 0., 0.f, 0.25, -1.));
gameEngine.addComponent(newEnt, Collider.class, new Collider(50., 200.)); gameEngine.addComponent(newEnt, Collider.class, new Collider(50., 200.));
gameEngine.addComponent(newEnt, Render.class, new Render(BoxRender.class)); gameEngine.addComponent(newEnt, Render.class, new Render(BoxRender.class));
gameEngine.addComponent(newEnt, BoxRender.class, new BoxRender(50, 200, 64, 64, 64)); gameEngine.addComponent(newEnt, BoxRender.class, new BoxRender(50, 200, 64, 64, 64));
// Top boundary // Top boundary
newEnt = gameEngine.createEntity(); newEnt = gameEngine.createEntity();
gameEngine.addComponent(newEnt, Vec2D.class, new Vec2D(-50., 100.,0)); gameEngine.addComponent(newEnt, Vec2D.class, new Vec2D(-50., 100.,0));
gameEngine.addComponent(newEnt, RidgidBody.class, new RidgidBody(0., 0., 0., 0., 0.f, 0., -1.)); gameEngine.addComponent(newEnt, RidgidBody.class, new RidgidBody(0., 0., 0., 0., 0.f, 0.25, -1.));
gameEngine.addComponent(newEnt, Collider.class, new Collider(200., 50.)); gameEngine.addComponent(newEnt, Collider.class, new Collider(200., 50.));
gameEngine.addComponent(newEnt, Render.class, new Render(BoxRender.class)); gameEngine.addComponent(newEnt, Render.class, new Render(BoxRender.class));
gameEngine.addComponent(newEnt, BoxRender.class, new BoxRender(200, 50, 64, 64, 64)); gameEngine.addComponent(newEnt, BoxRender.class, new BoxRender(200, 50, 64, 64, 64));
// Right boundary // Right boundary
newEnt = gameEngine.createEntity(); newEnt = gameEngine.createEntity();
gameEngine.addComponent(newEnt, Vec2D.class, new Vec2D(100., -50.,0)); gameEngine.addComponent(newEnt, Vec2D.class, new Vec2D(100., -50.,0));
gameEngine.addComponent(newEnt, RidgidBody.class, new RidgidBody(0., 0., 0., 0., 0.f, 0., -1.)); gameEngine.addComponent(newEnt, RidgidBody.class, new RidgidBody(0., 0., 0., 0., 0.f, 0.25, -1.));
gameEngine.addComponent(newEnt, Collider.class, new Collider(50., 200.)); gameEngine.addComponent(newEnt, Collider.class, new Collider(50., 200.));
gameEngine.addComponent(newEnt, Render.class, new Render(BoxRender.class)); gameEngine.addComponent(newEnt, Render.class, new Render(BoxRender.class));
gameEngine.addComponent(newEnt, BoxRender.class, new BoxRender(50, 200, 64, 64, 64)); gameEngine.addComponent(newEnt, BoxRender.class, new BoxRender(50, 200, 64, 64, 64));
@ -110,8 +110,8 @@ public final class App {
gameEngine.addComponent(newEnt, Reporter.class, new Reporter()); gameEngine.addComponent(newEnt, Reporter.class, new Reporter());
gameEngine.addComponent(newEnt, Vec2D.class, new Vec2D(5,5,0)); gameEngine.addComponent(newEnt, Vec2D.class, new Vec2D(5,5,0));
/* // Uncomment this block to enable the stress-test (runs 500 square entities, with physics etc.) // Uncomment this block to enable the stress-test (runs 500 square entities, with physics etc.)
Random rand = new Random(); /*Random rand = new Random();
for (int i = 0; i < 500; i++) { for (int i = 0; i < 500; i++) {
newEnt = gameEngine.createEntity(); newEnt = gameEngine.createEntity();
double size = 1 + rand.nextDouble(); double size = 1 + rand.nextDouble();
@ -122,7 +122,7 @@ public final class App {
gameEngine.addComponent(newEnt, Render.class, new Render(BoxRender.class)); gameEngine.addComponent(newEnt, Render.class, new Render(BoxRender.class));
gameEngine.addComponent(newEnt, BoxRender.class, new BoxRender(size, size, 30 + rand.nextInt(225), 30 + rand.nextInt(225), 30 + rand.nextInt(225))); gameEngine.addComponent(newEnt, BoxRender.class, new BoxRender(size, size, 30 + rand.nextInt(225), 30 + rand.nextInt(225), 30 + rand.nextInt(225)));
gameEngine.addComponent(newEnt, TimedExistence.class, new TimedExistence(25 + rand.nextDouble() * 90)); gameEngine.addComponent(newEnt, TimedExistence.class, new TimedExistence(25 + rand.nextDouble() * 90));
} */ }*/
/************************************ /************************************
** Run init() on the systems ** ** Run init() on the systems **

View File

@ -42,9 +42,8 @@ public class CollisionSystem extends ECSSystem {
Collider collider = (Collider) gameEngine.getComponentData(entity, Collider.class); Collider collider = (Collider) gameEngine.getComponentData(entity, Collider.class);
if (ridgidBody.mass >= 0) { if (ridgidBody.mass >= 0) {
// Only ignore non-static colliders // Only ignore non-static colliders
//processed.add(entity);
for (Entity entity2 : entities) { for (Entity entity2 : entities) {
if (!processed.contains(entity2)) { if (!processed.contains(entity2)) { // If this entity has been added, we've already calc'ed its forces completely
// skip entities that have already been processed // skip entities that have already been processed
Vec2D otherPos = (Vec2D) gameEngine.getComponentData(entity2, Vec2D.class); Vec2D otherPos = (Vec2D) gameEngine.getComponentData(entity2, Vec2D.class);
RidgidBody otherRidgidBody = (RidgidBody) gameEngine.getComponentData(entity2, RidgidBody otherRidgidBody = (RidgidBody) gameEngine.getComponentData(entity2,
@ -74,7 +73,7 @@ public class CollisionSystem extends ECSSystem {
double totalYVel = Math.abs(ridgidBody.yVel) + Math.abs(otherRidgidBody.yVel); double totalYVel = Math.abs(ridgidBody.yVel) + Math.abs(otherRidgidBody.yVel);
double xMult = 0; double xMult = 0;
double yMult = 0; double yMult = 0;
double multTot = (1 + ridgidBody.bounciness); // reflect a force back 100%, (srtabilises) then add any extra in bounce double multTot = 1; // reflect a force back 100%, (srtabilises) then add any extra in bounce
double totalMass = ridgidBody.mass + otherRidgidBody.mass; double totalMass = ridgidBody.mass + otherRidgidBody.mass;
boolean fullEdge = false; boolean fullEdge = false;
// left-hand collision // left-hand collision
@ -90,7 +89,7 @@ public class CollisionSystem extends ECSSystem {
xMult = -multTot; xMult = -multTot;
} }
// Bottom collision // Bottom collision
if (blCollide && brCollide) { else if (blCollide && brCollide) {
fullEdge = true; fullEdge = true;
//pos.y = otherPos.y + otherCollider.y; //pos.y = otherPos.y + otherCollider.y;
pos.y = otherPos.y - collider.y; pos.y = otherPos.y - collider.y;
@ -127,12 +126,12 @@ public class CollisionSystem extends ECSSystem {
} }
else if (deltaYVel > deltaXVel){ else if (deltaYVel > deltaXVel){
// Top edge // Top edge
if (deltaYVel > deltaMin) pos.y = otherPos.y + otherCollider.y; //if (deltaYVel > deltaMin) pos.y = otherPos.y + otherCollider.y;
yMult = multTot; yMult = multTot;
} }
else{ else{
if (deltaXVel > deltaMin) pos.x = otherPos.x + collider.x; //if (deltaXVel > deltaMin) pos.x = otherPos.x + collider.x;
xMult = -multTot; xMult = -multTot;
} }
} }
@ -150,11 +149,11 @@ public class CollisionSystem extends ECSSystem {
} }
else if (deltaYVel < deltaXVel){ else if (deltaYVel < deltaXVel){
//pos.y = otherPos.y + otherCollider.y; //pos.y = otherPos.y + otherCollider.y;
if (deltaYVel > deltaMin) pos.y = otherPos.y - collider.y; //if (deltaYVel > deltaMin) pos.y = otherPos.y - collider.y;
yMult = -multTot; yMult = -multTot;
} }
else{ else{
if (deltaXVel > deltaMin) pos.x = otherPos.x - collider.x; //if (deltaXVel > deltaMin) pos.x = otherPos.x - collider.x;
xMult = -multTot; xMult = -multTot;
} }
} }
@ -171,11 +170,11 @@ public class CollisionSystem extends ECSSystem {
} }
} }
else if (deltaYVel > deltaXVel){ else if (deltaYVel > deltaXVel){
if (deltaYVel > deltaMin) pos.y = otherPos.y - collider.y; //if (deltaYVel > deltaMin) pos.y = otherPos.y - collider.y;
yMult = -multTot; yMult = -multTot;
} }
else{ else{
if (deltaXVel > deltaMin) pos.x = otherPos.x + otherCollider.x; //if (deltaXVel > deltaMin) pos.x = otherPos.x + otherCollider.x;
xMult = multTot; xMult = multTot;
} }
} }
@ -192,11 +191,11 @@ public class CollisionSystem extends ECSSystem {
} }
} }
else if (deltaYVel > deltaXVel){ else if (deltaYVel > deltaXVel){
if (deltaYVel > deltaMin) pos.y = otherPos.y +otherCollider.y; //if (deltaYVel > deltaMin) pos.y = otherPos.y +otherCollider.y;
yMult = multTot; yMult = multTot;
} }
else { else {
if (deltaXVel > deltaMin) pos.x = otherPos.x + otherCollider.x; //if (deltaXVel > deltaMin) pos.x = otherPos.x + otherCollider.x;
xMult = multTot; xMult = multTot;
} }
} }
@ -207,17 +206,16 @@ public class CollisionSystem extends ECSSystem {
// entity 2 is immovable; full acceleration applied to the current entity // entity 2 is immovable; full acceleration applied to the current entity
if (otherRidgidBody.mass >= 0){ if (otherRidgidBody.mass >= 0){
yMult *= otherRidgidBody.bounciness; ridgidBody.xVel += totalXVel * ((totalMass - ridgidBody.mass) / totalMass) * (xMult + (Math.abs(xMult) + (ridgidBody.bounciness * otherRidgidBody.bounciness)));
xMult *= otherRidgidBody.bounciness; ridgidBody.yVel += totalYVel * ((totalMass - ridgidBody.mass) / totalMass) * (yMult + (Math.abs(yMult) + (ridgidBody.bounciness * otherRidgidBody.bounciness)));
ridgidBody.xVel += totalXVel * xMult * ((totalMass - ridgidBody.mass) / totalMass); otherRidgidBody.xVel -= totalXVel * ((totalMass - otherRidgidBody.mass) / totalMass) * (xMult + (Math.abs(xMult) + (ridgidBody.bounciness * otherRidgidBody.bounciness)));
ridgidBody.yVel += totalYVel * yMult * ((totalMass - ridgidBody.mass) / totalMass); otherRidgidBody.yVel -= totalYVel * ((totalMass - otherRidgidBody.mass) / totalMass) * (yMult + (Math.abs(yMult) + (ridgidBody.bounciness * otherRidgidBody.bounciness)));
otherRidgidBody.xVel -= totalXVel * xMult * ((totalMass - otherRidgidBody.mass) / totalMass);
otherRidgidBody.yVel -= totalYVel * yMult * ((totalMass - otherRidgidBody.mass) / totalMass);
} }
else{ else{
ridgidBody.xVel += totalXVel * xMult; double newXVel = totalXVel * (xMult * (Math.abs(xMult) + ridgidBody.bounciness));
ridgidBody.yVel += totalYVel * yMult; double newYVel = totalYVel * (yMult * (Math.abs(yMult) + ridgidBody.bounciness));
ridgidBody.xVel += newXVel;
ridgidBody.yVel += newYVel;
} }
Object grav = gameEngine.getComponentData(entity, Gravity.class); Object grav = gameEngine.getComponentData(entity, Gravity.class);
if (grav != null && otherRidgidBody.mass < 0) { if (grav != null && otherRidgidBody.mass < 0) {
@ -231,6 +229,7 @@ public class CollisionSystem extends ECSSystem {
} }
} }
} }
//processed.add(entity); // Add this entity to the already processed ones
} }
} }

17
demo2/.editorconfig Normal file
View File

@ -0,0 +1,17 @@
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 80
[*.sh]
end_of_line = lf
[*.java]
indent_size = 4
max_line_length = 120

2
demo2/.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# When shell scripts end in CRLF, bash gives a cryptic error message
*.sh text eol=lf

28
demo2/.gitignore vendored Normal file
View File

@ -0,0 +1,28 @@
#
# Standard Maven .gitignore
#
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
#
# IntelliJ
#
*.iml
.idea/*
!.idea/runConfigurations/
#
# Visual Studio Code
#
.settings/
.classpath
.factorypath
.project
.vscode/

4
demo2/.travis.yml Normal file
View File

@ -0,0 +1,4 @@
language: java
jdk: openjdk8
after_success:
- mvn coveralls:report

195
demo2/pom.xml Normal file
View File

@ -0,0 +1,195 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nz.ac.massey.javaecs.examples</groupId>
<artifactId>demo2</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.6.0</junit.version>
<maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
<maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
<checkstyle.version>8.29</checkstyle.version>
<checkstyle-rules.version>4.0.1</checkstyle-rules.version>
<maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
<jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
<coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
<!-- JaCoCo thresholds. Increase gradually as you add tests. -->
<jacoco.unit-tests.limit.instruction-ratio>0%</jacoco.unit-tests.limit.instruction-ratio>
<jacoco.unit-tests.limit.branch-ratio>0%</jacoco.unit-tests.limit.branch-ratio>
<jacoco.unit-tests.limit.class-complexity>20</jacoco.unit-tests.limit.class-complexity>
<jacoco.unit-tests.limit.method-complexity>5</jacoco.unit-tests.limit.method-complexity>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven-enforcer-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.6.3</version>
</requireMavenVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
<dependency>
<groupId>com.github.ngeor</groupId>
<artifactId>checkstyle-rules</artifactId>
<version>${checkstyle-rules.version}</version>
</dependency>
</dependencies>
<configuration>
<configLocation>com/github/ngeor/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<skip>${skipTests}</skip>
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>check-unit-test</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.unit-tests.limit.instruction-ratio}</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.unit-tests.limit.branch-ratio}</minimum>
</limit>
</limits>
</rule>
<rule>
<element>CLASS</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>TOTALCOUNT</value>
<maximum>${jacoco.unit-tests.limit.class-complexity}</maximum>
</limit>
</limits>
</rule>
<rule>
<element>METHOD</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>TOTALCOUNT</value>
<maximum>${jacoco.unit-tests.limit.method-complexity}</maximum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
</plugin>
</plugins>
</reporting>
<profiles>
<!-- Publish coverage report to Coveralls, only when running in Travis. -->
<profile>
<id>travis</id>
<activation>
<property>
<name>env.TRAVIS</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${coveralls-maven-plugin.version}</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -0,0 +1,17 @@
package nz.ac.massey.javaecs.examples;
/**
* Hello world!
*/
public final class App {
private App() {
}
/**
* Says hello to the world.
* @param args The arguments of the program.
*/
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@ -0,0 +1,18 @@
package nz.ac.massey.javaecs.examples;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Unit test for simple App.
*/
class AppTest {
/**
* Rigorous Test.
*/
@Test
void testApp() {
assertEquals(1, 1);
}
}

View File

@ -18,7 +18,12 @@ public final class App {
*/ */
public static void main(String[] args) { public static void main(String[] args) {
int nEntities = 1_000_000; int nEntities = 1_000_000;
double startTime = System.nanoTime();
Engine engine = new Engine(nEntities); 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(ComflabulationComponent.class);
engine.registerComponent(DirectionComponent.class); engine.registerComponent(DirectionComponent.class);
@ -29,7 +34,9 @@ public final class App {
MovementSystem movementSystem = new MovementSystem(engine); MovementSystem movementSystem = new MovementSystem(engine);
engine.registerSystem(MovementSystem.class, movementSystem); engine.registerSystem(MovementSystem.class, movementSystem);
double startTime = System.nanoTime();
startTime = System.nanoTime();
for (int i = 0; i < nEntities; i++) { for (int i = 0; i < nEntities; i++) {
Entity entity = engine.createEntity(); Entity entity = engine.createEntity();
engine.addComponent(entity, PositionComponent.class, new PositionComponent()); engine.addComponent(entity, PositionComponent.class, new PositionComponent());
@ -39,17 +46,17 @@ public final class App {
engine.addComponent(entity, ComflabulationComponent.class, new ComflabulationComponent()); 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(); startTime = System.nanoTime();
movementSystem.update(dt); movementSystem.update(dt);
comflabSystem.update(dt); comflabSystem.update(dt);
endTime = System.nanoTime(); 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!"); System.out.println("Hello World!");
} }

View File

@ -1,12 +1,12 @@
package nz.ac.massey.javaecs.examples.Components; package nz.ac.massey.javaecs.examples.Components;
public class ComflabulationComponent { public class ComflabulationComponent {
public Float thingy; public double thingy;
public Integer dingy; public int dingy;
public boolean mingy; public boolean mingy;
public String stringy; 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.thingy = thingy;
this.dingy = dingy; this.dingy = dingy;
this.mingy = mingy; this.mingy = mingy;

View File

@ -1,10 +1,10 @@
package nz.ac.massey.javaecs.examples.Components; package nz.ac.massey.javaecs.examples.Components;
public class DirectionComponent { public class DirectionComponent {
public Float x; public double x;
public Float y; public double y;
public DirectionComponent(Float x, Float y){ public DirectionComponent(double x, double y){
this.x = x; this.x = x;
this.y = y; this.y = y;
} }

View File

@ -1,10 +1,10 @@
package nz.ac.massey.javaecs.examples.Components; package nz.ac.massey.javaecs.examples.Components;
public class PositionComponent { public class PositionComponent {
public Float x; public double x;
public Float y; public double y;
public PositionComponent(Float x, Float y){ public PositionComponent(double x, double y){
this.x = x; this.x = x;
this.y = y; this.y = y;
} }

View File

@ -26,10 +26,10 @@ public class ComflabSystem extends ECSSystem {
public void update() { public void update() {
} }
public void update(Float dt) { public void update(double dt) {
for (Entity entity : entities) { for (Entity entity : entities) {
ComflabulationComponent comflab = (ComflabulationComponent)ecs.getComponentData(entity, ComflabulationComponent.class); ComflabulationComponent comflab = (ComflabulationComponent)ecs.getComponentData(entity, ComflabulationComponent.class);
comflab.thingy *= 1.000001f; comflab.thingy *= 1.000001;
comflab.mingy = !comflab.mingy; comflab.mingy = !comflab.mingy;
comflab.dingy++; comflab.dingy++;
} }

View File

@ -29,7 +29,7 @@ public class MovementSystem extends ECSSystem {
public void update() { public void update() {
} }
public void update(Float dt) { public void update(double dt) {
for (Entity entity : entities) { for (Entity entity : entities) {
PositionComponent position = (PositionComponent)ecs.getComponentData(entity, PositionComponent.class); PositionComponent position = (PositionComponent)ecs.getComponentData(entity, PositionComponent.class);
DirectionComponent direction = (DirectionComponent)ecs.getComponentData(entity, DirectionComponent.class); DirectionComponent direction = (DirectionComponent)ecs.getComponentData(entity, DirectionComponent.class);