diff --git a/src/main/java/electrosphere/game/collision/CollisionEngine.java b/src/main/java/electrosphere/game/collision/CollisionEngine.java index 4d09e9eb..df09f16d 100644 --- a/src/main/java/electrosphere/game/collision/CollisionEngine.java +++ b/src/main/java/electrosphere/game/collision/CollisionEngine.java @@ -1,5 +1,18 @@ package electrosphere.game.collision; +import com.bulletphysics.collision.broadphase.BroadphaseInterface; +import com.bulletphysics.collision.broadphase.DbvtBroadphase; +import com.bulletphysics.collision.dispatch.CollisionDispatcher; +import com.bulletphysics.collision.dispatch.CollisionObject; +import com.bulletphysics.collision.dispatch.DefaultCollisionConfiguration; +import com.bulletphysics.collision.shapes.BoxShape; +import com.bulletphysics.collision.shapes.CollisionShape; +import com.bulletphysics.dynamics.DiscreteDynamicsWorld; +import com.bulletphysics.dynamics.RigidBody; +import com.bulletphysics.dynamics.RigidBodyConstructionInfo; +import com.bulletphysics.dynamics.constraintsolver.SequentialImpulseConstraintSolver; +import com.bulletphysics.linearmath.DefaultMotionState; +import com.bulletphysics.linearmath.Transform; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; @@ -15,9 +28,31 @@ import org.joml.Vector3f; */ public class CollisionEngine { + BroadphaseInterface broadphase; + DefaultCollisionConfiguration collisionConfiguration; + CollisionDispatcher dispatcher; + List collisionEntities = new ArrayList(); public CollisionEngine(){ + broadphase = new DbvtBroadphase(); + collisionConfiguration = new DefaultCollisionConfiguration(); + dispatcher = new CollisionDispatcher(collisionConfiguration); + SequentialImpulseConstraintSolver solver = new SequentialImpulseConstraintSolver(); + DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); + + CollisionShape boxShape = new BoxShape(new javax.vecmath.Vector3f(1,1,1)); + float mass = 1.0f; + DefaultMotionState fallMotionState = new DefaultMotionState(new Transform(new javax.vecmath.Matrix4f(new javax.vecmath.Quat4f(0,0,0,1),new javax.vecmath.Vector3f(0,50,0),1.0f))); + RigidBodyConstructionInfo boxShapeRigidBodyCI = new RigidBodyConstructionInfo(mass, fallMotionState, boxShape); + RigidBody boxRigidBody = new RigidBody(boxShapeRigidBodyCI); + + + world.addRigidBody(boxRigidBody); + + //https://pybullet.org/Bullet/phpBB3/viewtopic.php?t=11507 + //https://www.google.com/search?client=firefox-b-1-d&q=bullet+set+position+and+check+if+collision + //https://pybullet.org/Bullet/phpBB3/viewtopic.php?t=11399 } diff --git a/src/main/java/electrosphere/game/collision/collidable/Collidable.java b/src/main/java/electrosphere/game/collision/collidable/Collidable.java new file mode 100644 index 00000000..93afa638 --- /dev/null +++ b/src/main/java/electrosphere/game/collision/collidable/Collidable.java @@ -0,0 +1,12 @@ +package electrosphere.game.collision.collidable; + + +/** + * + * @author satellite + */ +public class Collidable { + + + +} diff --git a/src/main/java/electrosphere/game/server/world/datacell/DataCell.java b/src/main/java/electrosphere/game/server/world/datacell/DataCell.java index 9d106d8c..b8b09fde 100644 --- a/src/main/java/electrosphere/game/server/world/datacell/DataCell.java +++ b/src/main/java/electrosphere/game/server/world/datacell/DataCell.java @@ -1,9 +1,96 @@ package electrosphere.game.server.world.datacell; +import electrosphere.entity.Entity; +import electrosphere.net.server.Player; +import electrosphere.game.server.character.Character; +import electrosphere.game.server.world.virtualcell.VirtualCell; +import electrosphere.main.Globals; +import electrosphere.net.parser.net.message.NetworkMessage; +import java.util.List; + /** - * - * @author amaterasu + * Container for entities loaded into memory. This isn't intended to be in charge + * of simulation. It just acts as an object to relate players and entities by location. + * This SHOULD be used for networking purposes. This is the mechanism to scope + * network messages by location. + * */ public class DataCell { + List loadedEntities; + List activePlayers; + + + /** + * Constructs a datacell based on a virtual cell. Should be used when a player + * first comes into range of the cell. + * @param virtualCell + */ + public DataCell(VirtualCell virtualCell, Player p){ + + } + + /** + * Add a player to the current datacell. This should be done if a player moves + * into close enough proximity with the cell that they are concerned with + * the microlevel simulation of the cell. This should _not_ be called if + * this is the first player coming into range. + * @param p + */ + public void addPlayer(Player p){ + if(!activePlayers.contains(p)){ + activePlayers.add(p); + } + } + + /** + * Removes a player from the current datacell. Basically the player has moved + * far enough away that this cell doesn't concern them anymore. + * If the number of players for this cell is zero, we should prepare it to be + * unloaded from memory and converted back into a virtual cell. + * @param p + */ + public void removePlayer(Player p){ + activePlayers.remove(p); + } + + /** + * This should be used to translate a character from macrolevel simulation to + * microlevel, datacell based simulation. + * @param character + */ + public void addCharacter(Character character){ + Entity newEntity = new Entity(); + loadedEntities.add(newEntity); + } + + /** + * This should be used to translate an entity from one data cell to another. + * @param e + */ + public void addEntity(Entity e){ + loadedEntities.add(e); + } + + /** + * Intention of this function is to entirely remove the entity from microlevel simulation. + * This should be conbined with code to convert the entity into a tracked macrolevel character. + * The previous should not be true if you're tracking something inconsequential like + * a rabbit or something. Then just delete it. + * @param e + */ + public void removeEntity(Entity e){ + loadedEntities.remove(e); + + } + + /** + * Broadcast a message to all players within range of this cell. + * @param message + */ + public void broadcastNetworkMessage(NetworkMessage message){ + for(Player player : activePlayers){ + player.setMessage(message); + } + } } diff --git a/src/main/java/electrosphere/game/server/world/datacell/DataCellManager.java b/src/main/java/electrosphere/game/server/world/datacell/DataCellManager.java new file mode 100644 index 00000000..56553926 --- /dev/null +++ b/src/main/java/electrosphere/game/server/world/datacell/DataCellManager.java @@ -0,0 +1,16 @@ +package electrosphere.game.server.world.datacell; + +import java.util.LinkedList; +import java.util.List; + +/** + * + * @author satellite + */ +public class DataCellManager { + List loadedDataCells = new LinkedList(); + + public DataCellManager() { + + } +} diff --git a/src/main/java/electrosphere/game/server/world/virtualcell/VirtualCell.java b/src/main/java/electrosphere/game/server/world/virtualcell/VirtualCell.java new file mode 100644 index 00000000..e067951e --- /dev/null +++ b/src/main/java/electrosphere/game/server/world/virtualcell/VirtualCell.java @@ -0,0 +1,31 @@ +package electrosphere.game.server.world.virtualcell; + +import java.util.List; +import electrosphere.game.server.character.Character; +import java.util.LinkedList; + +/** + * Container of virtual character data related to a position. The intention isn't + * to have it perform simulation itself. + */ +public class VirtualCell { + + List characterList = new LinkedList(); + + + public void addCharacter(Character c){ + if(!characterList.contains(c)){ + characterList.add(c); + } + } + + public void removeCharacter(Character c){ + characterList.remove(c); + } + + public List getCharacters(){ + return characterList; + } + + +} diff --git a/src/main/java/electrosphere/main/Globals.java b/src/main/java/electrosphere/main/Globals.java index 855209f1..98b1c201 100644 --- a/src/main/java/electrosphere/main/Globals.java +++ b/src/main/java/electrosphere/main/Globals.java @@ -162,6 +162,7 @@ public class Globals { // //keeps track of all entities in game public static EntityManager entityManager; + public static EntityManager serverEntityManager; //terrain manager public static boolean LOAD_TERRAIN = true; diff --git a/src/main/java/electrosphere/net/server/Player.java b/src/main/java/electrosphere/net/server/Player.java new file mode 100644 index 00000000..af0ba742 --- /dev/null +++ b/src/main/java/electrosphere/net/server/Player.java @@ -0,0 +1,23 @@ +package electrosphere.net.server; + +import electrosphere.net.parser.net.message.NetworkMessage; + +/** + * + * @author satellite + */ +public class Player { + + ServerConnectionHandler connectionHandler; + int id; + + public int getId() { + return id; + } + + public void setMessage(NetworkMessage message){ + connectionHandler.addMessagetoOutgoingQueue(message); + } + + +} diff --git a/src/main/java/electrosphere/renderer/light/ItsBroken_DirectionalLight.java b/src/main/java/electrosphere/renderer/light/ItsBroken_DirectionalLight.java new file mode 100644 index 00000000..1aba3c8f --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/ItsBroken_DirectionalLight.java @@ -0,0 +1,69 @@ +package electrosphere.renderer.light; + +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class ItsBroken_DirectionalLight { + Vector3f direction; + + Vector3f ambient; + Vector3f diffuse; + Vector3f specular; + + public void setDirection(Vector3f direction) { + this.direction = direction; + } + + public void setAmbient(Vector3f ambient) { + this.ambient = ambient; + } + + public void setDiffuse(Vector3f diffuse) { + this.diffuse = diffuse; + } + + public void setSpecular(Vector3f specular) { + this.specular = specular; + } + + public Vector3f getDirection() { + return direction; + } + + public Vector3f getAmbient() { + return ambient; + } + + public Vector3f getDiffuse() { + return diffuse; + } + + public Vector3f getSpecular() { + return specular; + } + + public ItsBroken_DirectionalLight(Vector3f direction){ + this.direction = direction; + ambient = new Vector3f(0.05f, 0.05f, 0.05f); + diffuse = new Vector3f(0.4f, 0.4f, 0.4f); + specular = new Vector3f(0.5f, 0.5f, 0.5f); + this.direction.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } + + public ItsBroken_DirectionalLight(Vector3f direction, Vector3f color){ + this.direction = direction; + ambient = new Vector3f( color.x * 0.05f, color.y * 0.05f, color.z * 0.05f); + diffuse = new Vector3f( color.x * 0.4f, color.y * 0.4f, color.z * 0.4f); + specular = new Vector3f(color.x * 0.5f, color.y * 0.5f, color.z * 0.5f); + this.direction.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } +} diff --git a/src/main/java/electrosphere/renderer/light/LightBuffer.java b/src/main/java/electrosphere/renderer/light/LightBuffer.java new file mode 100644 index 00000000..af877f73 --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/LightBuffer.java @@ -0,0 +1,23 @@ +/* + * 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.renderer.light; + +import static org.lwjgl.opengl.GL15.*; +import static org.lwjgl.opengl.GL31.GL_UNIFORM_BUFFER; + +/** + * + * @author amaterasu + */ +public class LightBuffer { + int light_uniform_buffer_address; + + public LightBuffer(){ + light_uniform_buffer_address = glGenBuffers(); + glBindBuffer(GL_UNIFORM_BUFFER,light_uniform_buffer_address); + //glBufferData(GL_UNIFORM_BUFFER, , GL_STATIC_DRAW); + } +} diff --git a/src/main/java/electrosphere/renderer/light/LightEntityUtils.java b/src/main/java/electrosphere/renderer/light/LightEntityUtils.java new file mode 100644 index 00000000..fc62a5b1 --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/LightEntityUtils.java @@ -0,0 +1,41 @@ +package electrosphere.renderer.light; + +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; +import electrosphere.main.Globals; +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class LightEntityUtils { + + public static Entity createDirectionalLight(Vector3f position, Vector3f ambient, Vector3f diffuse, Vector3f specular){ + Entity rVal = new Entity(); + Globals.entityManager.registerEntity(rVal); + Globals.entityManager.registerLightEntity(rVal); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_DIRECTIONAL); + rVal.putData(EntityDataStrings.DATA_STRING_POSITION, position); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular); + return rVal; + } + + public static Entity createPointLight(Vector3f position, Vector3f ambient, Vector3f diffuse, Vector3f specular, float constant, float linear, float quadratic){ + Entity rVal = new Entity(); + Globals.entityManager.registerEntity(rVal); + Globals.entityManager.registerLightEntity(rVal); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_POINT); + rVal.putData(EntityDataStrings.DATA_STRING_POSITION, position); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_CONSTANT, constant); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_LINEAR, linear); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_QUADRATIC, quadratic); + return rVal; + } + +} diff --git a/src/main/java/electrosphere/renderer/light/LightManager.java b/src/main/java/electrosphere/renderer/light/LightManager.java new file mode 100644 index 00000000..77693dae --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/LightManager.java @@ -0,0 +1,9 @@ +package electrosphere.renderer.light; + +/** + * + * @author amaterasu + */ +public class LightManager { + +} diff --git a/src/main/java/electrosphere/renderer/light/PointLight.java b/src/main/java/electrosphere/renderer/light/PointLight.java new file mode 100644 index 00000000..8860bc9f --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/PointLight.java @@ -0,0 +1,106 @@ + /* + * 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.renderer.light; + +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class PointLight { + Vector3f position; + float constant; + float linear; + float quadratic; + Vector3f ambient; + Vector3f diffuse; + Vector3f specular; + + public void setPosition(Vector3f position) { + this.position = position; + } + + public void setConstant(float constant) { + this.constant = constant; + } + + public void setLinear(float linear) { + this.linear = linear; + } + + public void setQuadratic(float quadratic) { + this.quadratic = quadratic; + } + + public void setAmbient(Vector3f ambient) { + this.ambient = ambient; + } + + public void setDiffuse(Vector3f diffuse) { + this.diffuse = diffuse; + } + + public void setSpecular(Vector3f specular) { + this.specular = specular; + } + + public Vector3f getPosition() { + return position; + } + + public float getConstant() { + return constant; + } + + public float getLinear() { + return linear; + } + + public float getQuadratic() { + return quadratic; + } + + public Vector3f getAmbient() { + return ambient; + } + + public Vector3f getDiffuse() { + return diffuse; + } + + public Vector3f getSpecular() { + return specular; + } + + public PointLight(Vector3f position){ + this.position = position; + constant = 1.0f; + linear = 0.01f; + quadratic = 0.01f; + ambient = new Vector3f(0.05f, 0.05f, 0.05f); + diffuse = new Vector3f(0.8f, 0.8f, 0.8f); + specular = new Vector3f(1.0f, 1.0f, 1.0f); + this.position.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } + + public PointLight(Vector3f position, Vector3f color){ + this.position = position; + constant = 1.0f; + linear = 0.01f; + quadratic = 0.01f; + ambient = new Vector3f(color.x * 0.05f, color.y * 0.05f, color.z * 0.05f); + diffuse = new Vector3f(color.x * 0.8f, color.y * 0.8f, color.z * 0.8f); + specular = new Vector3f(color.x, color.y, color.z); + this.position.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } +} diff --git a/src/main/java/electrosphere/renderer/light/SpotLight.java b/src/main/java/electrosphere/renderer/light/SpotLight.java new file mode 100644 index 00000000..bee4b384 --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/SpotLight.java @@ -0,0 +1,143 @@ +/* + * 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.renderer.light; + +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class SpotLight { + Vector3f position; + Vector3f direction; + float cutOff; + float outerCutOff; + + float constant; + float linear; + float quadratic; + + Vector3f ambient; + Vector3f diffuse; + Vector3f specular; + + public void setPosition(Vector3f position) { + this.position = position; + } + + public void setDirection(Vector3f direction) { + this.direction = direction; + } + + public void setCutOff(float cutOff) { + this.cutOff = cutOff; + } + + public void setOuterCutOff(float outerCutOff) { + this.outerCutOff = outerCutOff; + } + + public void setConstant(float constant) { + this.constant = constant; + } + + public void setLinear(float linear) { + this.linear = linear; + } + + public void setQuadratic(float quadratic) { + this.quadratic = quadratic; + } + + public void setAmbient(Vector3f ambient) { + this.ambient = ambient; + } + + public void setDiffuse(Vector3f diffuse) { + this.diffuse = diffuse; + } + + public void setSpecular(Vector3f specular) { + this.specular = specular; + } + + public Vector3f getPosition() { + return position; + } + + public Vector3f getDirection() { + return direction; + } + + public float getCutOff() { + return cutOff; + } + + public float getOuterCutOff() { + return outerCutOff; + } + + public float getConstant() { + return constant; + } + + public float getLinear() { + return linear; + } + + public float getQuadratic() { + return quadratic; + } + + public Vector3f getAmbient() { + return ambient; + } + + public Vector3f getDiffuse() { + return diffuse; + } + + public Vector3f getSpecular() { + return specular; + } + + + + public SpotLight(Vector3f position, Vector3f direction){ + this.position = position; + this.direction = direction; + cutOff = (float)Math.toRadians(12.5f); + outerCutOff = (float)Math.toRadians(15.0f); + constant = 1.0f; + linear = 0.01f; + quadratic = 0.01f; + ambient = new Vector3f(0.05f, 0.05f, 0.05f); + diffuse = new Vector3f(0.8f, 0.8f, 0.8f); + specular = new Vector3f(1.0f, 1.0f, 1.0f); + this.position.normalize(); + this.direction.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } + + public SpotLight(Vector3f position, Vector3f direction, Vector3f color){ + this.position = position; + this.direction = direction; + constant = 1.0f; + linear = 0.01f; + quadratic = 0.01f; + ambient = new Vector3f(color.x * 0.05f, color.y * 0.05f, color.z * 0.05f); + diffuse = new Vector3f(color.x * 0.8f, color.y * 0.8f, color.z * 0.8f); + specular = new Vector3f(color.x, color.y, color.z); + this.position.normalize(); + this.direction.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } +}