Behavior trees, Cell management, new humanoid model, animations,
generally a lot of shit
This commit is contained in:
parent
0f8609079a
commit
f684d1c722
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
|
|
||||||
/src/main/resources/Config/terrain.json
|
/src/main/resources/Config/terrain.json
|
||||||
/src/main/resources/Config/localconfig.json
|
/src/main/resources/Config/localconfig.json
|
||||||
|
/src/main/resources/Config/keybinds.json
|
||||||
|
|||||||
@ -30,7 +30,14 @@ public class MainConfig {
|
|||||||
//
|
//
|
||||||
//Networking related
|
//Networking related
|
||||||
//
|
//
|
||||||
|
//should we run a server at all?
|
||||||
public boolean runServer;
|
public boolean runServer;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//Rendering related
|
||||||
|
//
|
||||||
|
//should the renderer run at all?
|
||||||
public boolean runRenderer;
|
public boolean runRenderer;
|
||||||
|
|
||||||
|
|
||||||
@ -45,6 +52,9 @@ public class MainConfig {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a localconfig.json and save it to our resources dir
|
||||||
|
*/
|
||||||
public static void generateMainConfig(){
|
public static void generateMainConfig(){
|
||||||
System.out.println("localconfig.json either doesn't exist or is out of date");
|
System.out.println("localconfig.json either doesn't exist or is out of date");
|
||||||
System.out.println("Would you like to generate a new one?(1-y/0-n)");
|
System.out.println("Would you like to generate a new one?(1-y/0-n)");
|
||||||
|
|||||||
174
src/main/java/electrosphere/controls/ControlHandler.java
Normal file
174
src/main/java/electrosphere/controls/ControlHandler.java
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
package electrosphere.controls;
|
||||||
|
|
||||||
|
import electrosphere.entity.CreatureUtils;
|
||||||
|
import electrosphere.entity.EntityUtil;
|
||||||
|
import electrosphere.entity.state.MovementTree;
|
||||||
|
import electrosphere.entity.state.MovementTree.MovementTreeState;
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
import static electrosphere.main.Main.camera_Current;
|
||||||
|
import electrosphere.util.Utilities;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_A;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_D;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_CONTROL;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_S;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_PRESS;
|
||||||
|
import static org.lwjgl.glfw.GLFW.glfwGetKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author amaterasu
|
||||||
|
*/
|
||||||
|
public class ControlHandler {
|
||||||
|
|
||||||
|
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD = "moveForward";
|
||||||
|
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_MOVEMENT_JUMP = "jump";
|
||||||
|
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_FALL = "fall";
|
||||||
|
|
||||||
|
|
||||||
|
HashMap<String, Integer> controlsMap;
|
||||||
|
HashMap<String, Boolean> controlsState;
|
||||||
|
|
||||||
|
ControlHandler(){
|
||||||
|
controlsMap = new HashMap();
|
||||||
|
controlsState = new HashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void generateExampleControlsMap(){
|
||||||
|
ControlHandler handler = new ControlHandler();
|
||||||
|
/*
|
||||||
|
Map the controls
|
||||||
|
*/
|
||||||
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, GLFW_KEY_W);
|
||||||
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, GLFW_KEY_S);
|
||||||
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, GLFW_KEY_A);
|
||||||
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, GLFW_KEY_D);
|
||||||
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, GLFW_KEY_SPACE);
|
||||||
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, GLFW_KEY_LEFT_CONTROL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Set their states to false(not pressed)
|
||||||
|
*/
|
||||||
|
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, false);
|
||||||
|
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, false);
|
||||||
|
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, false);
|
||||||
|
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, false);
|
||||||
|
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, false);
|
||||||
|
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, false);
|
||||||
|
Utilities.saveObjectToJsonFile("/Config/keybinds.json", handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void pollControls(){
|
||||||
|
MovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||||
|
/*
|
||||||
|
Move forward
|
||||||
|
*/
|
||||||
|
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)){
|
||||||
|
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)) == GLFW_PRESS){
|
||||||
|
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-camera_Current.pos_Center.x,0,-camera_Current.pos_Center.z).normalize());
|
||||||
|
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
|
||||||
|
movementTree.start();
|
||||||
|
}
|
||||||
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, true);
|
||||||
|
} else {
|
||||||
|
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD) == true){
|
||||||
|
movementTree.slowdown();
|
||||||
|
}
|
||||||
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Move backward
|
||||||
|
*/
|
||||||
|
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)){
|
||||||
|
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)) == GLFW_PRESS){
|
||||||
|
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(camera_Current.pos_Center.x,0,camera_Current.pos_Center.z).normalize());
|
||||||
|
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
|
||||||
|
movementTree.start();
|
||||||
|
}
|
||||||
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, true);
|
||||||
|
} else {
|
||||||
|
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD) == true){
|
||||||
|
movementTree.slowdown();
|
||||||
|
}
|
||||||
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Move left
|
||||||
|
*/
|
||||||
|
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)){
|
||||||
|
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)) == GLFW_PRESS){
|
||||||
|
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-camera_Current.pos_Center.x,0,-camera_Current.pos_Center.z).rotateY((float)(90 * Math.PI / 180)).normalize());
|
||||||
|
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
|
||||||
|
movementTree.start();
|
||||||
|
}
|
||||||
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, true);
|
||||||
|
} else {
|
||||||
|
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT) == true){
|
||||||
|
movementTree.slowdown();
|
||||||
|
}
|
||||||
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Move right
|
||||||
|
*/
|
||||||
|
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)){
|
||||||
|
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)) == GLFW_PRESS){
|
||||||
|
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-camera_Current.pos_Center.x,0,-camera_Current.pos_Center.z).rotateY((float)(-90 * Math.PI / 180)).normalize());
|
||||||
|
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
|
||||||
|
movementTree.start();
|
||||||
|
}
|
||||||
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, true);
|
||||||
|
} else {
|
||||||
|
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT) == true){
|
||||||
|
movementTree.slowdown();
|
||||||
|
}
|
||||||
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Move up
|
||||||
|
*/
|
||||||
|
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP) && glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP)) == GLFW_PRESS){
|
||||||
|
EntityUtil.getEntityPosition(Globals.playerCharacter).add(new Vector3f(0,0.6f,0).mul(1f));
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Move down
|
||||||
|
*/
|
||||||
|
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FALL) && glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FALL)) == GLFW_PRESS){
|
||||||
|
EntityUtil.getEntityPosition(Globals.playerCharacter).add(new Vector3f(0,-0.6f,0).mul(1f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getControl(String controlName){
|
||||||
|
return controlsMap.get(controlName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsControl(String controlName){
|
||||||
|
return controlsMap.containsKey(controlName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeControl(String controlName){
|
||||||
|
controlsMap.remove(controlName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addControl(String controlName, int keyCode){
|
||||||
|
controlsMap.put(controlName, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addControlState(String controlName, boolean state){
|
||||||
|
controlsState.put(controlName,state);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
60
src/main/java/electrosphere/entity/CameraEntityUtils.java
Normal file
60
src/main/java/electrosphere/entity/CameraEntityUtils.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package electrosphere.entity;
|
||||||
|
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author amaterasu
|
||||||
|
*/
|
||||||
|
public class CameraEntityUtils {
|
||||||
|
|
||||||
|
|
||||||
|
public static Entity spawnBasicCameraEntity(Vector3f position){
|
||||||
|
Entity rVal = new Entity();
|
||||||
|
Globals.entityManager.registerEntity(rVal);
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Entity spawnOrbitalCameraEntity(Entity target, float distance){
|
||||||
|
Entity rVal = new Entity();
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT);
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_ORBIT_TARGET, target);
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_POSITION, new Vector3f(0,0,0));
|
||||||
|
rVal.putData(EntityDataStrings .DATA_STRING_CAMERA_ROTATION, new Quaternionf());
|
||||||
|
Globals.entityManager.registerEntity(rVal);
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Entity getOrbitalCameraTarget(Entity camera){
|
||||||
|
return (Entity)camera.getData(EntityDataStrings.DATA_STRING_CAMERA_ORBIT_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getOrbitalCameraDistance(Entity camera){
|
||||||
|
return (float)camera.getData(EntityDataStrings.DATA_STRING_CAMERA_ORBIT_DISTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCameraPosition(Entity camera, Vector3f position){
|
||||||
|
camera.putData(EntityDataStrings.DATA_STRING_CAMERA_POSITION, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3f getCameraPosition(Entity camera){
|
||||||
|
return (Vector3f)camera.getData(EntityDataStrings.DATA_STRING_CAMERA_POSITION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCameraRotation(Entity camera, Quaternionf rotation){
|
||||||
|
camera.putData(EntityDataStrings.DATA_STRING_CAMERA_ROTATION, rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Quaternionf getCameraRotation(Entity camera){
|
||||||
|
return (Quaternionf)camera.getData(EntityDataStrings.DATA_STRING_CAMERA_ROTATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void destroyCameraEntity(Entity e){
|
||||||
|
if(e != null){
|
||||||
|
Globals.entityManager.deregisterEntity(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
66
src/main/java/electrosphere/entity/CreatureUtils.java
Normal file
66
src/main/java/electrosphere/entity/CreatureUtils.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package electrosphere.entity;
|
||||||
|
|
||||||
|
import electrosphere.entity.state.MovementTree;
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
import electrosphere.renderer.Model;
|
||||||
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author amaterasu
|
||||||
|
*/
|
||||||
|
public class CreatureUtils {
|
||||||
|
public static Entity spawnBasicControllableEntity(Model m, float acceleration, float maxVelocity){
|
||||||
|
Entity rVal = new Entity();
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_MODEL, m);
|
||||||
|
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_MOVEMENT_BT, new MovementTree(rVal));
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,0));
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, maxVelocity);
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, acceleration);
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f);
|
||||||
|
Globals.entityManager.registerEntity(rVal);
|
||||||
|
Globals.entityManager.registerDrawableEntity(rVal);
|
||||||
|
Globals.entityManager.registerMoveableEntity(rVal);
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMovementVector(Entity e, Vector3f vector){
|
||||||
|
e.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, vector);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3f getMovementVector(Entity e){
|
||||||
|
return (Vector3f)e.getData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getAcceleration(Entity e){
|
||||||
|
return (float)e.getData(EntityDataStrings.DATA_STRING_ACCELERATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setAcceleration(Entity e, float scalar){
|
||||||
|
e.putData(EntityDataStrings.DATA_STRING_ACCELERATION, scalar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getVelocity(Entity e){
|
||||||
|
return (float)e.getData(EntityDataStrings.DATA_STRING_VELOCITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setVelocity(Entity e, float scalar){
|
||||||
|
e.putData(EntityDataStrings.DATA_STRING_VELOCITY, scalar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getMaxNaturalVelocity(Entity e){
|
||||||
|
return (float)e.getData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMaxNaturalVelocity(Entity e, float scalar){
|
||||||
|
e.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, scalar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MovementTree getEntityMovementTree(Entity e){
|
||||||
|
return (MovementTree)e.getData(EntityDataStrings.DATA_STRING_MOVEMENT_BT);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,3 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package electrosphere.entity;
|
package electrosphere.entity;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -15,6 +10,9 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class Entity {
|
public class Entity {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int entity_id_iterator = 0;
|
static int entity_id_iterator = 0;
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
|
|||||||
42
src/main/java/electrosphere/entity/EntityDataStrings.java
Normal file
42
src/main/java/electrosphere/entity/EntityDataStrings.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package electrosphere.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author amaterasu
|
||||||
|
*/
|
||||||
|
public class EntityDataStrings {
|
||||||
|
|
||||||
|
/*
|
||||||
|
Drawable Entity
|
||||||
|
*/
|
||||||
|
public static final String DATA_STRING_POSITION = "position";
|
||||||
|
public static final String DATA_STRING_ROTATION = "rotation";
|
||||||
|
public static final String DATA_STRING_SCALE = "scale";
|
||||||
|
public static final String DATA_STRING_MODEL = "model";
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Moveable Entity
|
||||||
|
*/
|
||||||
|
public static final String DATA_STRING_MOVEMENT_BT = "movementBT";
|
||||||
|
public static final String DATA_STRING_MOVEMENT_VECTOR = "movementVector";
|
||||||
|
public static final String DATA_STRING_VELOCITY = "velocity";
|
||||||
|
public static final String DATA_STRING_ACCELERATION = "acceleration";
|
||||||
|
public static final String DATA_STRING_MAX_NATURAL_VELOCITY = "velocityMaxNatural";
|
||||||
|
|
||||||
|
/*
|
||||||
|
All Camera Types
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static final String DATA_STRING_CAMERA_TYPE = "cameraType";
|
||||||
|
public static final String DATA_STRING_CAMERA_TYPE_ORBIT = "cameraTypeOrbit";
|
||||||
|
public static final String DATA_STRING_CAMERA_POSITION = "cameraPosition";
|
||||||
|
public static final String DATA_STRING_CAMERA_ROTATION = "cameraRotation";
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Orbital Camera
|
||||||
|
*/
|
||||||
|
public static final String DATA_STRING_CAMERA_ORBIT_TARGET = "cameraOrbitTarget";
|
||||||
|
public static final String DATA_STRING_CAMERA_ORBIT_DISTANCE = "cameraOrbitDistance";
|
||||||
|
}
|
||||||
@ -11,10 +11,12 @@ public class EntityManager {
|
|||||||
|
|
||||||
static CopyOnWriteArrayList<Entity> entityList;
|
static CopyOnWriteArrayList<Entity> entityList;
|
||||||
static CopyOnWriteArrayList<Entity> drawableList;
|
static CopyOnWriteArrayList<Entity> drawableList;
|
||||||
|
static CopyOnWriteArrayList<Entity> moveableList;
|
||||||
|
|
||||||
public EntityManager(){
|
public EntityManager(){
|
||||||
entityList = new CopyOnWriteArrayList();
|
entityList = new CopyOnWriteArrayList();
|
||||||
drawableList = new CopyOnWriteArrayList();
|
drawableList = new CopyOnWriteArrayList();
|
||||||
|
moveableList = new CopyOnWriteArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEntity(Entity e){
|
public void registerEntity(Entity e){
|
||||||
@ -29,6 +31,14 @@ public class EntityManager {
|
|||||||
return drawableList.iterator();
|
return drawableList.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerMoveableEntity(Entity e){
|
||||||
|
moveableList.add(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<Entity> getMoveableIterator(){
|
||||||
|
return moveableList.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
public void deregisterEntity(Entity e){
|
public void deregisterEntity(Entity e){
|
||||||
if(drawableList.contains(e)){
|
if(drawableList.contains(e)){
|
||||||
drawableList.remove(e);
|
drawableList.remove(e);
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package electrosphere.entity;
|
package electrosphere.entity;
|
||||||
|
|
||||||
|
import electrosphere.entity.state.MovementTree;
|
||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
@ -17,27 +18,27 @@ import org.joml.Vector3f;
|
|||||||
public class EntityUtil {
|
public class EntityUtil {
|
||||||
|
|
||||||
public static Vector3f getEntityPosition(Entity e){
|
public static Vector3f getEntityPosition(Entity e){
|
||||||
return (Vector3f)e.getData("position");
|
return (Vector3f)e.getData(EntityDataStrings.DATA_STRING_POSITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Quaternionf getEntityRotation(Entity e){
|
public static Quaternionf getEntityRotation(Entity e){
|
||||||
return (Quaternionf)e.getData("rotation");
|
return (Quaternionf)e.getData(EntityDataStrings.DATA_STRING_ROTATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3f getEntityScale(Entity e){
|
public static Vector3f getEntityScale(Entity e){
|
||||||
return (Vector3f)e.getData("scale");
|
return (Vector3f)e.getData(EntityDataStrings.DATA_STRING_SCALE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Model getEntityModel(Entity e){
|
public static Model getEntityModel(Entity e){
|
||||||
return (Model)e.getData("model");
|
return (Model)e.getData(EntityDataStrings.DATA_STRING_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entity spawnDrawableEntity(Model m){
|
public static Entity spawnDrawableEntity(Model m){
|
||||||
Entity rVal = new Entity();
|
Entity rVal = new Entity();
|
||||||
rVal.putData("model", m);
|
rVal.putData(EntityDataStrings.DATA_STRING_MODEL, m);
|
||||||
rVal.putData("position", new Vector3f(0,0,0));
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
|
||||||
rVal.putData("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("scale", new Vector3f(1,1,1));
|
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
|
||||||
Globals.entityManager.registerEntity(rVal);
|
Globals.entityManager.registerEntity(rVal);
|
||||||
Globals.entityManager.registerDrawableEntity(rVal);
|
Globals.entityManager.registerDrawableEntity(rVal);
|
||||||
return rVal;
|
return rVal;
|
||||||
|
|||||||
136
src/main/java/electrosphere/entity/state/MovementTree.java
Normal file
136
src/main/java/electrosphere/entity/state/MovementTree.java
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
package electrosphere.entity.state;
|
||||||
|
|
||||||
|
import electrosphere.entity.CreatureUtils;
|
||||||
|
import electrosphere.entity.Entity;
|
||||||
|
import electrosphere.entity.EntityUtil;
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
import electrosphere.renderer.Animation;
|
||||||
|
import electrosphere.renderer.Model;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author amaterasu
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
Behavior tree for movement in an entity
|
||||||
|
*/
|
||||||
|
public class MovementTree {
|
||||||
|
|
||||||
|
public static enum MovementTreeState {
|
||||||
|
STARTUP,
|
||||||
|
MOVE,
|
||||||
|
SLOWDOWN,
|
||||||
|
IDLE,
|
||||||
|
}
|
||||||
|
|
||||||
|
MovementTreeState state;
|
||||||
|
|
||||||
|
Entity parent;
|
||||||
|
|
||||||
|
public MovementTree(Entity e){
|
||||||
|
state = MovementTreeState.IDLE;
|
||||||
|
parent = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MovementTreeState getState(){
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start(){
|
||||||
|
//TODO: check if can start moving
|
||||||
|
state = MovementTreeState.STARTUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void interrupt(){
|
||||||
|
state = MovementTreeState.IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void slowdown(){
|
||||||
|
state = MovementTreeState.SLOWDOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transitionState(){
|
||||||
|
switch(state){
|
||||||
|
case STARTUP:
|
||||||
|
//transition if velocity >= acceleration
|
||||||
|
state = MovementTreeState.MOVE;
|
||||||
|
break;
|
||||||
|
case MOVE:
|
||||||
|
state = MovementTreeState.SLOWDOWN;
|
||||||
|
break;
|
||||||
|
case SLOWDOWN:
|
||||||
|
state = MovementTreeState.IDLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void simulate(){
|
||||||
|
float velocity = CreatureUtils.getVelocity(parent);
|
||||||
|
float acceleration = CreatureUtils.getAcceleration(parent);
|
||||||
|
float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent);
|
||||||
|
Model entityModel = EntityUtil.getEntityModel(parent);
|
||||||
|
Vector3f position = EntityUtil.getEntityPosition(parent);
|
||||||
|
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
||||||
|
System.out.println(movementVector);
|
||||||
|
switch(state){
|
||||||
|
case STARTUP:
|
||||||
|
//run startup code
|
||||||
|
velocity = velocity + acceleration;
|
||||||
|
CreatureUtils.setVelocity(parent, velocity);
|
||||||
|
if(entityModel.currentAnimation == null || !entityModel.currentAnimation.name.equals(Animation.ANIMATION_MOVEMENT_STARTUP)){
|
||||||
|
entityModel.playAnimation(Animation.ANIMATION_MOVEMENT_STARTUP);
|
||||||
|
entityModel.currentAnimation.incrementTime(0.01);
|
||||||
|
}
|
||||||
|
//check if can transition state
|
||||||
|
if(velocity >= maxNaturalVelocity){
|
||||||
|
velocity = maxNaturalVelocity;
|
||||||
|
state = MovementTreeState.MOVE;
|
||||||
|
}
|
||||||
|
//move the entity
|
||||||
|
position.add(new Vector3f(movementVector).mul(velocity));
|
||||||
|
position.y = Globals.cellManager.getElevationAtRealPoint(position.x, position.z);
|
||||||
|
EntityUtil.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
|
break;
|
||||||
|
case MOVE:
|
||||||
|
//check if can restart animation
|
||||||
|
//if yes, restart animation
|
||||||
|
if(entityModel.currentAnimation == null || !entityModel.currentAnimation.name.equals(Animation.ANIMATION_MOVEMENT_MOVE)){
|
||||||
|
entityModel.playAnimation(Animation.ANIMATION_MOVEMENT_MOVE);
|
||||||
|
entityModel.currentAnimation.incrementTime(0.01);
|
||||||
|
}
|
||||||
|
//check if can move forward (collision engine)
|
||||||
|
//if can, move forward by entity movement stats
|
||||||
|
position.add(new Vector3f(movementVector).mul(velocity));
|
||||||
|
position.y = Globals.cellManager.getElevationAtRealPoint(position.x, position.z);
|
||||||
|
EntityUtil.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
|
break;
|
||||||
|
case SLOWDOWN:
|
||||||
|
//run slowdown code
|
||||||
|
velocity = velocity - acceleration;
|
||||||
|
CreatureUtils.setVelocity(parent, velocity);
|
||||||
|
if(entityModel.currentAnimation == null || !entityModel.currentAnimation.name.equals(Animation.ANIMATION_MOVEMENT_STARTUP)){
|
||||||
|
entityModel.playAnimation(Animation.ANIMATION_MOVEMENT_STARTUP);
|
||||||
|
entityModel.currentAnimation.incrementTime(0.01);
|
||||||
|
}
|
||||||
|
//check if can transition state
|
||||||
|
if(velocity <= 0){
|
||||||
|
velocity = 0;
|
||||||
|
state = MovementTreeState.IDLE;
|
||||||
|
}
|
||||||
|
//move the entity
|
||||||
|
position.add(new Vector3f(movementVector).mul(velocity));
|
||||||
|
position.y = Globals.cellManager.getElevationAtRealPoint(position.x, position.z);
|
||||||
|
EntityUtil.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
|
break;
|
||||||
|
case IDLE:
|
||||||
|
if(entityModel.currentAnimation == null || !entityModel.currentAnimation.name.equals(Animation.ANIMATION_IDLE_1)){
|
||||||
|
entityModel.playAnimation(Animation.ANIMATION_IDLE_1);
|
||||||
|
entityModel.currentAnimation.incrementTime(0.01);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
17
src/main/java/electrosphere/entity/state/RagdollTree.java
Normal file
17
src/main/java/electrosphere/entity/state/RagdollTree.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package electrosphere.entity.state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author amaterasu
|
||||||
|
*/
|
||||||
|
public class RagdollTree {
|
||||||
|
|
||||||
|
|
||||||
|
enum RagdollState {
|
||||||
|
RAGDOLL,
|
||||||
|
GETUP,
|
||||||
|
IDLE,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@ package electrosphere.game.cell;
|
|||||||
import electrosphere.game.terrain.TerrainManager;
|
import electrosphere.game.terrain.TerrainManager;
|
||||||
import electrosphere.renderer.ShaderProgram;
|
import electrosphere.renderer.ShaderProgram;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -31,9 +32,9 @@ public class CellManager {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int drawRadius = 5;
|
int drawRadius = 6;
|
||||||
int drawStepdownInterval = 2;
|
int drawStepdownInterval = 3;
|
||||||
int drawStepdownValue = 2;
|
int drawStepdownValue = 5;
|
||||||
|
|
||||||
public CellManager(TerrainManager terrainManager, float realX, float realY){
|
public CellManager(TerrainManager terrainManager, float realX, float realY){
|
||||||
this.terrainManager = terrainManager;
|
this.terrainManager = terrainManager;
|
||||||
@ -299,4 +300,40 @@ public class CellManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void calculateDeltas(Vector3f oldPosition, Vector3f newPosition){
|
||||||
|
if(transformRealSpaceToCellSpace(newPosition.x()) < transformRealSpaceToCellSpace(oldPosition.x())){
|
||||||
|
shiftChunksNegX();
|
||||||
|
setCellX(transformRealSpaceToCellSpace(newPosition.x()));
|
||||||
|
setCellY(transformRealSpaceToCellSpace(newPosition.z()));
|
||||||
|
} else if(transformRealSpaceToCellSpace(newPosition.x()) > transformRealSpaceToCellSpace(oldPosition.x())){
|
||||||
|
shiftChunksPosX();
|
||||||
|
setCellX(transformRealSpaceToCellSpace(newPosition.x()));
|
||||||
|
setCellY(transformRealSpaceToCellSpace(newPosition.z()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(transformRealSpaceToCellSpace(newPosition.z()) < transformRealSpaceToCellSpace(oldPosition.z())){
|
||||||
|
shiftChunksNegY();
|
||||||
|
setCellX(transformRealSpaceToCellSpace(newPosition.x()));
|
||||||
|
setCellY(transformRealSpaceToCellSpace(newPosition.z()));
|
||||||
|
} else if(transformRealSpaceToCellSpace(newPosition.z()) > transformRealSpaceToCellSpace(oldPosition.z())){
|
||||||
|
shiftChunksPosY();
|
||||||
|
setCellX(transformRealSpaceToCellSpace(newPosition.x()));
|
||||||
|
setCellY(transformRealSpaceToCellSpace(newPosition.z()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(){
|
||||||
|
if(containsUpdateableCell()){
|
||||||
|
updateCellModel();
|
||||||
|
} else if(containsUndrawableCell()){
|
||||||
|
makeCellDrawable();
|
||||||
|
} else if(containsInvalidCell()){
|
||||||
|
updateInvalidCell();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getElevationAtRealPoint(float realPointX, float realPointY){
|
||||||
|
return terrainManager.getHeightAtPosition(realPointX, realPointY);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public class DrawCell {
|
|||||||
Model terrainModel = ModelUtils.createTerrainModelPrecomputedShader(drawArray, program, stride);
|
Model terrainModel = ModelUtils.createTerrainModelPrecomputedShader(drawArray, program, stride);
|
||||||
modelEntity = EntityUtil.spawnDrawableEntity(terrainModel);
|
modelEntity = EntityUtil.spawnDrawableEntity(terrainModel);
|
||||||
// System.out.println("New cell @ " + cellX * cellWidth + "," + cellY * cellWidth);
|
// System.out.println("New cell @ " + cellX * cellWidth + "," + cellY * cellWidth);
|
||||||
EntityUtil.getEntityPosition(modelEntity).set(new Vector3f(cellX * cellWidth, 0, cellY * cellWidth));
|
EntityUtil.getEntityPosition(modelEntity).set(new Vector3f(cellX * cellWidth, 0.01f, cellY * cellWidth));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void retireCell(){
|
public void retireCell(){
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
package electrosphere.game.collision;
|
||||||
|
|
||||||
|
import electrosphere.entity.Entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author amaterasu
|
||||||
|
*/
|
||||||
|
public class CollisionEngine {
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean collisionCheck(Entity entity){
|
||||||
|
boolean rVal = false;
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package electrosphere.game.simcell.physical;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author satellite
|
||||||
|
*/
|
||||||
|
public class PhysicalCell {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package electrosphere.game.simcell.virtual;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author satellite
|
||||||
|
*/
|
||||||
|
public class VirtualCell {
|
||||||
|
|
||||||
|
}
|
||||||
@ -26,6 +26,8 @@ public class TerrainManager {
|
|||||||
|
|
||||||
int dynamicInterpolationRatio;
|
int dynamicInterpolationRatio;
|
||||||
|
|
||||||
|
float randomDampener;
|
||||||
|
|
||||||
TerrainModel model;
|
TerrainModel model;
|
||||||
|
|
||||||
|
|
||||||
@ -38,12 +40,13 @@ public class TerrainManager {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public TerrainManager(int worldSizeDiscrete, int verticalInterpolationRatio, int dynamicInterpolationRatio){
|
public TerrainManager(int worldSizeDiscrete, int verticalInterpolationRatio, int dynamicInterpolationRatio, float randomDampener){
|
||||||
this.worldSizeDiscrete = worldSizeDiscrete;
|
this.worldSizeDiscrete = worldSizeDiscrete;
|
||||||
this.verticalInterpolationRatio = verticalInterpolationRatio;
|
this.verticalInterpolationRatio = verticalInterpolationRatio;
|
||||||
this.dynamicInterpolationRatio = dynamicInterpolationRatio;
|
this.dynamicInterpolationRatio = dynamicInterpolationRatio;
|
||||||
this.elevationMapCache = new HashMap();
|
this.elevationMapCache = new HashMap();
|
||||||
this.elevationMapCacheContents = new ArrayList();
|
this.elevationMapCacheContents = new ArrayList();
|
||||||
|
this.randomDampener = randomDampener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generate(){
|
public void generate(){
|
||||||
@ -53,6 +56,7 @@ public class TerrainManager {
|
|||||||
terrainGen.setDynamicInterpolationRatio(dynamicInterpolationRatio);
|
terrainGen.setDynamicInterpolationRatio(dynamicInterpolationRatio);
|
||||||
terrainGen.setRandomSeed(0);
|
terrainGen.setRandomSeed(0);
|
||||||
model = terrainGen.generateModel();
|
model = terrainGen.generateModel();
|
||||||
|
model.setRandomDampener(randomDampener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(){
|
public void save(){
|
||||||
|
|||||||
@ -10,9 +10,11 @@ import electrosphere.renderer.texture.Texture;
|
|||||||
import electrosphere.renderer.texture.TextureMap;
|
import electrosphere.renderer.texture.TextureMap;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import electrosphere.cfg.MainConfig;
|
import electrosphere.cfg.MainConfig;
|
||||||
|
import electrosphere.controls.ControlHandler;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityManager;
|
import electrosphere.entity.EntityManager;
|
||||||
import electrosphere.game.cell.CellManager;
|
import electrosphere.game.cell.CellManager;
|
||||||
|
import electrosphere.net.client.Connection;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -38,6 +40,19 @@ public class Globals {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//Client connection to server
|
||||||
|
//
|
||||||
|
public static Connection connection;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//Controls Handler
|
||||||
|
//
|
||||||
|
public static ControlHandler controlHandler;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
//Generic OpenGL Statements
|
//Generic OpenGL Statements
|
||||||
//
|
//
|
||||||
@ -86,7 +101,13 @@ public class Globals {
|
|||||||
|
|
||||||
|
|
||||||
//player's entity
|
//player's entity
|
||||||
public static Entity player;
|
|
||||||
|
|
||||||
|
//the player camera entity
|
||||||
|
public static Entity playerCamera;
|
||||||
|
|
||||||
|
//the creature the player camera will orbit and will receive controlHandler movementTree updates
|
||||||
|
public static Entity playerCharacter;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,9 @@ package electrosphere.main;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import electrosphere.cfg.MainConfig;
|
import electrosphere.cfg.MainConfig;
|
||||||
|
import electrosphere.controls.ControlHandler;
|
||||||
|
import electrosphere.entity.CameraEntityUtils;
|
||||||
|
import electrosphere.entity.CreatureUtils;
|
||||||
import electrosphere.renderer.Camera;
|
import electrosphere.renderer.Camera;
|
||||||
import electrosphere.renderer.Material;
|
import electrosphere.renderer.Material;
|
||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
@ -10,6 +13,7 @@ import electrosphere.renderer.ShaderProgram;
|
|||||||
import electrosphere.renderer.texture.Texture;
|
import electrosphere.renderer.texture.Texture;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityUtil;
|
import electrosphere.entity.EntityUtil;
|
||||||
|
import electrosphere.entity.state.MovementTree;
|
||||||
import electrosphere.game.cell.CellManager;
|
import electrosphere.game.cell.CellManager;
|
||||||
import electrosphere.game.terrain.TerrainManager;
|
import electrosphere.game.terrain.TerrainManager;
|
||||||
import electrosphere.renderer.ModelUtils;
|
import electrosphere.renderer.ModelUtils;
|
||||||
@ -89,8 +93,8 @@ public class Main {
|
|||||||
public static boolean CAMERA_IS_ORBIT = true;
|
public static boolean CAMERA_IS_ORBIT = true;
|
||||||
public static float camera_Orbit_Length = 1.0f;
|
public static float camera_Orbit_Length = 1.0f;
|
||||||
|
|
||||||
static final int playerStartRealX = 580 * 200;
|
static int playerStartRealX = 0;
|
||||||
static final int playerStartRealY = 900 * 200;
|
static int playerStartRealY = 0;
|
||||||
|
|
||||||
// public static Camera cam_Player_Orbit;
|
// public static Camera cam_Player_Orbit;
|
||||||
//Camera angles using theta-phi system
|
//Camera angles using theta-phi system
|
||||||
@ -114,6 +118,9 @@ public class Main {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
|
//controls
|
||||||
|
initControlHandler();
|
||||||
|
|
||||||
//run initialization stuff
|
//run initialization stuff
|
||||||
|
|
||||||
initWorld();
|
initWorld();
|
||||||
@ -136,10 +143,12 @@ public class Main {
|
|||||||
|
|
||||||
initPlayer();
|
initPlayer();
|
||||||
|
|
||||||
Entity unitCube = EntityUtil.spawnDrawableEntity(ModelUtils.createUnitCube());
|
|
||||||
EntityUtil.getEntityPosition(unitCube).set(playerStartRealX - 0.5f,10,playerStartRealY - 0.5f);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Entity unitCube = EntityUtil.spawnDrawableEntity(ModelUtils.createUnitCube());
|
||||||
|
EntityUtil.getEntityPosition(unitCube).set(playerStartRealX - 0.5f,10,playerStartRealY - 0.5f);
|
||||||
|
|
||||||
RenderUtils.recaptureScreen();
|
RenderUtils.recaptureScreen();
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -160,12 +169,14 @@ public class Main {
|
|||||||
deltaTime = currentFrame - lastFrame;
|
deltaTime = currentFrame - lastFrame;
|
||||||
lastFrame = currentFrame;
|
lastFrame = currentFrame;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//poll mouse variables and update camera variables
|
//poll mouse variables and update camera variables
|
||||||
updateMouseVariables();
|
updateMouseVariables();
|
||||||
|
|
||||||
|
|
||||||
float cam_Player_Orbit_Magnitude = 1f;
|
float cam_Player_Orbit_Magnitude = 1f;
|
||||||
float cam_Player_Orbit_Offset_Height = 1f;
|
float cam_Player_Orbit_Offset_Height = 0f;
|
||||||
cam_Player_Orbit.pos_Center = new Vector3f(0, 0, 0);
|
cam_Player_Orbit.pos_Center = new Vector3f(0, 0, 0);
|
||||||
cam_Player_Orbit.pos_Center.x = 0 + (float) Math.cos(yaw / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
|
cam_Player_Orbit.pos_Center.x = 0 + (float) Math.cos(yaw / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
|
||||||
cam_Player_Orbit.pos_Center.y = 0 + (float) Math.sin(pitch / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
|
cam_Player_Orbit.pos_Center.y = 0 + (float) Math.sin(pitch / 180.0f * Math.PI) * cam_Player_Orbit_Magnitude;
|
||||||
@ -189,71 +200,51 @@ public class Main {
|
|||||||
if (glfwGetKey(Globals.window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
if (glfwGetKey(Globals.window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(Globals.window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
|
|
||||||
if(CAMERA_UNDER_FREE_CONTROL) {
|
//Poll controls
|
||||||
//cameraSpeed = cameraSpeed * 100;
|
Vector3f oldPlayerCharacterPosition = new Vector3f(EntityUtil.getEntityPosition(Globals.playerCharacter));
|
||||||
} else if(PLAYER_UNDER_USER_CONTROL) {
|
Globals.controlHandler.pollControls();
|
||||||
|
|
||||||
}
|
|
||||||
|
///
|
||||||
|
/// C R E A T U R E S I M U L A T I O N T R E E S
|
||||||
|
///
|
||||||
|
Iterator<Entity> moveablesIterator = Globals.entityManager.getMoveableIterator();
|
||||||
|
while(moveablesIterator.hasNext()){
|
||||||
|
Entity currentMoveable = moveablesIterator.next();
|
||||||
|
MovementTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable);
|
||||||
|
behaviorTree.simulate();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f oldPos = new Vector3f(EntityUtil.getEntityPosition(Globals.player));
|
Vector3f newPlayerCharacterPosition = EntityUtil.getEntityPosition(Globals.playerCharacter);
|
||||||
if(glfwGetKey(Globals.window, GLFW_KEY_W) == GLFW_PRESS){
|
|
||||||
EntityUtil.getEntityPosition(Globals.player).add(new Vector3f(-camera_Current.pos_Center.x,0,-camera_Current.pos_Center.z));
|
|
||||||
}
|
|
||||||
if(glfwGetKey(Globals.window, GLFW_KEY_S) == GLFW_PRESS){
|
|
||||||
EntityUtil.getEntityPosition(Globals.player).add(new Vector3f(camera_Current.pos_Center.x,0,camera_Current.pos_Center.z));
|
|
||||||
}
|
|
||||||
if(glfwGetKey(Globals.window, GLFW_KEY_D) == GLFW_PRESS){
|
|
||||||
EntityUtil.getEntityPosition(Globals.player).add(new Vector3f(-camera_Current.pos_Center.x,0,-camera_Current.pos_Center.z).rotateY((float)(-90 * Math.PI / 180)));
|
|
||||||
}
|
|
||||||
if(glfwGetKey(Globals.window, GLFW_KEY_A) == GLFW_PRESS){
|
|
||||||
EntityUtil.getEntityPosition(Globals.player).add(new Vector3f(-camera_Current.pos_Center.x,0,-camera_Current.pos_Center.z).rotateY((float)(90 * Math.PI / 180)));
|
|
||||||
}
|
|
||||||
if(glfwGetKey(Globals.window, GLFW_KEY_SPACE) == GLFW_PRESS){
|
|
||||||
EntityUtil.getEntityPosition(Globals.player).add(new Vector3f(0,0.6f,0));
|
|
||||||
}
|
|
||||||
if(glfwGetKey(Globals.window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS){
|
|
||||||
EntityUtil.getEntityPosition(Globals.player).add(new Vector3f(0,-0.6f,0));
|
|
||||||
}
|
|
||||||
Vector3f newPos = EntityUtil.getEntityPosition(Globals.player);
|
|
||||||
|
|
||||||
if(Globals.cellManager.transformRealSpaceToCellSpace(newPos.x()) < Globals.cellManager.transformRealSpaceToCellSpace(oldPos.x())){
|
///
|
||||||
Globals.cellManager.shiftChunksNegX();
|
/// C E L L M A N A G E R
|
||||||
Globals.cellManager.setCellX(Globals.cellManager.transformRealSpaceToCellSpace(newPos.x()));
|
///
|
||||||
Globals.cellManager.setCellY(Globals.cellManager.transformRealSpaceToCellSpace(newPos.z()));
|
//Cell manager do your things
|
||||||
} else if(Globals.cellManager.transformRealSpaceToCellSpace(newPos.x()) > Globals.cellManager.transformRealSpaceToCellSpace(oldPos.x())){
|
Globals.cellManager.calculateDeltas(oldPlayerCharacterPosition, newPlayerCharacterPosition);
|
||||||
Globals.cellManager.shiftChunksPosX();
|
Globals.cellManager.update();
|
||||||
Globals.cellManager.setCellX(Globals.cellManager.transformRealSpaceToCellSpace(newPos.x()));
|
|
||||||
Globals.cellManager.setCellY(Globals.cellManager.transformRealSpaceToCellSpace(newPos.z()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Globals.cellManager.transformRealSpaceToCellSpace(newPos.z()) < Globals.cellManager.transformRealSpaceToCellSpace(oldPos.z())){
|
|
||||||
Globals.cellManager.shiftChunksNegY();
|
|
||||||
Globals.cellManager.setCellX(Globals.cellManager.transformRealSpaceToCellSpace(newPos.x()));
|
|
||||||
Globals.cellManager.setCellY(Globals.cellManager.transformRealSpaceToCellSpace(newPos.z()));
|
|
||||||
} else if(Globals.cellManager.transformRealSpaceToCellSpace(newPos.z()) > Globals.cellManager.transformRealSpaceToCellSpace(oldPos.z())){
|
|
||||||
Globals.cellManager.shiftChunksPosY();
|
|
||||||
Globals.cellManager.setCellX(Globals.cellManager.transformRealSpaceToCellSpace(newPos.x()));
|
|
||||||
Globals.cellManager.setCellY(Globals.cellManager.transformRealSpaceToCellSpace(newPos.z()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Globals.cellManager.containsUpdateableCell()){
|
|
||||||
Globals.cellManager.updateCellModel();
|
|
||||||
} else if(Globals.cellManager.containsUndrawableCell()){
|
|
||||||
Globals.cellManager.makeCellDrawable();
|
|
||||||
} else if(Globals.cellManager.containsInvalidCell()){
|
|
||||||
Globals.cellManager.updateInvalidCell();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// camera_player_chase.pos_Center = new Vector3f(EntityUtil.getEntityPosition(player)).sub(EntityUtil.getEntityRotation(player).transform(new Vector3f(-1,1,0)));
|
// camera_player_chase.pos_Center = new Vector3f(EntityUtil.getEntityPosition(player)).sub(EntityUtil.getEntityRotation(player).transform(new Vector3f(-1,1,0)));
|
||||||
|
|
||||||
|
///
|
||||||
|
/// C A M E R A S T U F F
|
||||||
|
///
|
||||||
Globals.cameraVisible.apply_camera(camera_player_chase);
|
Globals.cameraVisible.apply_camera(camera_player_chase);
|
||||||
|
|
||||||
Globals.viewMatrix = Globals.cameraVisible.get_view_matrix();
|
Globals.viewMatrix = Globals.cameraVisible.get_view_matrix();
|
||||||
Globals.viewMatrix = new Matrix4f().setLookAt(camera_Current.pos_Center, new Vector3f(0,0,0), new Vector3f(camera_Current.pos_Center).add(new Vector3f(0,1.0f,0))).scale(1.0f, 1.5f, 1.0f);
|
Globals.viewMatrix = new Matrix4f().setLookAt(
|
||||||
|
camera_Current.pos_Center, //eye
|
||||||
|
new Vector3f(0,0,0), //center
|
||||||
|
new Vector3f(camera_Current.pos_Center).add(new Vector3f(0,1.0f,0)) // up
|
||||||
|
).scale(1.0f, 1.5f, 1.0f);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// R E N D E R I N G S T U F F
|
||||||
|
///
|
||||||
//Sets the background color.
|
//Sets the background color.
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
@ -266,8 +257,11 @@ public class Main {
|
|||||||
while(entity_iterator.hasNext()){
|
while(entity_iterator.hasNext()){
|
||||||
Entity currentEntity = entity_iterator.next();
|
Entity currentEntity = entity_iterator.next();
|
||||||
Model currentModel = EntityUtil.getEntityModel(currentEntity);
|
Model currentModel = EntityUtil.getEntityModel(currentEntity);
|
||||||
|
if(currentModel.currentAnimation != null){
|
||||||
|
currentModel.incrementTime(deltaTime * 500);
|
||||||
|
}
|
||||||
currentModel.modelMatrix = new Matrix4f();
|
currentModel.modelMatrix = new Matrix4f();
|
||||||
currentModel.modelMatrix.translate(new Vector3f(EntityUtil.getEntityPosition(currentEntity)).sub(EntityUtil.getEntityPosition(Globals.player)));
|
currentModel.modelMatrix.translate(new Vector3f(EntityUtil.getEntityPosition(currentEntity)).sub(EntityUtil.getEntityPosition(Globals.playerCharacter)).sub(new Vector3f(0,1,0)));
|
||||||
currentModel.modelMatrix.rotate(EntityUtil.getEntityRotation(currentEntity));
|
currentModel.modelMatrix.rotate(EntityUtil.getEntityRotation(currentEntity));
|
||||||
currentModel.modelMatrix.scale(EntityUtil.getEntityScale(currentEntity));
|
currentModel.modelMatrix.scale(EntityUtil.getEntityScale(currentEntity));
|
||||||
currentModel.draw();
|
currentModel.draw();
|
||||||
@ -297,7 +291,10 @@ public class Main {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void initControlHandler(){
|
||||||
|
ControlHandler.generateExampleControlsMap();
|
||||||
|
Globals.controlHandler = Utilities.loadObjectFromJsonFile("/Config/keybinds.json",ControlHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -343,7 +340,7 @@ public class Main {
|
|||||||
static void initWorld(){
|
static void initWorld(){
|
||||||
|
|
||||||
float[][] elevation;
|
float[][] elevation;
|
||||||
terrainManager = new TerrainManager(2000,200,100);
|
terrainManager = new TerrainManager(2000,200,100,0.25f);
|
||||||
if(Globals.mainConfig.loadTerrain){
|
if(Globals.mainConfig.loadTerrain){
|
||||||
terrainManager.load();
|
terrainManager.load();
|
||||||
} else {
|
} else {
|
||||||
@ -392,12 +389,34 @@ public class Main {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
playerStartRealX = playerStartX * chunkSize;
|
||||||
|
playerStartRealY = playerStartY * chunkSize;
|
||||||
|
|
||||||
Globals.player = new Entity();
|
// Globals.player = CameraEntityUtils.spawnOrbitalCameraEntity(target, 3f);
|
||||||
Globals.player.putData("position", new Vector3f(playerStartX*chunkSize,terrainManager.getHeightAtPosition(playerStartX*chunkSize, playerStartY*chunkSize),playerStartY*chunkSize));
|
// Globals.player.putData("position", new Vector3f(playerStartRealX,terrainManager.getHeightAtPosition(playerStartRealX, playerStartRealY),playerStartRealY));
|
||||||
|
|
||||||
Globals.cellManager.setCellX(Globals.cellManager.transformRealSpaceToCellSpace(playerStartX*chunkSize));
|
/*
|
||||||
Globals.cellManager.setCellY(Globals.cellManager.transformRealSpaceToCellSpace(playerStartY*chunkSize));
|
Entity playerCharacter = EntityUtil.spawnDrawableEntity(ModelLoader.load_Model_From_File("Models/person1walkanim.fbx"));
|
||||||
|
EntityUtil.getEntityPosition(playerCharacter).set(playerStartRealX - 0.5f,terrainManager.getHeightAtPosition(playerStartRealX, playerStartRealY),playerStartRealY - 0.5f);
|
||||||
|
Model playerCharacterModel = EntityUtil.getEntityModel(playerCharacter);
|
||||||
|
EntityUtil.getEntityScale(playerCharacter).set(0.005f);
|
||||||
|
// playerCharacterModel.describeAllAnimations();
|
||||||
|
playerCharacterModel.playAnimation("Armature|Walk");
|
||||||
|
playerCharacterModel.incrementTime(0.1);
|
||||||
|
// EntityUtil.getEntityModel(playerCharacter).playAnimation("Armature|Idle1");
|
||||||
|
*/
|
||||||
|
Model homieModel = ModelLoader.load_Model_From_File("Models/person1walkanim.fbx");
|
||||||
|
homieModel.describeAllAnimations();
|
||||||
|
Globals.playerCharacter = CreatureUtils.spawnBasicControllableEntity(homieModel, 0.005f, 0.025f);
|
||||||
|
EntityUtil.getEntityScale(Globals.playerCharacter).set(0.005f);
|
||||||
|
EntityUtil.getEntityPosition(Globals.playerCharacter).set(playerStartRealX - 0.5f,terrainManager.getHeightAtPosition(playerStartRealX, playerStartRealY),playerStartRealY - 0.5f);
|
||||||
|
|
||||||
|
|
||||||
|
Globals.playerCamera = CameraEntityUtils.spawnOrbitalCameraEntity(Globals.playerCharacter, 3f);
|
||||||
|
|
||||||
|
|
||||||
|
Globals.cellManager.setCellX(Globals.cellManager.transformRealSpaceToCellSpace(playerStartRealX));
|
||||||
|
Globals.cellManager.setCellY(Globals.cellManager.transformRealSpaceToCellSpace(playerStartRealY));
|
||||||
|
|
||||||
Globals.cellManager.invalidateAllCells();
|
Globals.cellManager.invalidateAllCells();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
package electrosphere.net.client;
|
package electrosphere.net.client;
|
||||||
|
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import org.apache.commons.crypto.stream.CryptoInputStream;
|
import org.apache.commons.crypto.stream.CryptoInputStream;
|
||||||
import org.apache.commons.crypto.stream.CryptoOutputStream;
|
import org.apache.commons.crypto.stream.CryptoOutputStream;
|
||||||
|
|
||||||
@ -9,11 +13,59 @@ import org.apache.commons.crypto.stream.CryptoOutputStream;
|
|||||||
* @author amaterasu
|
* @author amaterasu
|
||||||
*/
|
*/
|
||||||
public class Connection {
|
public class Connection {
|
||||||
|
|
||||||
|
enum ConnectionState {
|
||||||
|
HANDSHAKE_START,
|
||||||
|
HANDSHAKE_SUCCESS,
|
||||||
|
HANDSHAKE_FAILURE,
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionState state;
|
||||||
|
|
||||||
|
static int port = 42536;
|
||||||
|
|
||||||
Socket socket;
|
Socket socket;
|
||||||
|
|
||||||
CryptoInputStream inputStream;
|
CryptoInputStream inputStream;
|
||||||
|
|
||||||
CryptoOutputStream outputStream;
|
CryptoOutputStream outputStream;
|
||||||
|
|
||||||
|
public Connection(String address, int port){
|
||||||
|
try {
|
||||||
|
this.socket = new Socket(address,port);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.err.println("Failed to connect!");
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processAllPackets(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void startConnection(){
|
||||||
|
Globals.connection = new Connection("localhost",port);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConnectionProtocol implements Runnable {
|
||||||
|
Connection connection;
|
||||||
|
|
||||||
|
public ConnectionProtocol(Connection conn){
|
||||||
|
connection = conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
boolean running = true;
|
||||||
|
// while(running){
|
||||||
|
// if(connection.inputStream.read)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import org.apache.commons.crypto.stream.CryptoOutputStream;
|
|||||||
*
|
*
|
||||||
* @author satellite
|
* @author satellite
|
||||||
*/
|
*/
|
||||||
public class Client {
|
public class Client implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
Socket socket;
|
Socket socket;
|
||||||
@ -17,4 +17,14 @@ public class Client {
|
|||||||
|
|
||||||
CryptoOutputStream outputStream;
|
CryptoOutputStream outputStream;
|
||||||
|
|
||||||
|
|
||||||
|
public Client(Socket socket) {
|
||||||
|
this.socket = socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
System.out.println("aaaaaaaaaaaeoiu");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,12 @@
|
|||||||
package electrosphere.net.server;
|
package electrosphere.net.server;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -8,9 +14,52 @@ import java.net.ServerSocket;
|
|||||||
*/
|
*/
|
||||||
public class Server {
|
public class Server {
|
||||||
|
|
||||||
|
static int port = 42536;
|
||||||
|
|
||||||
ServerSocket serverSocket;
|
ServerSocket serverSocket;
|
||||||
|
|
||||||
public Server(int port){
|
HashMap<String,Client> clientMap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void initServer(){
|
||||||
|
clientMap = new HashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Server(int port){
|
||||||
|
initServer();
|
||||||
|
try {
|
||||||
|
serverSocket = new ServerSocket();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.err.println("Failed to start server socket!");
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
serverSocket.bind(new InetSocketAddress(port));
|
||||||
|
boolean running = true;
|
||||||
|
while(running){
|
||||||
|
Socket newSocket = serverSocket.accept();
|
||||||
|
Client newClient = new Client(newSocket);
|
||||||
|
clientMap.put(newSocket.getInetAddress().getHostAddress(), newClient);
|
||||||
|
new Thread(newClient).start();
|
||||||
|
}
|
||||||
|
} catch (IOException ex){
|
||||||
|
System.err.println("Socket error on client socket!");
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void startServerThread(){
|
||||||
|
Thread t = new Thread(){
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
Server s = new Server(port);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,13 @@ import org.lwjgl.assimp.AIVectorKey;
|
|||||||
* @author satellite
|
* @author satellite
|
||||||
*/
|
*/
|
||||||
public class Animation {
|
public class Animation {
|
||||||
|
|
||||||
|
public static final String ANIMATION_MOVEMENT_STARTUP = "Armature|WalkStart";
|
||||||
|
public static final String ANIMATION_MOVEMENT_MOVE = "Armature|Walk";
|
||||||
|
public static final String ANIMATION_IDLE_1 = "Armature|Idle1";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AIAnimation animData;
|
AIAnimation animData;
|
||||||
public String name;
|
public String name;
|
||||||
public int ID;
|
public int ID;
|
||||||
|
|||||||
@ -69,6 +69,12 @@ public class Mesh {
|
|||||||
boolean hasBones = true;
|
boolean hasBones = true;
|
||||||
public boolean hasTextureCoords = true;
|
public boolean hasTextureCoords = true;
|
||||||
|
|
||||||
|
public float vertexMinX;
|
||||||
|
public float vertexMaxX;
|
||||||
|
public float vertexMinY;
|
||||||
|
public float vertexMaxY;
|
||||||
|
public float vertexMinZ;
|
||||||
|
public float vertexMaxZ;
|
||||||
|
|
||||||
public ShaderProgram shader;
|
public ShaderProgram shader;
|
||||||
|
|
||||||
@ -135,13 +141,39 @@ public class Mesh {
|
|||||||
rVal.vertexCount = mesh.mNumVertices();
|
rVal.vertexCount = mesh.mNumVertices();
|
||||||
FloatBuffer VertexArrayBufferData = BufferUtils.createFloatBuffer(rVal.vertexCount * 3);
|
FloatBuffer VertexArrayBufferData = BufferUtils.createFloatBuffer(rVal.vertexCount * 3);
|
||||||
float[] temp = new float[3];
|
float[] temp = new float[3];
|
||||||
|
boolean definedDimensions = false;
|
||||||
|
float minX = 0, maxX = 0, minY = 0, maxY = 0, minZ = 0, maxZ = 0;
|
||||||
for (int i = 0; i < rVal.vertexCount; i++) {
|
for (int i = 0; i < rVal.vertexCount; i++) {
|
||||||
AIVector3D vertex = vertexData.get();
|
AIVector3D vertex = vertexData.get();
|
||||||
temp[0] = vertex.x();
|
float x = vertex.x();
|
||||||
temp[1] = vertex.y();
|
float y = vertex.y();
|
||||||
temp[2] = vertex.z();
|
float z = vertex.z();
|
||||||
|
if(definedDimensions){
|
||||||
|
if(x < minX){ minX = x; }
|
||||||
|
if(x > maxX){ maxX = x; }
|
||||||
|
if(y < minY){ minY = y; }
|
||||||
|
if(y > maxY){ maxY = y; }
|
||||||
|
if(z < minZ){ minZ = z; }
|
||||||
|
if(z > maxZ){ maxZ = z; }
|
||||||
|
} else {
|
||||||
|
definedDimensions = true;
|
||||||
|
minX = maxX = x;
|
||||||
|
minY = maxY = y;
|
||||||
|
minZ = maxZ = z;
|
||||||
|
}
|
||||||
|
temp[0] = x;
|
||||||
|
temp[1] = y;
|
||||||
|
temp[2] = z;
|
||||||
VertexArrayBufferData.put(temp);
|
VertexArrayBufferData.put(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rVal.vertexMaxX = maxX;
|
||||||
|
rVal.vertexMinX = minX;
|
||||||
|
rVal.vertexMaxY = maxY;
|
||||||
|
rVal.vertexMinY = minY;
|
||||||
|
rVal.vertexMaxZ = maxZ;
|
||||||
|
rVal.vertexMinZ = minZ;
|
||||||
|
|
||||||
VertexArrayBufferData.flip();
|
VertexArrayBufferData.flip();
|
||||||
rVal.buffer_vertices(VertexArrayBufferData);
|
rVal.buffer_vertices(VertexArrayBufferData);
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
|
|||||||
@ -493,4 +493,34 @@ public class ModelUtils {
|
|||||||
rVal.meshes.add(m);
|
rVal.meshes.add(m);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void printModelDimension(Model m){
|
||||||
|
float minX = 0;
|
||||||
|
float maxX = 0;
|
||||||
|
float minY = 0;
|
||||||
|
float maxY = 0;
|
||||||
|
float minZ = 0;
|
||||||
|
float maxZ = 0;
|
||||||
|
boolean initiated = false;
|
||||||
|
|
||||||
|
for(Mesh currentMesh : m.meshes){
|
||||||
|
if(initiated){
|
||||||
|
if(currentMesh.vertexMinX < minX){ minX = currentMesh.vertexMinX; }
|
||||||
|
if(currentMesh.vertexMaxX > maxX){ maxX = currentMesh.vertexMaxX; }
|
||||||
|
if(currentMesh.vertexMinY < minY){ minY = currentMesh.vertexMinY; }
|
||||||
|
if(currentMesh.vertexMaxY > maxY){ maxY = currentMesh.vertexMaxY; }
|
||||||
|
if(currentMesh.vertexMinZ < minZ){ minZ = currentMesh.vertexMinZ; }
|
||||||
|
if(currentMesh.vertexMaxZ > maxZ){ maxZ = currentMesh.vertexMaxZ; }
|
||||||
|
} else {
|
||||||
|
initiated = true;
|
||||||
|
minX = currentMesh.vertexMinX;
|
||||||
|
maxX = currentMesh.vertexMaxX;
|
||||||
|
minY = currentMesh.vertexMinY;
|
||||||
|
maxY = currentMesh.vertexMaxY;
|
||||||
|
minZ = currentMesh.vertexMinZ;
|
||||||
|
maxZ = currentMesh.vertexMaxZ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("dimensions: " + (maxX - minX) + "," + (maxY - minY) + "," + (maxZ-minZ));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,8 +18,11 @@ import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MAJOR;
|
|||||||
import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MINOR;
|
import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MINOR;
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_CURSOR;
|
import static org.lwjgl.glfw.GLFW.GLFW_CURSOR;
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_DISABLED;
|
import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_DISABLED;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_FALSE;
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_CORE_PROFILE;
|
import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_CORE_PROFILE;
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_PROFILE;
|
import static org.lwjgl.glfw.GLFW.GLFW_OPENGL_PROFILE;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_TRANSPARENT_FRAMEBUFFER;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_TRUE;
|
||||||
import static org.lwjgl.glfw.GLFW.glfwCreateWindow;
|
import static org.lwjgl.glfw.GLFW.glfwCreateWindow;
|
||||||
import static org.lwjgl.glfw.GLFW.glfwInit;
|
import static org.lwjgl.glfw.GLFW.glfwInit;
|
||||||
import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
|
import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
|
||||||
@ -79,6 +82,8 @@ public class RenderUtils {
|
|||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
// glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); Allows you to make the background transparent
|
||||||
|
// glfwWindowHint(GLFW_OPACITY, 23);
|
||||||
//Creates the window reference object
|
//Creates the window reference object
|
||||||
Globals.window = glfwCreateWindow(screenWidth, screenHeight, "LearnOpenGL", NULL, NULL);
|
Globals.window = glfwCreateWindow(screenWidth, screenHeight, "LearnOpenGL", NULL, NULL);
|
||||||
//Errors for failure to create window (IE: No GUI mode on linux ?)
|
//Errors for failure to create window (IE: No GUI mode on linux ?)
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import java.io.IOException;
|
|||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -142,9 +143,7 @@ public class Utilities {
|
|||||||
|
|
||||||
public static void loadMainConfig(){
|
public static void loadMainConfig(){
|
||||||
if(Main.class.getResource("/Config/localconfig.json") != null){
|
if(Main.class.getResource("/Config/localconfig.json") != null){
|
||||||
Gson gson = new Gson();
|
Globals.mainConfig = loadObjectFromJsonFile("/Config/localconfig.json", MainConfig.class);
|
||||||
String configRaw = Utilities.readFileToString(new File(Main.class.getResource("/Config/localconfig.json").getPath()));
|
|
||||||
Globals.mainConfig = gson.fromJson(configRaw, MainConfig.class);
|
|
||||||
if(Globals.mainConfig.version != MainConfig.CONFIG_FILE_VERSION){
|
if(Globals.mainConfig.version != MainConfig.CONFIG_FILE_VERSION){
|
||||||
//dynamically generate config and save it
|
//dynamically generate config and save it
|
||||||
MainConfig.generateMainConfig();
|
MainConfig.generateMainConfig();
|
||||||
@ -153,4 +152,24 @@ public class Utilities {
|
|||||||
MainConfig.generateMainConfig();
|
MainConfig.generateMainConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static <T>T loadObjectFromJsonFile(String fileName, Class<T> className){
|
||||||
|
T rVal = null;
|
||||||
|
String rawJSON = Utilities.readFileToString(new File(Main.class.getResource(fileName).getPath()));
|
||||||
|
Gson gson = new Gson();
|
||||||
|
rVal = gson.fromJson(rawJSON, className);
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveObjectToJsonFile(String fileName, Object object){
|
||||||
|
Path path = new File(Main.class.getResource(fileName).getPath()).toPath();
|
||||||
|
Gson gson = new Gson();
|
||||||
|
try {
|
||||||
|
Files.write(path, gson.toJson(object).getBytes());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
src/main/resources/Models/person1walkanim.fbx
Normal file
BIN
src/main/resources/Models/person1walkanim.fbx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user