Author SHA1 Message Date
BrychanD b1efb9802d Removed implementation classes
Leaves only the framework in the compiled clause.
Find the removed files in ../examples/misc/
2021-06-08 14:47:10 +12:00
BrychanD 7524a0096a Added abstraction to ECSSystem
Allows the library to signal the required implementations of inti() and update()
2021-06-08 14:44:34 +12:00
BrychanD 4354eac0cf Fixed referencing to package name 2021-06-07 21:25:01 +12:00
14 changed files with 38 additions and 18 deletions
+1 -1
View File
@@ -14,7 +14,7 @@
"type": "java",
"name": "Launch App",
"request": "launch",
"mainClass": "nz.ac.massey.programming_project_159333_s1_2021.App",
"mainClass": "nz.ac.massey.javaecs.App",
"projectName": "javaecs"
}
]
@@ -1,9 +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));
}
}
@@ -6,12 +6,18 @@ public class LogVec2DSystem extends ECSSystem{
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));
}
}
}
@@ -6,9 +6,13 @@ public class PhysicsSystem extends ECSSystem{
this.gameEngine = gameEngine;
}
@Override
void init() {}
void update(double dt){
@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);
+1 -1
View File
@@ -1,6 +1,6 @@
<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.programming_project_159333_s1_2021</groupId>
<groupId>nz.ac.massey.javaecs</groupId>
<artifactId>javaecs</artifactId>
<version>1.1-SNAPSHOT</version>
<properties>
@@ -97,7 +97,7 @@ public class ECS {
void addComponent(int entity, Type componentName, Object component){
componentManager.addComponentToEntity(componentName, component, entity);
entityManager.registerComponent(componentManager.getComponentIndex(componentName), entity);
systemManager.entitySignatureChanged(entity, entityManager.getRegistrations(entity));
systemManager.entityRegistrationsChanged(entity, entityManager.getRegistrations(entity));
}
/**
@@ -108,7 +108,7 @@ public class ECS {
void removeComponent(int entity, Type componentType){
componentManager.removeComponentFromEntity(componentType, entity);
entityManager.unregisterComponent(componentManager.getComponentIndex(componentType), entity);
systemManager.entitySignatureChanged(entity, entityManager.getRegistrations(entity));
systemManager.entityRegistrationsChanged(entity, entityManager.getRegistrations(entity));
}
/**
@@ -137,7 +137,7 @@ public class ECS {
* @param signature the new signature data
*/
void setSystemSignature(Type system, BitSet signature){
systemManager.setSignature(system, signature);
systemManager.setRegistrationSignature(system, signature);
}
Integer getMaxEntities(){
return entityManager.currentSize;
@@ -15,6 +15,10 @@ package nz.ac.massey.javaecs;
import java.util.Set;
import java.util.HashSet;
class ECSSystem{
abstract class ECSSystem{
Set<Integer> entities = new HashSet<>();
// Abstractions are included to remind the library user these two implementations (and/or variations) should be implemented
abstract void init();
abstract void update();
}
@@ -110,7 +110,7 @@ class EntityManager{
setRegistrations(newPos, getRegistrations(integer));
// Invoke an update in the SystemManager
systemManager.entityDestroyed(integer);
systemManager.entitySignatureChanged(newPos, getRegistrations(newPos));
systemManager.entityRegistrationsChanged(newPos, getRegistrations(newPos));
// Invoke the change in the components
componentManager.moveComponentData(integer, newPos);
componentManager.entityDestroyed(integer);
@@ -15,7 +15,7 @@ import java.util.Map;
import java.util.HashMap;
class SystemManager{
Map<Type, BitSet> signatures = new HashMap<>();
Map<Type, BitSet> registrationSignatures = new HashMap<>();
Map<Type, ECSSystem> systems = new HashMap<>();
// Registering the system adds it to the array of systems.
@@ -33,12 +33,12 @@ class SystemManager{
return false;
}
systems.put(systemType, system);
signatures.put(systemType, new BitSet());
registrationSignatures.put(systemType, new BitSet());
return true;
}
public void setSignature(Type system, BitSet registrations){
signatures.put(system, registrations);
public void setRegistrationSignature(Type systemType, BitSet registrations){
registrationSignatures.put(systemType, registrations);
}
public void entityDestroyed(int entity){
@@ -47,13 +47,13 @@ class SystemManager{
}
}
public void entitySignatureChanged(int entity, BitSet entitySignature){
public void entityRegistrationsChanged(int entity, BitSet entityRegistrations){
for (Type key : systems.keySet()) {
// Check if the signature is null
if (!entitySignature.equals(null)){
BitSet srcCpy = (BitSet)entitySignature.clone();
srcCpy.and(signatures.get(key));
if (srcCpy.equals(signatures.get(key))){ // Bitwise check if the entity is subscribed to this system
if (!entityRegistrations.equals(null)){
BitSet srcCpy = (BitSet)entityRegistrations.clone();
srcCpy.and(registrationSignatures.get(key));
if (srcCpy.equals(registrationSignatures.get(key))){ // Bitwise check if the entity is subscribed to this system
systems.get(key).entities.add(entity);
}
else{
@@ -62,7 +62,7 @@ class AppTest {
for (int i = 0; i < gameEngine.getMaxEntities() + 5; i++) {
if (i >= gameEngine.getMaxEntities()){
assertThrows(IndexOutOfBoundsException.class, () -> {
int entity = gameEngine.createEntity();
gameEngine.createEntity();
});
}
else{