Updated examples to the latest version

For release, used in the report/presentation
This commit is contained in:
Brychan Dempsey 2021-06-15 18:13:49 +12:00
parent 3c45ca9de8
commit 05c57efc52
14 changed files with 95 additions and 268 deletions

2
demo1/.gitignore vendored
View File

@ -26,3 +26,5 @@ buildNumber.properties
.factorypath .factorypath
.project .project
.vscode/ .vscode/
*.jar

View File

@ -19,8 +19,8 @@
<!-- JaCoCo thresholds. Increase gradually as you add tests. --> <!-- 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.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.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.class-complexity>2100</jacoco.unit-tests.limit.class-complexity>
<jacoco.unit-tests.limit.method-complexity>5</jacoco.unit-tests.limit.method-complexity> <jacoco.unit-tests.limit.method-complexity>1000</jacoco.unit-tests.limit.method-complexity>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
@ -38,12 +38,12 @@
<dependency> <dependency>
<groupId>nz.ac.massey.javaecs</groupId> <groupId>nz.ac.massey.javaecs</groupId>
<artifactId>javaecs</artifactId> <artifactId>javaecs</artifactId>
<version>0.9.9-RELEASE_CANDIDATE</version> <version>1.0.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <!-- <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId> <artifactId>maven-enforcer-plugin</artifactId>
<version>${maven-enforcer-plugin.version}</version> <version>${maven-enforcer-plugin.version}</version>
@ -93,8 +93,8 @@
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin> -->
<plugin> <!--<plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version> <version>${maven-surefire-plugin.version}</version>
@ -165,7 +165,7 @@
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin> -->
</plugins> </plugins>
</build> </build>
<reporting> <reporting>
@ -179,7 +179,7 @@
</reporting> </reporting>
<profiles> <profiles>
<!-- Publish coverage report to Coveralls, only when running in Travis. --> <!-- Publish coverage report to Coveralls, only when running in Travis. -->
<profile> <!-- <profile>
<id>travis</id> <id>travis</id>
<activation> <activation>
<property> <property>
@ -195,6 +195,6 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</profile> </profile> -->
</profiles> </profiles>
</project> </project>

View File

