Client side entity instancing

This commit is contained in:
austin 2021-08-03 00:04:57 -04:00
parent e18e342492
commit 3a1924f8f4
15 changed files with 269 additions and 126 deletions

View File

@ -132,7 +132,7 @@ public class LoadingThread extends Thread {
initClientTerrainManager(); initClientTerrainManager();
//initialize the cell manager (client) //initialize the cell manager (client)
initDynamicCellManager(); initDrawCellManager();
//collision engine //collision engine
initCollisionEngine(Globals.RUN_SERVER); initCollisionEngine(Globals.RUN_SERVER);
@ -212,7 +212,7 @@ public class LoadingThread extends Thread {
initClientTerrainManager(); initClientTerrainManager();
//initialize the cell manager (client) //initialize the cell manager (client)
initDynamicCellManager(); initDrawCellManager();
//collision engine //collision engine
initCollisionEngine(Globals.RUN_SERVER); initCollisionEngine(Globals.RUN_SERVER);
@ -315,7 +315,7 @@ public class LoadingThread extends Thread {
} }
} }
Globals.spawnPoint = new Vector3f(playerStartX * chunkSize, Globals.serverTerrainManager.getHeightAtPosition(playerStartX * chunkSize,playerStartY * chunkSize), playerStartY * chunkSize); // Globals.spawnPoint = new Vector3f(playerStartX * chunkSize, Globals.serverTerrainManager.getHeightAtPosition(playerStartX * chunkSize,playerStartY * chunkSize), playerStartY * chunkSize);
@ -345,7 +345,7 @@ public class LoadingThread extends Thread {
Vector2i townLoc = Town.findValidTownLocation(); Vector2i townLoc = Town.findValidTownLocation();
if(townLoc != null){ if(townLoc != null){
int chunkSize = Globals.serverTerrainManager.getChunkWidth(); int chunkSize = Globals.serverTerrainManager.getChunkWidth();
Globals.spawnPoint = new Vector3f(townLoc.x * chunkSize, Globals.serverTerrainManager.getHeightAtPosition(townLoc.x * chunkSize,townLoc.y * chunkSize), townLoc.y * chunkSize); Globals.spawnPoint = new Vector3f((townLoc.x - 3) * chunkSize, Globals.serverTerrainManager.getHeightAtPosition(townLoc.x * chunkSize,townLoc.y * chunkSize), townLoc.y * chunkSize);
Town.createTown(townLoc.x,townLoc.y); Town.createTown(townLoc.x,townLoc.y);
} }
} }
@ -401,12 +401,12 @@ public class LoadingThread extends Thread {
} }
static void initDynamicCellManager(){ static void initDrawCellManager(){
Globals.drawCellManager = new DrawCellManager( Globals.drawCellManager = new DrawCellManager(
Globals.clientWorldData, Globals.clientWorldData,
Globals.clientTerrainManager, Globals.clientTerrainManager,
Globals.clientPlayerData.getInitialDiscretePositionX(), Globals.clientPlayerData.getWorldPositionX(),
Globals.clientPlayerData.getInitialDiscretePositionY() Globals.clientPlayerData.getWorldPositionY()
// Globals.terrainManager.getDynamicInterpolationRatio(), // Globals.terrainManager.getDynamicInterpolationRatio(),
// Globals.terrainManager.getRandomDampener() // Globals.terrainManager.getRandomDampener()
); );

View File

@ -15,6 +15,13 @@ public class EntityDataStrings {
public static final String DATA_STRING_SCALE = "scale"; public static final String DATA_STRING_SCALE = "scale";
public static final String DATA_STRING_MODEL_PATH = "modelPath"; public static final String DATA_STRING_MODEL_PATH = "modelPath";
public static final String DATA_STRING_ACTOR = "actor"; public static final String DATA_STRING_ACTOR = "actor";
public static final String DATA_STRING_DRAW = "drawFlag";
/*
Terrain Entity
*/
public static final String TERRAIN_IS_TERRAIN = "terrainEntity";
/* /*
@ -93,6 +100,7 @@ public class EntityDataStrings {
public static final String COLLISION_ENTITY_COLLISION_OBJECT = "collisionEntityBulletObject"; public static final String COLLISION_ENTITY_COLLISION_OBJECT = "collisionEntityBulletObject";
public static final String COLLISION_ENTITY_COLLIDABLE = "collisionEntityCollidable"; public static final String COLLISION_ENTITY_COLLIDABLE = "collisionEntityCollidable";
public static final String COLLISION_ENTITY_PARENT = "collisionEntityParent";
public static final String COLLISION_ENTITY_TYPE_PLANE = "collisionTypePlane"; public static final String COLLISION_ENTITY_TYPE_PLANE = "collisionTypePlane";
public static final String COLLISION_ENTITY_TYPE_CUBE = "collisionTypeCube"; public static final String COLLISION_ENTITY_TYPE_CUBE = "collisionTypeCube";

View File

@ -1,9 +1,13 @@
package electrosphere.entity; package electrosphere.entity;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.main.Globals;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import org.joml.Vector3f;
/** /**
* *
@ -19,7 +23,7 @@ public class EntityManager {
static CopyOnWriteArrayList<Entity> lightList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList<Entity> lightList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> uiList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList<Entity> uiList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> itemList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList<Entity> itemList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> attachList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList<Entity> boneAttachedList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> attackerList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList<Entity> attackerList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> creatureList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList<Entity> creatureList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> lifeStateList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList<Entity> lifeStateList = new CopyOnWriteArrayList();
@ -75,12 +79,12 @@ public class EntityManager {
return itemList; return itemList;
} }
public void registerAttachedEntity(Entity e){ public void registerBoneAttachedEntity(Entity e){
attachList.add(e); boneAttachedList.add(e);
} }
public CopyOnWriteArrayList<Entity> getAttachedEntities(){ public CopyOnWriteArrayList<Entity> getBoneAttachedEntities(){
return attachList; return boneAttachedList;
} }
public void registerAttackerEntity(Entity e){ public void registerAttackerEntity(Entity e){
@ -160,6 +164,36 @@ public class EntityManager {
} }
} }
public void recursiveDeregister(Entity target){
if(AttachUtils.hasChildren(target)){
List<Entity> childrenList = AttachUtils.getChildrenList(target);
for(Entity currentChild : childrenList){
recursiveDeregister(currentChild);
}
}
deregisterEntity(target);
}
public void recursiveHide(Entity target){
if(AttachUtils.hasChildren(target)){
List<Entity> childrenList = AttachUtils.getChildrenList(target);
for(Entity currentChild : childrenList){
recursiveHide(currentChild);
}
}
target.putData(EntityDataStrings.DATA_STRING_DRAW, false);
}
public void recursiveShow(Entity target){
if(AttachUtils.hasChildren(target)){
List<Entity> childrenList = AttachUtils.getChildrenList(target);
for(Entity currentChild : childrenList){
recursiveShow(currentChild);
}
}
target.putData(EntityDataStrings.DATA_STRING_DRAW, true);
}
public void overrideEntityId(Entity e, int id){ public void overrideEntityId(Entity e, int id){
LoggerInterface.loggerGameLogic.DEBUG("Overriding entity ID " + e.getId() + " => " + id); LoggerInterface.loggerGameLogic.DEBUG("Overriding entity ID " + e.getId() + " => " + id);
if(entityIdMap.contains(e.getId())){ if(entityIdMap.contains(e.getId())){
@ -173,4 +207,35 @@ public class EntityManager {
return (Entity)entityIdMap.get(id); return (Entity)entityIdMap.get(id);
} }
public void clearOutOfBoundsEntities(){
for(Entity entity : entityList){
if(entity.getDataKeys().contains(EntityDataStrings.TERRAIN_IS_TERRAIN) || entity.getDataKeys().contains(EntityDataStrings.ATTACH_PARENT) || entity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_PARENT)){
} else {
Vector3f position = EntityUtils.getPosition(entity);
//common world data is initialized with the collision data
//if this is null then the engine hasn't fully started up yet
if(Globals.commonWorldData != null && position != null){
int worldX = Globals.commonWorldData.convertRealToWorld(position.x);
int worldY = Globals.commonWorldData.convertRealToWorld(position.z);
if(!Globals.drawCellManager.coordsInPhysicsSpace(worldX, worldY)){
//if we're running the server we need to just hide the entity
//otherwise delete it
if(Globals.RUN_SERVER && Globals.RUN_CLIENT){
recursiveHide(entity);
} else {
recursiveDeregister(entity);
}
} else {
//if the entity is within range, we're running server,
//and it's not set to visible, make it visible
if(Globals.RUN_SERVER && Globals.RUN_CLIENT){
recursiveShow(entity);
}
}
}
}
}
}
} }

View File

@ -44,6 +44,7 @@ public class EntityUtils {
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0)); rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity()); rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity());
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1)); rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
Globals.entityManager.registerEntity(rVal); Globals.entityManager.registerEntity(rVal);
Globals.entityManager.registerDrawableEntity(rVal); Globals.entityManager.registerDrawableEntity(rVal);
return rVal; return rVal;
@ -55,6 +56,7 @@ public class EntityUtils {
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0)); rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().rotateAxis((float)0, new Vector3f(1,0,0))); rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().rotateAxis((float)0, new Vector3f(1,0,0)));
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1)); rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
Globals.entityManager.registerEntity(rVal); Globals.entityManager.registerEntity(rVal);
Globals.entityManager.registerDrawableEntity(rVal); Globals.entityManager.registerDrawableEntity(rVal);
return rVal; return rVal;

View File

@ -19,12 +19,12 @@ public class AttachUtils {
public static void attachEntityToEntityAtBone(Entity parent, Entity toAttach, String boneName){ public static void attachEntityToEntityAtBone(Entity parent, Entity toAttach, String boneName){
Globals.entityManager.registerAttachedEntity(toAttach); Globals.entityManager.registerBoneAttachedEntity(toAttach);
toAttach.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, true); toAttach.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, true);
toAttach.putData(EntityDataStrings.ATTACH_PARENT, parent); toAttach.putData(EntityDataStrings.ATTACH_PARENT, parent);
toAttach.putData(EntityDataStrings.ATTACH_TARGET_BONE, boneName); toAttach.putData(EntityDataStrings.ATTACH_TARGET_BONE, boneName);
if(parent.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST)){ if(parent.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST)){
((LinkedList)parent.getData(EntityDataStrings.ATTACH_CHILDREN_LIST)).add(toAttach); getChildrenList(parent).add(toAttach);
} else { } else {
LinkedList<Entity> childrenEntities = new LinkedList(); LinkedList<Entity> childrenEntities = new LinkedList();
childrenEntities.add(toAttach); childrenEntities.add(toAttach);
@ -33,7 +33,7 @@ public class AttachUtils {
} }
public static void updateAttachedEntityPositions(){ public static void updateAttachedEntityPositions(){
for(Entity currentEntity : Globals.entityManager.getAttachedEntities()){ for(Entity currentEntity : Globals.entityManager.getBoneAttachedEntities()){
Entity parent; Entity parent;
if((parent = (Entity)currentEntity.getData(EntityDataStrings.ATTACH_PARENT))!=null){ if((parent = (Entity)currentEntity.getData(EntityDataStrings.ATTACH_PARENT))!=null){
String targetBone; String targetBone;
@ -68,4 +68,24 @@ public class AttachUtils {
public static Entity getParent(Entity e){ public static Entity getParent(Entity e){
return (Entity)e.getData(EntityDataStrings.ATTACH_PARENT); return (Entity)e.getData(EntityDataStrings.ATTACH_PARENT);
} }
public static boolean hasChildren(Entity e){
return e.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST) && !getChildrenList(e).isEmpty();
}
public static LinkedList<Entity> getChildrenList(Entity e){
return (LinkedList<Entity>)e.getData(EntityDataStrings.ATTACH_CHILDREN_LIST);
}
public static void attachEntityToEntity(Entity parent, Entity child){
child.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, true);
child.putData(EntityDataStrings.ATTACH_PARENT, parent);
if(parent.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST)){
getChildrenList(parent).add(child);
} else {
LinkedList<Entity> childrenEntities = new LinkedList();
childrenEntities.add(child);
parent.putData(EntityDataStrings.ATTACH_CHILDREN_LIST, childrenEntities);
}
}
} }

View File

@ -4,6 +4,7 @@ import electrosphere.collision.dispatch.CollisionObject;
import electrosphere.collision.shapes.CylinderShape; import electrosphere.collision.shapes.CylinderShape;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.game.collision.PhysicsUtils; import electrosphere.game.collision.PhysicsUtils;
import electrosphere.game.collision.collidable.Collidable; import electrosphere.game.collision.collidable.Collidable;
import electrosphere.main.Globals; import electrosphere.main.Globals;
@ -66,6 +67,21 @@ public class CollisionObjUtils {
} }
public static Entity attachCollisionPlane(Vector3f scale, Vector3f position, Quaternionf rotation, Entity parent){
Entity rVal = spawnCollisionPlane(scale, position, rotation);
AttachUtils.attachEntityToEntity(parent, rVal);
return rVal;
}
public static Entity attachCollisionCube(Vector3f scale, Vector3f position, Quaternionf rotation, Entity parent){
Entity rVal = spawnCollisionCube(scale, position, rotation);
AttachUtils.attachEntityToEntity(parent, rVal);
return rVal;
}
} }

View File

@ -35,7 +35,7 @@ public class StructureUtils {
Vector4f rotatedPosition = rotationTransform.transform(new Vector4f(template.getPositionX(),template.getPositionY(),template.getPositionZ(),1.0f)); Vector4f rotatedPosition = rotationTransform.transform(new Vector4f(template.getPositionX(),template.getPositionY(),template.getPositionZ(),1.0f));
Vector3f cubePosition = new Vector3f(position).add(rotatedPosition.x,rotatedPosition.y,rotatedPosition.z); Vector3f cubePosition = new Vector3f(position).add(rotatedPosition.x,rotatedPosition.y,rotatedPosition.z);
Quaternionf cubeRotation = new Quaternionf(rotation).mul(new Quaternionf(template.getRotationX(),template.getRotationY(),template.getRotationZ(),template.getRotationW())).normalize(); Quaternionf cubeRotation = new Quaternionf(rotation).mul(new Quaternionf(template.getRotationX(),template.getRotationY(),template.getRotationZ(),template.getRotationW())).normalize();
CollisionObjUtils.spawnCollisionCube(new Vector3f(template.getScaleX(),template.getScaleY(),template.getScaleZ()), cubePosition, cubeRotation); CollisionObjUtils.attachCollisionCube(new Vector3f(template.getScaleX(),template.getScaleY(),template.getScaleZ()), cubePosition, cubeRotation, rVal);
// Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE); // Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE);
// Globals.collisionEngine.registerPhysicsEntity(rVal); // Globals.collisionEngine.registerPhysicsEntity(rVal);
// Globals.collisionEngine.registerCollisionObject(rigidBody, collidable); // Globals.collisionEngine.registerCollisionObject(rigidBody, collidable);

View File

@ -3,6 +3,7 @@ package electrosphere.game.client.cells;
import electrosphere.collision.dispatch.CollisionObject; import electrosphere.collision.dispatch.CollisionObject;
import electrosphere.dynamics.RigidBody; import electrosphere.dynamics.RigidBody;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.game.collision.PhysicsUtils; import electrosphere.game.collision.PhysicsUtils;
import electrosphere.game.collision.collidable.Collidable; import electrosphere.game.collision.collidable.Collidable;
@ -85,6 +86,7 @@ public class DrawCell {
Model terrainModel = ModelUtils.createTerrainModelPrecomputedShader(heightmap, program, stride); Model terrainModel = ModelUtils.createTerrainModelPrecomputedShader(heightmap, program, stride);
String terrainModelPath = Globals.assetManager.registerModel(terrainModel); String terrainModelPath = Globals.assetManager.registerModel(terrainModel);
modelEntity = EntityUtils.spawnDrawableEntity(terrainModelPath); modelEntity = EntityUtils.spawnDrawableEntity(terrainModelPath);
modelEntity.putData(EntityDataStrings.TERRAIN_IS_TERRAIN, true);
LoggerInterface.loggerRenderer.INFO("New cell @ " + cellX * dynamicInterpolationRatio + "," + cellY * dynamicInterpolationRatio); LoggerInterface.loggerRenderer.INFO("New cell @ " + cellX * dynamicInterpolationRatio + "," + cellY * dynamicInterpolationRatio);
EntityUtils.getPosition(modelEntity).set(new Vector3f(cellX * dynamicInterpolationRatio, 0.0f, cellY * dynamicInterpolationRatio)); EntityUtils.getPosition(modelEntity).set(new Vector3f(cellX * dynamicInterpolationRatio, 0.0f, cellY * dynamicInterpolationRatio));
} }

View File

@ -638,6 +638,10 @@ public class DrawCellManager {
return rVal; return rVal;
} }
public boolean coordsInPhysicsSpace(int worldX, int worldY){
return worldX <= cellX + physicsRadius && worldX >= cellX - physicsRadius && worldY <= cellY + physicsRadius && worldY >= cellY - physicsRadius;
}
// public // public
} }

View File

@ -3,8 +3,8 @@ package electrosphere.game.client.player;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
public class ClientPlayerData { public class ClientPlayerData {
int initialDiscretePositionX; int worldPositionX;
int initialDiscretePositionY; int worldPositionY;
int simulationRadius = 3; int simulationRadius = 3;
boolean loaded = false; boolean loaded = false;
@ -16,19 +16,19 @@ public class ClientPlayerData {
return loaded; return loaded;
} }
public void setInitialDiscretePosition(int x, int y){ public void setWorldPosition(int x, int y){
initialDiscretePositionX = x; worldPositionX = x;
initialDiscretePositionY = y; worldPositionY = y;
LoggerInterface.loggerGameLogic.INFO("Loaded client data"); LoggerInterface.loggerGameLogic.INFO("Loaded client data");
loaded = true; loaded = true;
} }
public int getInitialDiscretePositionX() { public int getWorldPositionX() {
return initialDiscretePositionX; return worldPositionX;
} }
public int getInitialDiscretePositionY() { public int getWorldPositionY() {
return initialDiscretePositionY; return worldPositionY;
} }

View File

@ -70,4 +70,12 @@ public class CommonWorldData {
return serverWorldData.getWorldBoundMax(); return serverWorldData.getWorldBoundMax();
} }
} }
public int convertRealToWorld(float real){
if(clientWorldData != null){
return clientWorldData.convertRealToChunkSpace(real);
} else {
return serverWorldData.convertRealToChunkSpace(real);
}
}
} }

View File

@ -129,5 +129,8 @@ public class DataCellManager {
} }
} }
public void unloadPlayerlessChunks(){
}
} }

View File

@ -98,9 +98,14 @@ public class MicroSimulation {
} }
//clear collidable impulse lists //clear collidable impulse lists
Globals.collisionEngine.clearCollidableImpulseLists(); Globals.collisionEngine.clearCollidableImpulseLists();
//delete all client side entities that aren't in visible chunks
if(Globals.RUN_CLIENT){
Globals.entityManager.clearOutOfBoundsEntities();
}
//data cell manager update //data cell manager update
if(Globals.dataCellManager != null){ if(Globals.dataCellManager != null){
Globals.dataCellManager.updatePlayerPositions(); Globals.dataCellManager.updatePlayerPositions();
Globals.dataCellManager.unloadPlayerlessChunks();
} }
} }

View File

@ -120,7 +120,7 @@ public class ClientProtocol {
LoggerInterface.loggerNetworking.DEBUG("Player ID is " + Main.playerId); LoggerInterface.loggerNetworking.DEBUG("Player ID is " + Main.playerId);
break; break;
case SETINITIALDISCRETEPOSITION: case SETINITIALDISCRETEPOSITION:
Globals.clientPlayerData.setInitialDiscretePosition(message.getinitialDiscretePositionX(), message.getinitialDiscretePositionY()); Globals.clientPlayerData.setWorldPosition(message.getinitialDiscretePositionX(), message.getinitialDiscretePositionY());
break; break;
} }
} }

View File

@ -245,16 +245,18 @@ public class RenderingEngine {
// //
modelTransformMatrix = new Matrix4f(); modelTransformMatrix = new Matrix4f();
for(Entity currentEntity : Globals.entityManager.getDrawable()){ for(Entity currentEntity : Globals.entityManager.getDrawable()){
//fetch actor if((boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){
Actor currentActor = EntityUtils.getActor(currentEntity); //fetch actor
//calculate and apply model transform Actor currentActor = EntityUtils.getActor(currentEntity);
modelTransformMatrix.identity(); //calculate and apply model transform
modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); modelTransformMatrix.identity();
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity)); modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
currentActor.applyModelMatrix(modelTransformMatrix); modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
//draw currentActor.applyModelMatrix(modelTransformMatrix);
currentActor.drawForDepthBuffer(); //draw
currentActor.drawForDepthBuffer();
}
} }
@ -292,43 +294,67 @@ public class RenderingEngine {
// //
modelTransformMatrix = new Matrix4f(); modelTransformMatrix = new Matrix4f();
for(Entity currentEntity : Globals.entityManager.getDrawable()){ for(Entity currentEntity : Globals.entityManager.getDrawable()){
//fetch actor if((boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){
Actor currentActor = EntityUtils.getActor(currentEntity); //fetch actor
currentActor.incrementAnimationTime(0.001); Actor currentActor = EntityUtils.getActor(currentEntity);
//increment animations currentActor.incrementAnimationTime(0.001);
//this is incremented in the shadow calculations //increment animations
// if(currentActor.getCurrentAnimation() != null){ //this is incremented in the shadow calculations
// currentActor.incrementAnimationTime(deltaTime * 500); // if(currentActor.getCurrentAnimation() != null){
// } // currentActor.incrementAnimationTime(deltaTime * 500);
//calculate and apply model transform // }
modelTransformMatrix.identity(); //calculate and apply model transform
modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); modelTransformMatrix.identity();
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity)); modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
currentActor.applyModelMatrix(modelTransformMatrix); modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
//draw currentActor.applyModelMatrix(modelTransformMatrix);
currentActor.draw(); //draw
currentActor.draw();
// Model currentModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(currentEntity)); // Model currentModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(currentEntity));
// if(currentModel != null){ // if(currentModel != null){
// if(currentModel.currentAnimation != null){ // if(currentModel.currentAnimation != null){
// currentModel.incrementTime(deltaTime * 500); // currentModel.incrementTime(deltaTime * 500);
// } // }
// currentModel.modelMatrix = new Matrix4f(); // currentModel.modelMatrix = new Matrix4f();
// currentModel.modelMatrix.translate(new Vector3f(EntityUtils.getEntityPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0))); // currentModel.modelMatrix.translate(new Vector3f(EntityUtils.getEntityPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0)));
// currentModel.modelMatrix.rotate(EntityUtils.getEntityRotation(currentEntity)); // currentModel.modelMatrix.rotate(EntityUtils.getEntityRotation(currentEntity));
// currentModel.modelMatrix.scale(EntityUtils.getEntityScale(currentEntity)); // currentModel.modelMatrix.scale(EntityUtils.getEntityScale(currentEntity));
// currentModel.draw(); // currentModel.draw();
// } // }
}
} }
if(renderHitboxes){ if(renderHitboxes){
for(Entity currentHitbox : Globals.hitboxManager.getAllHitboxes()){ for(Entity currentHitbox : Globals.hitboxManager.getAllHitboxes()){
Model hitboxModel; if((boolean)currentHitbox.getData(EntityDataStrings.DATA_STRING_DRAW)){
HitboxData data = HitboxUtils.getHitboxData(currentHitbox); Model hitboxModel;
if(data.isActive()){ HitboxData data = HitboxUtils.getHitboxData(currentHitbox);
if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){ if(data.isActive()){
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){ if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){
Vector3f position = EntityUtils.getPosition(currentHitbox);
modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
modelTransformMatrix.scale(data.getRadius() * 2);
hitboxModel.modelMatrix = modelTransformMatrix;
hitboxModel.draw(true, true, false, true, true, true, true);
}
} else if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT)){
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_1.fbx")) != null){
Vector3f position = EntityUtils.getPosition(currentHitbox);
modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
modelTransformMatrix.scale(data.getRadius() * 2);
hitboxModel.modelMatrix = modelTransformMatrix;
hitboxModel.draw(true, true, false, true, true, true, true);
}
}
} else {
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_grey.fbx")) != null){
Vector3f position = EntityUtils.getPosition(currentHitbox); Vector3f position = EntityUtils.getPosition(currentHitbox);
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
@ -337,26 +363,6 @@ public class RenderingEngine {
hitboxModel.modelMatrix = modelTransformMatrix; hitboxModel.modelMatrix = modelTransformMatrix;
hitboxModel.draw(true, true, false, true, true, true, true); hitboxModel.draw(true, true, false, true, true, true, true);
} }
} else if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT)){
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_1.fbx")) != null){
Vector3f position = EntityUtils.getPosition(currentHitbox);
modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
modelTransformMatrix.scale(data.getRadius() * 2);
hitboxModel.modelMatrix = modelTransformMatrix;
hitboxModel.draw(true, true, false, true, true, true, true);
}
}
} else {
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_grey.fbx")) != null){
Vector3f position = EntityUtils.getPosition(currentHitbox);
modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
modelTransformMatrix.scale(data.getRadius() * 2);
hitboxModel.modelMatrix = modelTransformMatrix;
hitboxModel.draw(true, true, false, true, true, true, true);
} }
} }
} }
@ -365,47 +371,51 @@ public class RenderingEngine {
if(renderPhysics){ if(renderPhysics){
Model physicsGraphicsModel; Model physicsGraphicsModel;
for(Entity physicsEntity : Globals.collisionEngine.getDynamicPhysicsEntities()){ for(Entity physicsEntity : Globals.collisionEngine.getDynamicPhysicsEntities()){
PhysicsObject template = (PhysicsObject)physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE); if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){
switch(template.getType()){ PhysicsObject template = (PhysicsObject)physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE);
case "CYLINDER": switch(template.getType()){
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){ case "CYLINDER":
Vector3f position = EntityUtils.getPosition(physicsEntity); if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){
modelTransformMatrix.identity(); Vector3f position = EntityUtils.getPosition(physicsEntity);
modelTransformMatrix.translate(new Vector3f(position).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); modelTransformMatrix.identity();
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere modelTransformMatrix.translate(new Vector3f(position).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3()); // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
physicsGraphicsModel.modelMatrix = modelTransformMatrix; modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3());
physicsGraphicsModel.draw(true, true, false, true, true, true, true); physicsGraphicsModel.modelMatrix = modelTransformMatrix;
} physicsGraphicsModel.draw(true, true, false, true, true, true, true);
break; }
break;
}
} }
} }
for(Entity physicsEntity : Globals.collisionEngine.getStructurePhysicsEntities()){ for(Entity physicsEntity : Globals.collisionEngine.getStructurePhysicsEntities()){
if(physicsEntity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE)){ if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitplane.fbx")) != null){ if(physicsEntity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE)){
Vector3f position = EntityUtils.getPosition(physicsEntity); if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitplane.fbx")) != null){
Vector3f scale = EntityUtils.getScale(physicsEntity); Vector3f position = EntityUtils.getPosition(physicsEntity);
Quaternionf rotation = EntityUtils.getRotation(physicsEntity); Vector3f scale = EntityUtils.getScale(physicsEntity);
modelTransformMatrix.identity(); Quaternionf rotation = EntityUtils.getRotation(physicsEntity);
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); modelTransformMatrix.identity();
modelTransformMatrix.rotate(rotation); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere modelTransformMatrix.rotate(rotation);
modelTransformMatrix.scale(scale); // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
physicsGraphicsModel.modelMatrix = modelTransformMatrix; modelTransformMatrix.scale(scale);
physicsGraphicsModel.draw(true, true, false, true, true, true, true); physicsGraphicsModel.modelMatrix = modelTransformMatrix;
} physicsGraphicsModel.draw(true, true, false, true, true, true, true);
} else if(physicsEntity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_TYPE_CUBE)){ }
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcube.fbx")) != null){ } else if(physicsEntity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_TYPE_CUBE)){
Vector3f position = EntityUtils.getPosition(physicsEntity); if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcube.fbx")) != null){
Vector3f scale = EntityUtils.getScale(physicsEntity); Vector3f position = EntityUtils.getPosition(physicsEntity);
Quaternionf rotation = EntityUtils.getRotation(physicsEntity); Vector3f scale = EntityUtils.getScale(physicsEntity);
modelTransformMatrix.identity(); Quaternionf rotation = EntityUtils.getRotation(physicsEntity);
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); modelTransformMatrix.identity();
modelTransformMatrix.rotate(rotation); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere modelTransformMatrix.rotate(rotation);
modelTransformMatrix.scale(scale); // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
physicsGraphicsModel.modelMatrix = modelTransformMatrix; modelTransformMatrix.scale(scale);
physicsGraphicsModel.draw(true, true, false, true, true, true, true); physicsGraphicsModel.modelMatrix = modelTransformMatrix;
physicsGraphicsModel.draw(true, true, false, true, true, true, true);
}
} }
} }
} }