diff --git a/assets/Models/cloudRing.fbx b/assets/Models/cloudRing.fbx new file mode 100644 index 00000000..f4d5611d Binary files /dev/null and b/assets/Models/cloudRing.fbx differ diff --git a/assets/Textures/cloudRing.png b/assets/Textures/cloudRing.png new file mode 100644 index 00000000..41dde5bb Binary files /dev/null and b/assets/Textures/cloudRing.png differ diff --git a/assets/Textures/default_texture_map.json b/assets/Textures/default_texture_map.json index c7abe1cf..48ab4793 100644 --- a/assets/Textures/default_texture_map.json +++ b/assets/Textures/default_texture_map.json @@ -239,6 +239,12 @@ "/Textures/shirt1.png", "/Textures/shirt1.png" ] + }, + "Models/cloudRing.fbx" : { + "Sphere" : [ + "/Textures/cloudRing.png", + "/Textures/cloudRing.png" + ] } } } \ No newline at end of file diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java index 15367f41..5aab4be6 100644 --- a/src/main/java/electrosphere/controls/ControlHandler.java +++ b/src/main/java/electrosphere/controls/ControlHandler.java @@ -36,6 +36,8 @@ public class ControlHandler { public static final String DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD = "moveBackward"; public static final String DATA_STRING_INPUT_CODE_MOVEMENT_LEFT = "moveLeft"; public static final String DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT = "moveRight"; + public static final String DATA_STRING_INPUT_CODE_STRAFE_LEFT = "strafeLeft"; + public static final String DATA_STRING_INPUT_CODE_STRAFE_RIGHT = "strafeRight"; public static final String DATA_STRING_INPUT_CODE_MOVEMENT_JUMP = "jump"; public static final String DATA_STRING_INPUT_CODE_MOVEMENT_FALL = "fall"; public static final String DATA_STRING_INPUT_CODE_ATTACK_PRIMARY = "attackPrimary"; @@ -122,8 +124,10 @@ public class ControlHandler { */ handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, new Control(true,false,GLFW_KEY_W)); handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, new Control(true,false,GLFW_KEY_S)); - handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, new Control(true,false,GLFW_KEY_A)); - handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, new Control(true,false,GLFW_KEY_D)); + handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, new Control(true,false,GLFW_KEY_F24)); + handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, new Control(true,false,GLFW_KEY_F24)); + handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_LEFT, new Control(true,false,GLFW_KEY_A)); + handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_RIGHT, new Control(true,false,GLFW_KEY_D)); handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, new Control(true,false,GLFW_KEY_SPACE)); handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, new Control(true,false,GLFW_KEY_LEFT_CONTROL)); handler.addControl(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY, new Control(false,true,GLFW_MOUSE_BUTTON_LEFT)); @@ -381,13 +385,75 @@ public class ControlHandler { Move up */ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP) && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP).getKeyValue())){ - EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,0.6f,0).mul(1f)); + // EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,0.6f,0).mul(1f)); } /* Move down */ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FALL) && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FALL).getKeyValue())){ - EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,-0.6f,0).mul(1f)); + // EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,-0.6f,0).mul(1f)); + } + /* + Strafe left + */ + if(controls.containsKey(DATA_STRING_INPUT_CODE_STRAFE_LEFT)){ + if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).getKeyValue())){ + CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize()); + if( + (movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) && + (controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && + (controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())) + ){ + movementTree.start(MovementRelativeFacing.FORWARD); + } + controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setState(true); + //send to server +// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter); +// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage( +// Globals.playerCharacter.getId(), +// System.currentTimeMillis(), +// position.x, +// position.y, +// position.z +// ); +// Globals.clientConnection.queueOutgoingMessage(outgoingMessage); + } else { + if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState() == true){ + movementTree.slowdown(); + } + controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setState(false); + } + } + /* + Strafe right + */ + if(controls.containsKey(DATA_STRING_INPUT_CODE_STRAFE_RIGHT)){ + if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).getKeyValue())){ + CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize()); + if( + (movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) && + (controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && + (controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())) + ){ + movementTree.start(MovementRelativeFacing.FORWARD); + } + controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setState(true); + //send to server +// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter); +// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage( +// Globals.playerCharacter.getId(), +// System.currentTimeMillis(), +// position.x, +// position.y, +// position.z +// ); +// Globals.clientConnection.queueOutgoingMessage(outgoingMessage); + } else { + if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isState() == true){ + movementTree.slowdown(); + } + controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setState(false); + } } /* Sprint diff --git a/src/main/java/electrosphere/engine/LoadingThread.java b/src/main/java/electrosphere/engine/LoadingThread.java index 74146a91..89d8f574 100644 --- a/src/main/java/electrosphere/engine/LoadingThread.java +++ b/src/main/java/electrosphere/engine/LoadingThread.java @@ -480,30 +480,51 @@ public class LoadingThread extends Thread { } + static void initGameGraphicalEntities(){ - static void initArenaGraphicalEntities(){ - Globals.skyboxColors.add(new Vector3f(150,200,250)); - Globals.skyboxColors.add(new Vector3f(150,200,250)); - Globals.skyboxColors.add(new Vector3f(20,20,20)); - Globals.skyboxColors.add(new Vector3f(20,20,20)); - Globals.skyboxColors.add(new Vector3f(150,200,250)); - Globals.skyboxColors.add(new Vector3f(150,200,250)); - Globals.skyboxColors.add(new Vector3f(20,20,20)); - Globals.skyboxColors.add(new Vector3f(20,20,20)); + float skyR = 100; + float skyG = 150; + float skyB = 200; + + float groundR = 50; + float groundG = 100; + float groundB = 150; + + Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB)); + Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB)); + Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB)); + Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB)); + Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB)); + Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB)); + Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB)); + Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB)); } - static void initGameGraphicalEntities(){ - Globals.skyboxColors.add(new Vector3f(100,150,200)); - Globals.skyboxColors.add(new Vector3f(100,150,200)); - Globals.skyboxColors.add(new Vector3f(50,100,150)); - Globals.skyboxColors.add(new Vector3f(50,100,150)); - Globals.skyboxColors.add(new Vector3f(100,150,200)); - Globals.skyboxColors.add(new Vector3f(100,150,200)); - Globals.skyboxColors.add(new Vector3f(50,100,150)); - Globals.skyboxColors.add(new Vector3f(50,100,150)); + static void initArenaGraphicalEntities(){ + + float skyR = 150; + float skyG = 200; + float skyB = 250; + + float groundR = 20; + float groundG = 20; + float groundB = 20; + + Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB)); + Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB)); + Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB)); + Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB)); + Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB)); + Globals.skyboxColors.add(new Vector3f(skyR,skyG,skyB)); + Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB)); + Globals.skyboxColors.add(new Vector3f(groundR,groundG,groundB)); + + Entity cloudRing = EntityUtils.spawnDrawableEntity("Models/cloudRing.fbx"); + EntityUtils.getRotation(cloudRing).rotateX((float)(-Math.PI/2.0f)); + EntityUtils.getScale(cloudRing).mul(1000.0f); } diff --git a/src/main/java/electrosphere/entity/EntityManager.java b/src/main/java/electrosphere/entity/EntityManager.java index 6aa17312..7882d2bc 100644 --- a/src/main/java/electrosphere/entity/EntityManager.java +++ b/src/main/java/electrosphere/entity/EntityManager.java @@ -1,5 +1,6 @@ package electrosphere.entity; +import electrosphere.entity.state.BehaviorTree; import electrosphere.entity.types.attach.AttachUtils; import electrosphere.logger.LoggerInterface; import electrosphere.main.Globals; @@ -33,6 +34,8 @@ public class EntityManager { static CopyOnWriteArrayList collidableList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList targetableList = new CopyOnWriteArrayList(); static CopyOnWriteArrayList sprintableList = new CopyOnWriteArrayList(); + + static CopyOnWriteArrayList behaviorTreeList = new CopyOnWriteArrayList(); public EntityManager(){ diff --git a/src/main/java/electrosphere/entity/state/ApplyRotationTree.java b/src/main/java/electrosphere/entity/state/ApplyRotationTree.java new file mode 100644 index 00000000..a3d68327 --- /dev/null +++ b/src/main/java/electrosphere/entity/state/ApplyRotationTree.java @@ -0,0 +1,47 @@ +package electrosphere.entity.state; + +import org.joml.Quaterniond; +import org.joml.Quaternionf; + +import electrosphere.entity.Entity; +import electrosphere.entity.EntityUtils; + +public class ApplyRotationTree implements BehaviorTree { + + public static enum ApplyRotationTreeState { + ROTATE, + NO_ROTATE, + } + + + Quaternionf rotationToApply; + Entity parent; + ApplyRotationTreeState state; + + public ApplyRotationTree(Entity parent, Quaternionf rotationToApply){ + this.parent = parent; + this.rotationToApply = rotationToApply; + } + + public void start(){ + state = ApplyRotationTreeState.ROTATE; + } + + public void stop(){ + state = ApplyRotationTreeState.NO_ROTATE; + } + + @Override + public void simulate(){ + switch(state){ + case ROTATE: + EntityUtils.getRotation(parent).slerp(rotationToApply, 1.0f); + break; + case NO_ROTATE: + break; + } + } + + + +} diff --git a/src/main/java/electrosphere/entity/state/BehaviorTree.java b/src/main/java/electrosphere/entity/state/BehaviorTree.java new file mode 100644 index 00000000..dafceb05 --- /dev/null +++ b/src/main/java/electrosphere/entity/state/BehaviorTree.java @@ -0,0 +1,7 @@ +package electrosphere.entity.state; + +public interface BehaviorTree { + + public void simulate(); + +} diff --git a/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java index 3e7f1bc5..bea4b644 100644 --- a/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java @@ -118,6 +118,7 @@ public class GroundMovementTree { Vector3d movementVector = new Vector3d(facingVector); switch(facing){ case FORWARD: + movementVector.normalize(); break; case LEFT: movementVector.rotateY((float)(90 * Math.PI / 180)).normalize(); @@ -128,6 +129,7 @@ public class GroundMovementTree { case BACKWARD: movementVector.x = -movementVector.x; movementVector.z = -movementVector.z; + movementVector.normalize(); break; case FORWARD_LEFT: movementVector.rotateY((float)(45 * Math.PI / 180)).normalize(); @@ -211,14 +213,12 @@ public class GroundMovementTree { break; } } - + + // System.out.println(movementVector + " " + velocity * Main.deltaTime); //state machine switch(state){ case STARTUP: - //run startup code - velocity = velocity + acceleration * Main.deltaTime; - CreatureUtils.setVelocity(parent, velocity); if(entityActor != null){ String animationToPlay = determineCorrectAnimation(); if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationToPlay)){ @@ -226,11 +226,14 @@ public class GroundMovementTree { entityActor.incrementAnimationTime(0.01); } } + //run startup code + velocity = velocity + acceleration * Main.deltaTime; //check if can transition state if(velocity >= maxNaturalVelocity){ velocity = maxNaturalVelocity; state = MovementTreeState.MOVE; } + CreatureUtils.setVelocity(parent, velocity); // body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector.x,0,movementVector.z).normalize().mul(velocity))); EntityUtils.getRotation(parent).set(movementQuaternion); // //move the entity @@ -306,6 +309,7 @@ public class GroundMovementTree { } if(velocity != maxNaturalVelocity){ velocity = maxNaturalVelocity; + CreatureUtils.setVelocity(parent, velocity); } // body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(force)); EntityUtils.getRotation(parent).set(movementQuaternion); @@ -371,8 +375,6 @@ public class GroundMovementTree { break; case SLOWDOWN: //run slowdown code - velocity = velocity - acceleration * Main.deltaTime; - CreatureUtils.setVelocity(parent, velocity); if(entityActor != null){ String animationToPlay = determineCorrectAnimation(); if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationToPlay)){ @@ -380,11 +382,20 @@ public class GroundMovementTree { entityActor.incrementAnimationTime(0.01); } } + //velocity stuff + velocity = velocity - acceleration * Main.deltaTime; //check if can transition state if(velocity <= 0){ velocity = 0; state = MovementTreeState.IDLE; + if(entityActor != null){ + String animationToPlay = determineCorrectAnimation(); + if(entityActor.isPlayingAnimation() && entityActor.isPlayingAnimation(animationToPlay)){ + entityActor.stopAnimation(animationToPlay); + } + } } + CreatureUtils.setVelocity(parent, velocity); // body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector).mul(-1.0f).normalize().mul(velocity))); EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,(float)movementVector.y,(float)movementVector.z)); //move the entity @@ -448,12 +459,7 @@ public class GroundMovementTree { break; case IDLE: // body.clearForces(); - if(entityActor != null){ - String animationToPlay = determineCorrectAnimation(); - if(entityActor.isPlayingAnimation() && entityActor.isPlayingAnimation(animationToPlay)){ - entityActor.stopAnimation(animationToPlay); - } - } + // if(Globals.collisionEngine.gravityCheck(Globals.commonWorldData, parent)){ // position.set(Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData,parent,new Vector3f(position.x,position.y - 9.8f,position.z))); // } diff --git a/src/main/java/electrosphere/game/server/datacell/DataCellManager.java b/src/main/java/electrosphere/game/server/datacell/DataCellManager.java index 4eb487ae..da0e9c6b 100644 --- a/src/main/java/electrosphere/game/server/datacell/DataCellManager.java +++ b/src/main/java/electrosphere/game/server/datacell/DataCellManager.java @@ -129,7 +129,13 @@ public class DataCellManager { } public void sendNetworkMessageToChunk(NetworkMessage message, int worldX, int worldY){ - if(dataCells[worldX][worldY] != null){ + if( + //in bounds of array + worldX >= 0 && worldX < dataCells.length && + worldY >= 0 && worldY < dataCells[0].length && + //isn't null + dataCells[worldX][worldY] != null + ){ dataCells[worldX][worldY].broadcastNetworkMessage(message); } } diff --git a/src/main/java/electrosphere/renderer/Mesh.java b/src/main/java/electrosphere/renderer/Mesh.java index 3e5c7397..72bdfe21 100644 --- a/src/main/java/electrosphere/renderer/Mesh.java +++ b/src/main/java/electrosphere/renderer/Mesh.java @@ -740,14 +740,14 @@ public class Mesh { temp[2] = lightLoc.z; glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.direction"), temp); + temp[0] = 0.4f; + temp[1] = 0.4f; + temp[2] = 0.4f; + glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.ambient"), temp); + temp[0] = 0.3f; temp[1] = 0.3f; temp[2] = 0.3f; - glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.ambient"), temp); - - temp[0] = 0.5f; - temp[1] = 0.5f; - temp[2] = 0.5f; glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.diffuse"), temp); temp[0] = 0.1f;