@ -55,7 +55,7 @@ public final class App {
LogUpdateSystem logUpdateSystem = new LogUpdateSystem(gameEngine); LogUpdateSystem logUpdateSystem = new LogUpdateSystem(gameEngine);
gameEngine.registerSystem(LogUpdateSystem.class, logUpdateSystem); gameEngine.registerSystem(LogUpdateSystem.class, logUpdateSystem);
RenderSystem renderSystem = new RenderSystem(gameEngine, 10.); RenderSystem renderSystem = new RenderSystem(gameEngine, 5.);
gameEngine.registerSystem(RenderSystem.class, renderSystem); gameEngine.registerSystem(RenderSystem.class, renderSystem);
ExistenceSystem existenceSystem = new ExistenceSystem(gameEngine); ExistenceSystem existenceSystem = new ExistenceSystem(gameEngine);
@ -114,7 +114,7 @@ public final class App {
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();
@ -125,7 +125,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 **
@ -146,6 +146,7 @@ public final class App {
double frameRate = 1.0 / 144; // 1 second divided by target number of frames double frameRate = 1.0 / 144; // 1 second divided by target number of frames
boolean exit = false; boolean exit = false;
Thread.sleep(5000);
long startTime = System.nanoTime(); long startTime = System.nanoTime();
while (!exit){ while (!exit){
// Run system updates // Run system updates

View File

@ -1,14 +1,11 @@
package nz.ac.massey.javaecs.examples.Systems; package nz.ac.massey.javaecs.examples.Systems;
import java.util.BitSet; import java.util.BitSet;
import java.util.HashSet;
import java.util.Set;
import nz.ac.massey.javaecs.ECSSystem; import nz.ac.massey.javaecs.ECSSystem;
import nz.ac.massey.javaecs.Engine; import nz.ac.massey.javaecs.Engine;
import nz.ac.massey.javaecs.Entity; import nz.ac.massey.javaecs.Entity;
import nz.ac.massey.javaecs.examples.Components.Collider; import nz.ac.massey.javaecs.examples.Components.Collider;
import nz.ac.massey.javaecs.examples.Components.Gravity;
import nz.ac.massey.javaecs.examples.Components.RidgidBody; import nz.ac.massey.javaecs.examples.Components.RidgidBody;
import nz.ac.massey.javaecs.examples.Components.Vec2D; import nz.ac.massey.javaecs.examples.Components.Vec2D;
@ -28,14 +25,13 @@ public class CollisionSystem extends ECSSystem {
public void init() { public void init() {
} }
// This is a quick & naive physics implementation. Not all collision states are accurately calculated | I'm pretty sure one of the states is set wrong, and sends things flying in the wrong direction // This is a quick & naive physics implementation.
// I also expect it is highly inefficient, though it is able to run it with 500 subscribed entities // I expect it is highly inefficient, though it is able to run it with 500
// subscribed entities
// with no major performance issues // with no major performance issues
// Replace this with a proper system as required - I.e. Box2D or etc. // Replace this with a proper system as required - I.e. Box2D or etc.
@Override @Override
public void update(double dt) { public void update(double dt) {
Set<Entity> processed = new HashSet<>();
// Gets all items we have collided with
for (Entity entity : entities) { for (Entity entity : entities) {
Vec2D pos = (Vec2D) gameEngine.getComponentData(entity, Vec2D.class); Vec2D pos = (Vec2D) gameEngine.getComponentData(entity, Vec2D.class);
RidgidBody ridgidBody = (RidgidBody) gameEngine.getComponentData(entity, RidgidBody.class); RidgidBody ridgidBody = (RidgidBody) gameEngine.getComponentData(entity, RidgidBody.class);
@ -43,30 +39,25 @@ public class CollisionSystem extends ECSSystem {
if (ridgidBody.mass >= 0) { if (ridgidBody.mass >= 0) {
// Only ignore non-static colliders // Only ignore non-static colliders
for (Entity entity2 : entities) { for (Entity entity2 : entities) {
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, RidgidBody.class);
RidgidBody.class);
Collider otherCollider = (Collider) gameEngine.getComponentData(entity2, Collider.class); Collider otherCollider = (Collider) gameEngine.getComponentData(entity2, Collider.class);
if (ridgidBody.mass >= 0 || otherRidgidBody.mass >= 0) { if (otherRidgidBody.mass < 0) {
// Evaluate a collision in the top-left // Evaluate a collision in the top-left
boolean tlCollide = pos.x > otherPos.x && pos.x < otherPos.x + otherCollider.x boolean tlCollide = pos.x > otherPos.x && pos.x < otherPos.x + otherCollider.x
&& pos.y > otherPos.y && pos.y < otherPos.y + otherCollider.y; && pos.y > otherPos.y && pos.y < otherPos.y + otherCollider.y;
// Evaluate a collision in the bottom-left // Evaluate a collision in the bottom-left
boolean blCollide = pos.x > otherPos.x && pos.x < otherPos.x + otherCollider.x boolean blCollide = pos.x > otherPos.x && pos.x < otherPos.x + otherCollider.x
&& pos.y + collider.y > otherPos.y && pos.y + collider.y > otherPos.y && pos.y + collider.y < otherPos.y + otherCollider.y;
&& pos.y + collider.y < otherPos.y + otherCollider.y;
// Evaluate a collision in the bottom-right // Evaluate a collision in the bottom-right
boolean brCollide = pos.x + collider.x > otherPos.x boolean brCollide = pos.x + collider.x > otherPos.x
&& pos.x + collider.x < otherPos.x + otherCollider.x && pos.x + collider.x < otherPos.x + otherCollider.x && pos.y + collider.y > otherPos.y
&& pos.y + collider.y > otherPos.y
&& pos.y + collider.y < otherPos.y + otherCollider.y; && pos.y + collider.y < otherPos.y + otherCollider.y;
// Evaluate a collision in the top-right // Evaluate a collision in the top-right
boolean trCollide = pos.x + collider.x > otherPos.x boolean trCollide = pos.x + collider.x > otherPos.x
&& pos.x + collider.x < otherPos.x + otherCollider.x && pos.x + collider.x < otherPos.x + otherCollider.x && pos.y > otherPos.y
&& pos.y > otherPos.y
&& pos.y < otherPos.y + otherCollider.y; && pos.y < otherPos.y + otherCollider.y;
if (tlCollide || blCollide || brCollide || trCollide) { if (tlCollide || blCollide || brCollide || trCollide) {
// Get the vels // Get the vels
@ -74,166 +65,39 @@ 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; // reflect a force back 100%, (srtabilises) then add any extra in bounce double multTot = 1;
double totalMass = ridgidBody.mass + otherRidgidBody.mass;
boolean fullEdge = false; boolean fullEdge = false;
// left-hand collision // left-hand collision
if (tlCollide && blCollide) { if (tlCollide && blCollide) {
fullEdge = true; fullEdge = true;
pos.x = otherPos.x + otherCollider.x - .00001; pos.x = otherPos.x + otherCollider.x;
xMult = multTot; xMult = multTot;
} }
// right-hand collision // right-hand collision
else if (brCollide && trCollide) { else if (brCollide && trCollide) {
fullEdge = true; fullEdge = true;
pos.x = otherPos.x - collider.x + .00001; pos.x = otherPos.x - collider.x;
xMult = -multTot; xMult = -multTot;
} }
// Bottom collision // Bottom collision
else 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 + .00001; pos.y = otherPos.y - collider.y;
yMult = -multTot; yMult = -multTot;
} }
// top collision // top collision
else if (trCollide && tlCollide) { else if (trCollide && tlCollide) {
fullEdge = true; fullEdge = true;
//pos.y = otherPos.y - collider.y; // pos.y = otherPos.y - collider.y;
pos.y = otherPos.y + otherCollider.y -.00001; pos.y = otherPos.y + otherCollider.y;
yMult = multTot; yMult = multTot;
} }
if(!fullEdge){
// Not a full edge collision, must evaluate which edge it is (it then gets treated as a full edge)
double deltaXVel = Math.abs(ridgidBody.xVel - otherRidgidBody.xVel);
double deltaYVel = Math.abs(ridgidBody.yVel - otherRidgidBody.yVel);
double deltaMin = 50.;
double incidentThreshold = 0; // 10% of the sum of the velocity
if (trCollide){
fullEdge = true;
// use the ratio i.e. the angle
// There are 3 cases, the incident angle is less than 45
// The incident angle is more than 45
// The incident angle is near 0 or 90
if(deltaXVel < incidentThreshold || deltaYVel < incidentThreshold){
// must use cover calc, as it is near stationary
if (otherPos.y - (pos.y + collider.y) >= otherPos.x - (pos.x + collider.x)){
// vertical cover wins
yMult = multTot;
}
else{
xMult = -multTot;
}
}
else if (deltaYVel > deltaXVel){
// Top edge
//if (deltaYVel > deltaMin) pos.y = otherPos.y + otherCollider.y;
yMult = multTot;
}
else{
//if (deltaXVel > deltaMin) pos.x = otherPos.x + collider.x;
xMult = -multTot;
}
}
else if (brCollide){
fullEdge = true;
if(deltaXVel < incidentThreshold || deltaYVel < incidentThreshold){
// must use cover calc, as it is near stationary
if (pos.y - (otherPos.y + otherCollider.y) >= otherPos.x - (pos.x + collider.x)){
// vertical cover wins
yMult = -multTot;
}
else{
xMult = -multTot;
}
}
else if (deltaYVel < deltaXVel){
//pos.y = otherPos.y + otherCollider.y;
//if (deltaYVel > deltaMin) pos.y = otherPos.y - collider.y;
yMult = -multTot;
}
else{
//if (deltaXVel > deltaMin) pos.x = otherPos.x - collider.x;
xMult = -multTot;
}
}
else if (blCollide){
fullEdge = true;
if(deltaXVel < incidentThreshold || deltaYVel < incidentThreshold){
// must use cover calc, as it is near stationary
if (pos.y - (otherPos.y + otherCollider.y) >= pos.x - (otherPos.x + otherCollider.x)){
// vertical cover wins
yMult = -multTot;
}
else{
xMult = multTot;
}
}
else if (deltaYVel > deltaXVel){
//if (deltaYVel > deltaMin) pos.y = otherPos.y - collider.y;
yMult = -multTot;
}
else{
//if (deltaXVel > deltaMin) pos.x = otherPos.x + otherCollider.x;
xMult = multTot;
}
}
else{ // top left
fullEdge = true;
if(deltaXVel < incidentThreshold || deltaYVel < incidentThreshold){
// must use cover calc, as it is near stationary
if (otherPos.y - (pos.y + collider.y) >= pos.x - (otherPos.x + otherCollider.x)){
// vertical cover wins
yMult = multTot;
}
else{
xMult = multTot;
}
}
else if (deltaYVel > deltaXVel){
//if (deltaYVel > deltaMin) pos.y = otherPos.y +otherCollider.y;
yMult = multTot;
}
else {
//if (deltaXVel > deltaMin) pos.x = otherPos.x + otherCollider.x;
xMult = multTot;
}
}
}
if (fullEdge) { if (fullEdge) {
// Finally, actuate the calculation double newXVel = totalXVel * (xMult
// entity 2 is immovable; full acceleration applied to the current entity * (Math.abs(xMult) + (ridgidBody.bounciness * otherRidgidBody.bounciness)));
double newYVel = totalYVel * (yMult
if (otherRidgidBody.mass >= 0){ * (Math.abs(yMult) + (ridgidBody.bounciness * otherRidgidBody.bounciness)));
// For collisions between dynamic objects, the restoring velocity [rv] is shared between both objects.
// Each object experiences a restoring velocity proportionate to its percentage of the total mass.
// They each recieve an additional force of 'bounce',
// which is the total velocity * total bounciness
// This force is then shared by the mass
double rvX1 = totalXVel * ((totalMass - ridgidBody.mass) / totalMass) * xMult;
double rvY1 = totalYVel * ((totalMass - ridgidBody.mass) / totalMass) * yMult;
double totalBounce = ridgidBody.bounciness * otherRidgidBody.bounciness;
// Restoring forces
ridgidBody.xVel += rvX1;
ridgidBody.yVel += rvY1;
// Additional forces; 'bounce'
double xBounce = rvX1 * ((totalBounce - ridgidBody.bounciness) / totalBounce);
double yBounce = rvY1 * ((totalBounce - ridgidBody.bounciness) / totalBounce);
rvX1 = xBounce * ((totalMass - ridgidBody.mass) / totalMass);// * xMult;
rvY1 = yBounce * ((totalMass - ridgidBody.mass) / totalMass);// * yMult;
// bounce forces
ridgidBody.xVel += rvX1;
ridgidBody.yVel += rvY1;
}
else{
// For collisions against a fixed object, the restoring velocity (velocity in the direction against the collision vector) [name it 'rv']
// is at least -1x. This would affix the cardinal velocity to zero, both objects would have a 'bounciness' of zero.
// The bounciness is combined (b = object1 * object2), which gives us the total percent of retained velocity,
// i.e. a factor >= 0 & <= 1. Multiply this factor by rv to get the total restoring velocity
double newXVel = totalXVel * (xMult * (Math.abs(xMult) + (ridgidBody.bounciness * otherRidgidBody.bounciness)));
double newYVel = totalYVel * (yMult * (Math.abs(yMult) + (ridgidBody.bounciness * otherRidgidBody.bounciness)));
ridgidBody.xVel += newXVel; ridgidBody.xVel += newXVel;
ridgidBody.yVel += newYVel; ridgidBody.yVel += newYVel;
} }
@ -242,32 +106,5 @@ public class CollisionSystem extends ECSSystem {
} }
} }
} }
//processed.add(entity); // Add this entity to the already processed ones
} }
}
}
/**
* Zero degrees is straight up, 90 east -90 (270) = west 180 south
*
* @param xVel
* @param yVel
* @return
*/
public static double calcAngle(double xVel, double yVel) {
if (xVel == 0) { // Div zero; = +- 90
return yVel < 0 ? 270 : 90;
} else if (xVel < 0 && yVel < 0) { // bottom-left quad (180 - 270)
return 180. + Math.tanh(yVel / xVel);
} else if (xVel < 0) { // Top left quad (270 - 360)
return 360 - Math.tanh(yVel / xVel);
} else if (yVel < 0) {
return 180 - Math.tanh(yVel / xVel);
} else {
return Math.tanh(yVel / xVel);
}
}
} }

View File

@ -25,8 +25,8 @@ public class RenderSystem extends ECSSystem{
Engine gameEngine; Engine gameEngine;
Thread renderThread; Thread renderThread;
double renderScale; double renderScale;
int screenX = 1024; int screenX = 512;
int screenY = 1024; int screenY = 512;
public RenderSystem(Engine gameEngine, double renderScale){ public RenderSystem(Engine gameEngine, double renderScale){
this.gameEngine = gameEngine; this.gameEngine = gameEngine;
@ -46,6 +46,7 @@ public class RenderSystem extends ECSSystem{
@Override @Override
public void update(double dt) { public void update(double dt) {
// This approach needs reconsidering, as it creates an excessive amount of objects that
Group renderScene = new Group(); Group renderScene = new Group();
for (Entity entity : entities) { for (Entity entity : entities) {
if (((Render)gameEngine.getComponentData(entity, Render.class)).renderType == BoxRender.class){ if (((Render)gameEngine.getComponentData(entity, Render.class)).renderType == BoxRender.class){
@ -54,8 +55,8 @@ public class RenderSystem extends ECSSystem{
Rectangle rect = new Rectangle(box.xSize* renderScale, box.ySize * renderScale); Rectangle rect = new Rectangle(box.xSize* renderScale, box.ySize * renderScale);
rect.setFill(new Color(box.r, box.g, box.b, box.a)); rect.setFill(new Color(box.r, box.g, box.b, box.a));
rect.setX(12 + (vec2d.x * renderScale)); rect.setX(6 + (vec2d.x * renderScale));
rect.setY(1012 - (vec2d.y * renderScale) - rect.getHeight()); rect.setY(506 - (vec2d.y * renderScale) - rect.getHeight());
renderScene.getChildren().add(rect); renderScene.getChildren().add(rect);
} }
else if (((Render)gameEngine.getComponentData(entity, Render.class)).renderType == TextRender.class){ else if (((Render)gameEngine.getComponentData(entity, Render.class)).renderType == TextRender.class){
@ -100,7 +101,7 @@ public class RenderSystem extends ECSSystem{
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
// based on the colorful circles sample at https://docs.oracle.com/javase/8/javafx/get-started-tutorial/animation.htm // based on the colorful circles sample at https://docs.oracle.com/javase/8/javafx/get-started-tutorial/animation.htm
root = new Group(); root = new Group();
Scene scene = new Scene(root, 1024, 1024, Color.BLACK); Scene scene = new Scene(root, 512, 512, Color.BLACK);
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.show(); primaryStage.show();
// Signal the renderer is ready // Signal the renderer is ready

View File

@ -38,7 +38,7 @@
<dependency> <dependency>
<groupId>nz.ac.massey.javaecs</groupId> <groupId>nz.ac.massey.javaecs</groupId>
<artifactId>javaecs</artifactId> <artifactId>javaecs</artifactId>
<version>0.9.9-RELEASE_CANDIDATE</version> <version>1.0.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -56,7 +56,7 @@ public class App {
ControlSystem controlSystem = new ControlSystem(gameEngine); ControlSystem controlSystem = new ControlSystem(gameEngine);
gameEngine.registerSystem(ControlSystem.class, controlSystem); gameEngine.registerSystem(ControlSystem.class, controlSystem);
RenderSystem renderSystem = new RenderSystem(gameEngine, 10.); RenderSystem renderSystem = new RenderSystem(gameEngine, 5.);
gameEngine.registerSystem(RenderSystem.class, renderSystem); gameEngine.registerSystem(RenderSystem.class, renderSystem);
PlayerSystem playerSystem = new PlayerSystem(gameEngine); PlayerSystem playerSystem = new PlayerSystem(gameEngine);
@ -100,7 +100,6 @@ public class App {
boolean exit = false; boolean exit = false;
long startTime = System.nanoTime(); long startTime = System.nanoTime();
int state = 0;
while (!exit){ while (!exit){
// Run system updates // Run system updates

View File

@ -15,7 +15,7 @@ public class JFXView extends Application {
primaryStage.setTitle("JavaECS Demo 2"); primaryStage.setTitle("JavaECS Demo 2");
App.worldGroup = new Group(); App.worldGroup = new Group();
App.worldStage = primaryStage; App.worldStage = primaryStage;
Scene scene = new Scene(App.worldGroup, 1024, 1024, Color.BLACK); Scene scene = new Scene(App.worldGroup, 512, 512, Color.BLACK);
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.show(); primaryStage.show();
// Notifiy that the renderer is ready // Notifiy that the renderer is ready

View File

@ -9,9 +9,7 @@ import javafx.stage.Stage;
import nz.ac.massey.javaecs.ECSSystem; import nz.ac.massey.javaecs.ECSSystem;
import nz.ac.massey.javaecs.Engine; import nz.ac.massey.javaecs.Engine;
import nz.ac.massey.javaecs.Entity; import nz.ac.massey.javaecs.Entity;
import nz.ac.massey.javaecs.examples.Components.Control;
import nz.ac.massey.javaecs.examples.Components.Input; import nz.ac.massey.javaecs.examples.Components.Input;
import nz.ac.massey.javaecs.examples.Components.Render;
/** /**

View File

@ -2,18 +2,12 @@ package nz.ac.massey.javaecs.examples.Systems;
import java.util.BitSet; import java.util.BitSet;
import javafx.application.Application;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import nz.ac.massey.javaecs.ECSSystem; import nz.ac.massey.javaecs.ECSSystem;
import nz.ac.massey.javaecs.Engine; import nz.ac.massey.javaecs.Engine;
import nz.ac.massey.javaecs.Entity; import nz.ac.massey.javaecs.Entity;
import nz.ac.massey.javaecs.examples.Components.Control;
import nz.ac.massey.javaecs.examples.Components.Input;
import nz.ac.massey.javaecs.examples.Components.Render; import nz.ac.massey.javaecs.examples.Components.Render;
import nz.ac.massey.javaecs.examples.Components.Sprite; import nz.ac.massey.javaecs.examples.Components.Sprite;
import nz.ac.massey.javaecs.examples.Components.Vec2D; import nz.ac.massey.javaecs.examples.Components.Vec2D;
@ -25,8 +19,8 @@ public class RenderSystem extends ECSSystem {
Group renderGroup; Group renderGroup;
Thread renderThread; Thread renderThread;
double renderScale; double renderScale;
int screenX = 1024; int screenX = 512;
int screenY = 1024; int screenY = 512;
public RenderSystem(Engine gameEngine, double renderScale){ public RenderSystem(Engine gameEngine, double renderScale){
this.gameEngine = gameEngine; this.gameEngine = gameEngine;

View File

@ -38,7 +38,7 @@
<dependency> <dependency>
<groupId>nz.ac.massey.javaecs</groupId> <groupId>nz.ac.massey.javaecs</groupId>
<artifactId>javaecs</artifactId> <artifactId>javaecs</artifactId>
<version>0.9.2-PRERELEASE</version> <version>1.0.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -15,8 +15,9 @@ public final class App {
/** /**
* Says hello to the world. * Says hello to the world.
* @param args The arguments of the program. * @param args The arguments of the program.
* @throws InterruptedException
*/ */
public static void main(String[] args) { public static void main(String[] args) throws InterruptedException {
int nEntities = 1_000_000; int nEntities = 1_000_000;
double startTime = System.nanoTime(); double startTime = System.nanoTime();
Engine engine = new Engine(nEntities); Engine engine = new Engine(nEntities);
@ -41,15 +42,16 @@ public final class App {
Entity entity = engine.createEntity(); Entity entity = engine.createEntity();
engine.addComponent(entity, PositionComponent.class, new PositionComponent()); engine.addComponent(entity, PositionComponent.class, new PositionComponent());
engine.addComponent(entity, DirectionComponent.class, new DirectionComponent()); engine.addComponent(entity, DirectionComponent.class, new DirectionComponent());
if (i % 2 != 0){ if (i % 2 != 0){
engine.addComponent(entity, ComflabulationComponent.class, new ComflabulationComponent()); engine.addComponent(entity, ComflabulationComponent.class, new ComflabulationComponent());
} }
} }
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 )");
// Delay as object creation is multithreaded in at least OpenJDK 1.8 - lets use see the single core performance
Thread.sleep(5000);
double dt = 1.0f/60.0f; double dt = 1.0f/60.0f;
startTime = System.nanoTime(); startTime = System.nanoTime();
movementSystem.update(dt); movementSystem.update(dt);

View File

@ -23,9 +23,6 @@ public class ComflabSystem extends ECSSystem {
} }
@Override @Override
public void update() {
}
public void update(double 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);

View File

@ -1,6 +1,5 @@
package nz.ac.massey.javaecs.examples.Systems; package nz.ac.massey.javaecs.examples.Systems;
import java.lang.management.ThreadInfo;
import java.util.BitSet; import java.util.BitSet;
import nz.ac.massey.javaecs.ECSSystem; import nz.ac.massey.javaecs.ECSSystem;
@ -26,9 +25,6 @@ public class MovementSystem extends ECSSystem {
} }
@Override @Override
public void update() {
}
public void update(double 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);