Client side entity instancing
This commit is contained in:
parent
e18e342492
commit
3a1924f8f4
@ -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()
|
||||
);
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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<Entity> lightList = new CopyOnWriteArrayList();
|
||||
static CopyOnWriteArrayList<Entity> uiList = 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> creatureList = new CopyOnWriteArrayList();
|
||||
static CopyOnWriteArrayList<Entity> 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<Entity> getAttachedEntities(){
|
||||
return attachList;
|
||||
public CopyOnWriteArrayList<Entity> 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<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){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<Entity> 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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,5 +129,8 @@ public class DataCellManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadPlayerlessChunks(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user