Added some skeletons

This commit is contained in:
Brychan Dempsey 2021-06-11 21:09:41 +12:00
parent 8082817860
commit 4febf41721
8 changed files with 160 additions and 0 deletions

View File

@ -35,6 +35,11 @@
<version>${junit.version}</version> <version>${junit.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>nz.ac.massey.javaecs</groupId>
<artifactId>javaecs</artifactId>
<version>0.9.2-PRERELEASE</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@ -1,5 +1,7 @@
package nz.ac.massey.javaecs.examples; package nz.ac.massey.javaecs.examples;
import nz.ac.massey.javaecs.Engine;
/** /**
* Hello world! * Hello world!
*/ */
@ -12,6 +14,9 @@ public final class App {
* @param args The arguments of the program. * @param args The arguments of the program.
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Engine gameEngine = new Engine();
System.out.println("Hello World!"); System.out.println("Hello World!");
} }
} }

View File

@ -0,0 +1,5 @@
package nz.ac.massey.javaecs.examples.Components;
public class Control {
}

View File

@ -0,0 +1,11 @@
package nz.ac.massey.javaecs.examples.Components;
import java.lang.reflect.Type;
public class Render {
public Type renderType;
public Render(Type t){
renderType = t;
}
}

View File

@ -0,0 +1,7 @@
package nz.ac.massey.javaecs.examples.Components;
import javafx.scene.image.Image;
public class Sprite {
Image sprite;
}

View File

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

View File

@ -0,0 +1,19 @@
package nz.ac.massey.javaecs.examples.Systems;
import nz.ac.massey.javaecs.ECSSystem;
public class ControlSystem extends ECSSystem {
@Override
public void init() {
// TODO Auto-generated method stub
}
@Override
public void update() {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,97 @@
package nz.ac.massey.javaecs.examples.Systems;
import java.util.BitSet;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
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.Control;
import nz.ac.massey.javaecs.examples.Components.Render;
import nz.ac.massey.javaecs.examples.Components.Sprite;
import nz.ac.massey.javaecs.examples.Components.Vec2D;
public class RenderSystem extends ECSSystem {
JFXView jFXView;
Engine gameEngine;
Thread renderThread;
double renderScale;
int screenX = 1024;
int screenY = 1024;
public RenderSystem(Engine gameEngine, double renderScale){
this.gameEngine = gameEngine;
// Set registrations
registrationSet = new BitSet();
registrationSet.set(gameEngine.getComponentIndex(Render.class));
registrationSet.set(gameEngine.getComponentIndex(Vec2D.class));
this.renderScale = renderScale;
}
@Override
public void init() {
// Spawn a new asynchronous thread (won't rejoin the main program flow)
renderThread = new Thread(new RenderStarter());
renderThread.start();
}
@Override
public void update() {
Group renderScene = new Group();
for (Entity entity : entities) {
if (((Render)gameEngine.getComponentData(entity, Render.class)).renderType == Control.class){
// Do control updates here
}
else if (((Render)gameEngine.getComponentData(entity, Render.class)).renderType == Sprite.class){
Vec2D vec2d = (Vec2D)gameEngine.getComponentData(entity, Vec2D.class);
Sprite sprite = (Sprite)gameEngine.getComponentData(entity, Sprite.class);
}
}
// Must be run by the UI thread, not the main thread.
// This dispatches the operation run() to the UI.
Platform.runLater(new Runnable(){
@Override
public void run() {
JFXView.root.getChildren().clear();
JFXView.root.getChildren().add(renderScene);
}
});
}
// Add a renderer
public class RenderStarter implements Runnable{
@Override
public void run() {
JFXView.run();
}
void updateScene(Group newGroup){
JFXView.root.getChildren().clear();
JFXView.root.getChildren().add(newGroup);
}
}
public static class JFXView extends Application {
private static Group root;
@Override
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
root = new Group();
Scene scene = new Scene(root, 1024, 1024, Color.BLACK);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void run(){
launch(new String[0]);
}
}
}