From 3a1924f8f4b2ddef52049c58eeaa0db193c57cb0 Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 3 Aug 2021 00:04:57 -0400 Subject: [PATCH] Client side entity instancing --- .../electrosphere/engine/LoadingThread.java | 14 +- .../entity/EntityDataStrings.java | 8 + .../electrosphere/entity/EntityManager.java | 75 ++++++- .../electrosphere/entity/EntityUtils.java | 2 + .../entity/types/attach/AttachUtils.java | 26 ++- .../types/collision/CollisionObjUtils.java | 16 ++ .../types/structure/StructureUtils.java | 2 +- .../game/client/cells/DrawCell.java | 2 + .../game/client/cells/DrawCellManager.java | 4 + .../game/client/player/ClientPlayerData.java | 18 +- .../game/collision/CommonWorldData.java | 8 + .../world/datacell/DataCellManager.java | 3 + .../game/state/MicroSimulation.java | 5 + .../net/client/ClientProtocol.java | 2 +- .../renderer/RenderingEngine.java | 210 +++++++++--------- 15 files changed, 269 insertions(+), 126 deletions(-) diff --git a/src/main/java/electrosphere/engine/LoadingThread.java b/src/main/java/electrosphere/engine/LoadingThread.java index e7c8b98d..893e1cfb 100644 --- a/src/main/java/electrosphere/engine/LoadingThread.java +++ b/src/main/java/electrosphere/engine/LoadingThread.java @@ -132,7 +132,7 @@ public class LoadingThread extends Thread { initClientTerrainManager(); //initialize the cell manager (client) - initDynamicCellManager(); + initDrawCellManager(); //collision engine initCollisionEngine(Globals.RUN_SERVER); @@ -212,7 +212,7 @@ public class LoadingThread extends Thread { initClientTerrainManager(); //initialize the cell manager (client) - initDynamicCellManager(); + initDrawCellManager(); //collision engine 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(); if(townLoc != null){ 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); } } @@ -401,12 +401,12 @@ public class LoadingThread extends Thread { } - static void initDynamicCellManager(){ + static void initDrawCellManager(){ Globals.drawCellManager = new DrawCellManager( Globals.clientWorldData, Globals.clientTerrainManager, - Globals.clientPlayerData.getInitialDiscretePositionX(), - Globals.clientPlayerData.getInitialDiscretePositionY() + Globals.clientPlayerData.getWorldPositionX(), + Globals.clientPlayerData.getWorldPositionY() // Globals.terrainManager.getDynamicInterpolationRatio(), // Globals.terrainManager.getRandomDampener() ); diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index 3fa6dccb..d25a0a83 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -15,6 +15,13 @@ public class EntityDataStrings { public static final String DATA_STRING_SCALE = "scale"; public static final String DATA_STRING_MODEL_PATH = "modelPath"; 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_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_CUBE = "collisionTypeCube"; diff --git a/src/main/java/electrosphere/entity/EntityManager.java b/src/main/java/electrosphere/entity/EntityManager.java index debada1b..b056f261 100644 --- a/src/main/java/electrosphere/entity/EntityManager.java +++ b/src/main/java/electrosphere/entity/EntityManager.java @@ -1,9 +1,13 @@ package electrosphere.entity; +import electrosphere.entity.types.attach.AttachUtils; import electrosphere.logger.LoggerInterface; +import electrosphere.main.Globals; import java.util.Iterator; +import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; +import org.joml.Vector3f; /** * @@ -19,7 +23,7 @@ public class EntityManager { static CopyOnWriteArrayList lightList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList uiList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList itemList = new CopyOnWriteArrayList(); - static CopyOnWriteArrayList attachList = new CopyOnWriteArrayList(); + static CopyOnWriteArrayList boneAttachedList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList attackerList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList creatureList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList lifeStateList = new CopyOnWriteArrayList(); @@ -75,12 +79,12 @@ public class EntityManager { return itemList; } - public void registerAttachedEntity(Entity e){ - attachList.add(e); + public void registerBoneAttachedEntity(Entity e){ + boneAttachedList.add(e); } - public CopyOnWriteArrayList getAttachedEntities(){ - return attachList; + public CopyOnWriteArrayList getBoneAttachedEntities(){ + return boneAttachedList; } public void registerAttackerEntity(Entity e){ @@ -160,6 +164,36 @@ public class EntityManager { } } + public void recursiveDeregister(Entity target){ + if(AttachUtils.hasChildren(target)){ + List childrenList = AttachUtils.getChildrenList(target); + for(Entity currentChild : childrenList){ + recursiveDeregister(currentChild); + } + } + deregisterEntity(target); + } + + public void recursiveHide(Entity target){ + if(AttachUtils.hasChildren(target)){ + List 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 childrenList = AttachUtils.getChildrenList(target); + for(Entity currentChild : childrenList){ + recursiveShow(currentChild); + } + } + target.putData(EntityDataStrings.DATA_STRING_DRAW, true); + } + public void overrideEntityId(Entity e, int id){ LoggerInterface.loggerGameLogic.DEBUG("Overriding entity ID " + e.getId() + " => " + id); if(entityIdMap.contains(e.getId())){ @@ -173,4 +207,35 @@ public class EntityManager { 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); + } + } + } + } + } + } + } diff --git a/src/main/java/electrosphere/entity/EntityUtils.java b/src/main/java/electrosphere/entity/EntityUtils.java index bf535902..ea0a0d8f 100644 --- a/src/main/java/electrosphere/entity/EntityUtils.java +++ b/src/main/java/electrosphere/entity/EntityUtils.java @@ -44,6 +44,7 @@ public class EntityUtils { 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_SCALE, new Vector3f(1,1,1)); + rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); Globals.entityManager.registerEntity(rVal); Globals.entityManager.registerDrawableEntity(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_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_DRAW, true); Globals.entityManager.registerEntity(rVal); Globals.entityManager.registerDrawableEntity(rVal); return rVal; diff --git a/src/main/java/electrosphere/entity/types/attach/AttachUtils.java b/src/main/java/electrosphere/entity/types/attach/AttachUtils.java index 28084027..d89bf1af 100644 --- a/src/main/java/electrosphere/entity/types/attach/AttachUtils.java +++ b/src/main/java/electrosphere/entity/types/attach/AttachUtils.java @@ -19,12 +19,12 @@ public class AttachUtils { 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_PARENT, parent); toAttach.putData(EntityDataStrings.ATTACH_TARGET_BONE, boneName); if(parent.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST)){ - ((LinkedList)parent.getData(EntityDataStrings.ATTACH_CHILDREN_LIST)).add(toAttach); + getChildrenList(parent).add(toAttach); } else { LinkedList childrenEntities = new LinkedList(); childrenEntities.add(toAttach); @@ -33,7 +33,7 @@ public class AttachUtils { } public static void updateAttachedEntityPositions(){ - for(Entity currentEntity : Globals.entityManager.getAttachedEntities()){ + for(Entity currentEntity : Globals.entityManager.getBoneAttachedEntities()){ Entity parent; if((parent = (Entity)currentEntity.getData(EntityDataStrings.ATTACH_PARENT))!=null){ String targetBone; @@ -68,4 +68,24 @@ public class AttachUtils { public static Entity getParent(Entity e){ 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 getChildrenList(Entity e){ + return (LinkedList)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 childrenEntities = new LinkedList(); + childrenEntities.add(child); + parent.putData(EntityDataStrings.ATTACH_CHILDREN_LIST, childrenEntities); + } + } } diff --git a/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java b/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java index 5c4b9c7e..b10ae263 100644 --- a/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java +++ b/src/main/java/electrosphere/entity/types/collision/CollisionObjUtils.java @@ -4,6 +4,7 @@ import electrosphere.collision.dispatch.CollisionObject; import electrosphere.collision.shapes.CylinderShape; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.types.attach.AttachUtils; import electrosphere.game.collision.PhysicsUtils; import electrosphere.game.collision.collidable.Collidable; 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; + } } diff --git a/src/main/java/electrosphere/entity/types/structure/StructureUtils.java b/src/main/java/electrosphere/entity/types/structure/StructureUtils.java index 2698eb20..6d01289f 100644 --- a/src/main/java/electrosphere/entity/types/structure/StructureUtils.java +++ b/src/main/java/electrosphere/entity/types/structure/StructureUtils.java @@ -35,7 +35,7 @@ public class StructureUtils { 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); 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); // Globals.collisionEngine.registerPhysicsEntity(rVal); // Globals.collisionEngine.registerCollisionObject(rigidBody, collidable); diff --git a/src/main/java/electrosphere/game/client/cells/DrawCell.java b/src/main/java/electrosphere/game/client/cells/DrawCell.java index 835fc5e9..8ec023ea 100644 --- a/src/main/java/electrosphere/game/client/cells/DrawCell.java +++ b/src/main/java/electrosphere/game/client/cells/DrawCell.java @@ -3,6 +3,7 @@ package electrosphere.game.client.cells; import electrosphere.collision.dispatch.CollisionObject; import electrosphere.dynamics.RigidBody; import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.game.collision.PhysicsUtils; import electrosphere.game.collision.collidable.Collidable; @@ -85,6 +86,7 @@ public class DrawCell { Model terrainModel = ModelUtils.createTerrainModelPrecomputedShader(heightmap, program, stride); String terrainModelPath = Globals.assetManager.registerModel(terrainModel); modelEntity = EntityUtils.spawnDrawableEntity(terrainModelPath); + modelEntity.putData(EntityDataStrings.TERRAIN_IS_TERRAIN, true); LoggerInterface.loggerRenderer.INFO("New cell @ " + cellX * dynamicInterpolationRatio + "," + cellY * dynamicInterpolationRatio); EntityUtils.getPosition(modelEntity).set(new Vector3f(cellX * dynamicInterpolationRatio, 0.0f, cellY * dynamicInterpolationRatio)); } diff --git a/src/main/java/electrosphere/game/client/cells/DrawCellManager.java b/src/main/java/electrosphere/game/client/cells/DrawCellManager.java index 078535af..0613fac3 100644 --- a/src/main/java/electrosphere/game/client/cells/DrawCellManager.java +++ b/src/main/java/electrosphere/game/client/cells/DrawCellManager.java @@ -638,6 +638,10 @@ public class DrawCellManager { return rVal; } + public boolean coordsInPhysicsSpace(int worldX, int worldY){ + return worldX <= cellX + physicsRadius && worldX >= cellX - physicsRadius && worldY <= cellY + physicsRadius && worldY >= cellY - physicsRadius; + } + // public } diff --git a/src/main/java/electrosphere/game/client/player/ClientPlayerData.java b/src/main/java/electrosphere/game/client/player/ClientPlayerData.java index 45827421..ae53e958 100644 --- a/src/main/java/electrosphere/game/client/player/ClientPlayerData.java +++ b/src/main/java/electrosphere/game/client/player/ClientPlayerData.java @@ -3,8 +3,8 @@ package electrosphere.game.client.player; import electrosphere.logger.LoggerInterface; public class ClientPlayerData { - int initialDiscretePositionX; - int initialDiscretePositionY; + int worldPositionX; + int worldPositionY; int simulationRadius = 3; boolean loaded = false; @@ -16,19 +16,19 @@ public class ClientPlayerData { return loaded; } - public void setInitialDiscretePosition(int x, int y){ - initialDiscretePositionX = x; - initialDiscretePositionY = y; + public void setWorldPosition(int x, int y){ + worldPositionX = x; + worldPositionY = y; LoggerInterface.loggerGameLogic.INFO("Loaded client data"); loaded = true; } - public int getInitialDiscretePositionX() { - return initialDiscretePositionX; + public int getWorldPositionX() { + return worldPositionX; } - public int getInitialDiscretePositionY() { - return initialDiscretePositionY; + public int getWorldPositionY() { + return worldPositionY; } diff --git a/src/main/java/electrosphere/game/collision/CommonWorldData.java b/src/main/java/electrosphere/game/collision/CommonWorldData.java index 1acef14e..56e058f6 100644 --- a/src/main/java/electrosphere/game/collision/CommonWorldData.java +++ b/src/main/java/electrosphere/game/collision/CommonWorldData.java @@ -70,4 +70,12 @@ public class CommonWorldData { return serverWorldData.getWorldBoundMax(); } } + + public int convertRealToWorld(float real){ + if(clientWorldData != null){ + return clientWorldData.convertRealToChunkSpace(real); + } else { + return serverWorldData.convertRealToChunkSpace(real); + } + } } diff --git a/src/main/java/electrosphere/game/server/world/datacell/DataCellManager.java b/src/main/java/electrosphere/game/server/world/datacell/DataCellManager.java index cccb39c3..63ccc037 100644 --- a/src/main/java/electrosphere/game/server/world/datacell/DataCellManager.java +++ b/src/main/java/electrosphere/game/server/world/datacell/DataCellManager.java @@ -129,5 +129,8 @@ public class DataCellManager { } } + public void unloadPlayerlessChunks(){ + + } } diff --git a/src/main/java/electrosphere/game/state/MicroSimulation.java b/src/main/java/electrosphere/game/state/MicroSimulation.java index f5d4cb2c..19872d52 100644 --- a/src/main/java/electrosphere/game/state/MicroSimulation.java +++ b/src/main/java/electrosphere/game/state/MicroSimulation.java @@ -98,9 +98,14 @@ public class MicroSimulation { } //clear collidable impulse lists 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 if(Globals.dataCellManager != null){ Globals.dataCellManager.updatePlayerPositions(); + Globals.dataCellManager.unloadPlayerlessChunks(); } } diff --git a/src/main/java/electrosphere/net/client/ClientProtocol.java b/src/main/java/electrosphere/net/client/ClientProtocol.java index 06e27bc5..080caa4c 100644 --- a/src/main/java/electrosphere/net/client/ClientProtocol.java +++ b/src/main/java/electrosphere/net/client/ClientProtocol.java @@ -120,7 +120,7 @@ public class ClientProtocol { LoggerInterface.loggerNetworking.DEBUG("Player ID is " + Main.playerId); break; case SETINITIALDISCRETEPOSITION: - Globals.clientPlayerData.setInitialDiscretePosition(message.getinitialDiscretePositionX(), message.getinitialDiscretePositionY()); + Globals.clientPlayerData.setWorldPosition(message.getinitialDiscretePositionX(), message.getinitialDiscretePositionY()); break; } } diff --git a/src/main/java/electrosphere/renderer/RenderingEngine.java b/src/main/java/electrosphere/renderer/RenderingEngine.java index 397d88c9..f44f290d 100644 --- a/src/main/java/electrosphere/renderer/RenderingEngine.java +++ b/src/main/java/electrosphere/renderer/RenderingEngine.java @@ -245,16 +245,18 @@ public class RenderingEngine { // modelTransformMatrix = new Matrix4f(); for(Entity currentEntity : Globals.entityManager.getDrawable()){ - //fetch actor - Actor currentActor = EntityUtils.getActor(currentEntity); - //calculate and apply model transform - modelTransformMatrix.identity(); - modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); - modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); - modelTransformMatrix.scale(EntityUtils.getScale(currentEntity)); - currentActor.applyModelMatrix(modelTransformMatrix); - //draw - currentActor.drawForDepthBuffer(); + if((boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){ + //fetch actor + Actor currentActor = EntityUtils.getActor(currentEntity); + //calculate and apply model transform + modelTransformMatrix.identity(); + modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); + modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); + modelTransformMatrix.scale(EntityUtils.getScale(currentEntity)); + currentActor.applyModelMatrix(modelTransformMatrix); + //draw + currentActor.drawForDepthBuffer(); + } } @@ -292,43 +294,67 @@ public class RenderingEngine { // modelTransformMatrix = new Matrix4f(); for(Entity currentEntity : Globals.entityManager.getDrawable()){ - //fetch actor - Actor currentActor = EntityUtils.getActor(currentEntity); - currentActor.incrementAnimationTime(0.001); - //increment animations - //this is incremented in the shadow calculations -// if(currentActor.getCurrentAnimation() != null){ -// currentActor.incrementAnimationTime(deltaTime * 500); -// } - //calculate and apply model transform - modelTransformMatrix.identity(); - modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); - modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); - modelTransformMatrix.scale(EntityUtils.getScale(currentEntity)); - currentActor.applyModelMatrix(modelTransformMatrix); - //draw - currentActor.draw(); + if((boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){ + //fetch actor + Actor currentActor = EntityUtils.getActor(currentEntity); + currentActor.incrementAnimationTime(0.001); + //increment animations + //this is incremented in the shadow calculations + // if(currentActor.getCurrentAnimation() != null){ + // currentActor.incrementAnimationTime(deltaTime * 500); + // } + //calculate and apply model transform + modelTransformMatrix.identity(); + modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); + modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); + modelTransformMatrix.scale(EntityUtils.getScale(currentEntity)); + currentActor.applyModelMatrix(modelTransformMatrix); + //draw + currentActor.draw(); -// Model currentModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(currentEntity)); -// if(currentModel != null){ -// if(currentModel.currentAnimation != null){ -// currentModel.incrementTime(deltaTime * 500); -// } -// 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.rotate(EntityUtils.getEntityRotation(currentEntity)); -// currentModel.modelMatrix.scale(EntityUtils.getEntityScale(currentEntity)); -// currentModel.draw(); -// } + // Model currentModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(currentEntity)); + // if(currentModel != null){ + // if(currentModel.currentAnimation != null){ + // currentModel.incrementTime(deltaTime * 500); + // } + // 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.rotate(EntityUtils.getEntityRotation(currentEntity)); + // currentModel.modelMatrix.scale(EntityUtils.getEntityScale(currentEntity)); + // currentModel.draw(); + // } + } } if(renderHitboxes){ for(Entity currentHitbox : Globals.hitboxManager.getAllHitboxes()){ - Model hitboxModel; - HitboxData data = HitboxUtils.getHitboxData(currentHitbox); - if(data.isActive()){ - if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){ - if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){ + if((boolean)currentHitbox.getData(EntityDataStrings.DATA_STRING_DRAW)){ + Model hitboxModel; + HitboxData data = HitboxUtils.getHitboxData(currentHitbox); + if(data.isActive()){ + 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); modelTransformMatrix.identity(); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); @@ -337,26 +363,6 @@ public class RenderingEngine { 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); - 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){ Model physicsGraphicsModel; for(Entity physicsEntity : Globals.collisionEngine.getDynamicPhysicsEntities()){ - PhysicsObject template = (PhysicsObject)physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE); - switch(template.getType()){ - case "CYLINDER": - if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){ - Vector3f position = EntityUtils.getPosition(physicsEntity); - modelTransformMatrix.identity(); - modelTransformMatrix.translate(new Vector3f(position).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); -// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere - modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3()); - physicsGraphicsModel.modelMatrix = modelTransformMatrix; - physicsGraphicsModel.draw(true, true, false, true, true, true, true); - } - break; + if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){ + PhysicsObject template = (PhysicsObject)physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE); + switch(template.getType()){ + case "CYLINDER": + if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){ + Vector3f position = EntityUtils.getPosition(physicsEntity); + modelTransformMatrix.identity(); + modelTransformMatrix.translate(new Vector3f(position).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); + // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere + modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3()); + physicsGraphicsModel.modelMatrix = modelTransformMatrix; + physicsGraphicsModel.draw(true, true, false, true, true, true, true); + } + break; + } } } for(Entity physicsEntity : Globals.collisionEngine.getStructurePhysicsEntities()){ - if(physicsEntity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE)){ - if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitplane.fbx")) != null){ - Vector3f position = EntityUtils.getPosition(physicsEntity); - Vector3f scale = EntityUtils.getScale(physicsEntity); - Quaternionf rotation = EntityUtils.getRotation(physicsEntity); - modelTransformMatrix.identity(); - modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); - modelTransformMatrix.rotate(rotation); -// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere - modelTransformMatrix.scale(scale); - 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){ - Vector3f position = EntityUtils.getPosition(physicsEntity); - Vector3f scale = EntityUtils.getScale(physicsEntity); - Quaternionf rotation = EntityUtils.getRotation(physicsEntity); - modelTransformMatrix.identity(); - modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); - modelTransformMatrix.rotate(rotation); -// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere - modelTransformMatrix.scale(scale); - physicsGraphicsModel.modelMatrix = modelTransformMatrix; - physicsGraphicsModel.draw(true, true, false, true, true, true, true); + if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){ + if(physicsEntity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE)){ + if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitplane.fbx")) != null){ + Vector3f position = EntityUtils.getPosition(physicsEntity); + Vector3f scale = EntityUtils.getScale(physicsEntity); + Quaternionf rotation = EntityUtils.getRotation(physicsEntity); + modelTransformMatrix.identity(); + modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); + modelTransformMatrix.rotate(rotation); + // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere + modelTransformMatrix.scale(scale); + 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){ + Vector3f position = EntityUtils.getPosition(physicsEntity); + Vector3f scale = EntityUtils.getScale(physicsEntity); + Quaternionf rotation = EntityUtils.getRotation(physicsEntity); + modelTransformMatrix.identity(); + modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera))); + modelTransformMatrix.rotate(rotation); + // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere + modelTransformMatrix.scale(scale); + physicsGraphicsModel.modelMatrix = modelTransformMatrix; + physicsGraphicsModel.draw(true, true, false, true, true, true, true); + } } } }