Removed implementation classes

Leaves only the framework in the compiled clause.
Find the removed files in ../examples/misc/
This commit is contained in:
2021-06-08 14:47:10 +12:00
parent 7524a0096a
commit b1efb9802d
7 changed files with 0 additions and 0 deletions
+91
View File
@@ -0,0 +1,91 @@
package nz.ac.massey.javaecs;
import java.util.BitSet;
/**
* Hello world!
*/
public final class App {
private App() {
}
/**
* Says hello to the world.
* @param args The arguments of the program.
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
ECS gameEngine = new ECS();
System.out.println("Hello World!");
gameEngine.registerComponent(Vec2D.class);
gameEngine.registerComponent(RidgidBody.class);
gameEngine.registerComponent(Gravity.class);
PhysicsSystem physicsSystem = new PhysicsSystem(gameEngine);
gameEngine.registerSystem(PhysicsSystem.class, physicsSystem);
{
BitSet signature = new BitSet();
signature.set(gameEngine.getComponentIndex(Gravity.class));
signature.set(gameEngine.getComponentIndex(Vec2D.class));
signature.set(gameEngine.getComponentIndex(RidgidBody.class));
gameEngine.setSystemSignature(PhysicsSystem.class, signature);
}
physicsSystem.init();
LogVec2DSystem logVec2DSystem = new LogVec2DSystem(gameEngine);
gameEngine.registerSystem(LogVec2DSystem.class, logVec2DSystem);
{
BitSet signature = new BitSet();
signature.set(gameEngine.getComponentIndex(Gravity.class));
signature.set(gameEngine.getComponentIndex(Vec2D.class));
signature.set(gameEngine.getComponentIndex(RidgidBody.class));
gameEngine.setSystemSignature(LogVec2DSystem.class, signature);
}
logVec2DSystem.init();
FrameRateSystem frameRateSystem = new FrameRateSystem();
gameEngine.registerSystem(FrameRateSystem.class, frameRateSystem);
// Create components:
int entity = gameEngine.createEntity();
gameEngine.addComponent(entity, Gravity.class, new Gravity(0.0, -9.80665, -1.0, 100.0));
gameEngine.addComponent(entity, Vec2D.class, new Vec2D(1.5, 0.0, 1));
gameEngine.addComponent(entity, RidgidBody.class, new RidgidBody());
double dt = 0.0;
double frameRate = 1.0 / 20; // 1 second divided by target number of frames
double idleTime = 0.0; // the amount of time spent sleeping
boolean quit = false;
long loopStart = System.currentTimeMillis();
long startTime = System.nanoTime();
// One potential way to do this
while (!quit){
// Get the time between frames for accurate time-based calculations (i.e. physics systems etc)
frameRateSystem.update(dt, idleTime);
physicsSystem.update(dt);
logVec2DSystem.update(dt);
dt = (System.nanoTime() - startTime) / 1e9; // convert nanoseconds to seconds
startTime = System.nanoTime();
// Limit frame rate (approximately) to minimum of 16 ms
if (dt < frameRate){
idleTime = frameRate-dt;
Thread.sleep((int)((frameRate-dt)*1000));
dt = (System.nanoTime() - startTime) / 1e9;
startTime = System.nanoTime();
}
if (System.currentTimeMillis() - loopStart >= 1000){
loopStart = System.currentTimeMillis();
System.out.println("Second Elapsed");
}
}
}
}
+15
View File
@@ -0,0 +1,15 @@
package nz.ac.massey.javaecs;
public class FrameRateSystem extends ECSSystem{
@Override
void init() {}
@Override
void update() {}
void update(double dt, double idleTime){
System.out.print(String.format("dt: %.3g (%.3g idle) ", dt, idleTime));
}
}
+23
View File
@@ -0,0 +1,23 @@
package nz.ac.massey.javaecs;
public class Gravity {
public Gravity(){
}
public Gravity(double x, double y){
this.x = x;
this.y = y;
}
public Gravity(double x, double y, double terminalX, double terminalY){
this.x = x;
this.y = y;
this.terminalX = terminalX;
this.terminalY = terminalY;
}
double x = 0.0;
double y = -9.80665; // Force of gravity (from https://www.bipm.org/en/publications/si-brochure - 9th edition - p159 - Bureau International des Poids et Mesures - CC BY 4.0)
// Gravity won't be considered if the velocity exceeds this (absolute value). Negative values are ignored (not limited)
double terminalX = -1.0;
double terminalY = -1.0;
}
+23
View File
@@ -0,0 +1,23 @@
package nz.ac.massey.javaecs;
public class LogVec2DSystem extends ECSSystem{
ECS gameEngine;
public LogVec2DSystem(ECS gameEngine){
this.gameEngine = gameEngine;
}
@Override
void init() {}
@Override
void update() {}
void update(double dt){
for (Integer entity : entities) {
Vec2D pos = (Vec2D)gameEngine.getComponentData(entity, Vec2D.class);
System.out.println(String.format("X: %.6g, Y: %.6g", pos.x, pos.y));
}
}
}
+37
View File
@@ -0,0 +1,37 @@
package nz.ac.massey.javaecs;
public class PhysicsSystem extends ECSSystem{
ECS gameEngine;
public PhysicsSystem(ECS gameEngine){
this.gameEngine = gameEngine;
}
@Override
void init() {}
@Override
void update() {}
void update(Double dt){
for (Integer entity : entities) {
Vec2D pos = (Vec2D)gameEngine.getComponentData(entity, Vec2D.class);
RidgidBody ridgidBody = (RidgidBody)gameEngine.getComponentData(entity, RidgidBody.class);
Gravity gravity = (Gravity)gameEngine.getComponentData(entity, Gravity.class);
// Firstly, add the result of the accelerative forces to the ridgidbody
ridgidBody.xdot += ridgidBody.xAcc * dt;
ridgidBody.ydot += ridgidBody.yAcc * dt;
// Special case of gravity
if (gravity.terminalX < 0 || Math.abs(ridgidBody.xdot) < gravity.terminalX){
ridgidBody.xdot += gravity.x * dt;
}
if (gravity.terminalY < 0 || Math.abs(ridgidBody.ydot) < gravity.terminalY){
ridgidBody.ydot += gravity.y * dt;
}
// Finally, move the vec2d by the new velocity
pos.x += ridgidBody.xdot * dt;
pos.y += ridgidBody.ydot * dt;
}
}
}
+18
View File
@@ -0,0 +1,18 @@
package nz.ac.massey.javaecs;
public class RidgidBody {
public RidgidBody(){}
public RidgidBody(double xdot, double ydot, double xAcc, double yAcc){
this.xdot = xdot;
this.ydot = ydot;
this.xAcc = xAcc;
this.yAcc = yAcc;
}
// Velocities
double xdot = 0.0;
double ydot = 0.0;
// accelerations
double xAcc = 0.0;
double yAcc = 0.0;
}
+13
View File
@@ -0,0 +1,13 @@
package nz.ac.massey.javaecs;
public class Vec2D {
public Vec2D(){}
public Vec2D(double x, double y, int z){
this.x = x;
this.y = y;
this.z = z;
}
double x = 0.0;
double y = 0.0;
int z = 0;
}