Attempt at entity instancing via data cells
This commit is contained in:
parent
1a4b00a138
commit
84a416b99f
@ -8,7 +8,7 @@ import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.game.collision.CollisionEngine;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.game.client.drawcell.DrawCellManager;
|
||||
import electrosphere.game.client.cells.DrawCellManager;
|
||||
import electrosphere.game.client.player.ClientPlayerData;
|
||||
import electrosphere.game.client.terrain.manager.ClientTerrainManager;
|
||||
import electrosphere.game.client.world.ClientWorldData;
|
||||
@ -25,6 +25,7 @@ import electrosphere.game.collision.collidable.Collidable;
|
||||
import electrosphere.game.server.ai.creature.MindlessAttacker;
|
||||
import electrosphere.game.server.terrain.models.TerrainModification;
|
||||
import electrosphere.game.server.town.Town;
|
||||
import electrosphere.game.server.world.datacell.DataCellManager;
|
||||
import electrosphere.game.state.MicroSimulation;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
@ -113,6 +114,7 @@ public class LoadingThread extends Thread {
|
||||
if(Globals.RUN_SERVER){
|
||||
initServerGameWorldData();
|
||||
createServerWorld();
|
||||
initDataCellManager();
|
||||
}
|
||||
|
||||
//initialize the server thread (server only)
|
||||
@ -192,6 +194,9 @@ public class LoadingThread extends Thread {
|
||||
//init the data of the world
|
||||
initServerArenaWorldData();
|
||||
|
||||
//init data cell manager
|
||||
initDataCellManager();
|
||||
|
||||
//initialize the server thread (server only)
|
||||
if(Globals.RUN_SERVER){
|
||||
initServerThread();
|
||||
@ -273,8 +278,8 @@ public class LoadingThread extends Thread {
|
||||
/*
|
||||
Actually initialize the terrain manager
|
||||
*/
|
||||
float[][] elevation;
|
||||
Globals.serverTerrainManager = new ServerTerrainManager(2000,50,100,0.25f,0);
|
||||
float randomDampener = 0.0f; //0.25f;
|
||||
Globals.serverTerrainManager = new ServerTerrainManager(2000,50,100,randomDampener,0);
|
||||
if(Globals.RUN_SERVER){
|
||||
if(Globals.LOAD_TERRAIN){
|
||||
Globals.serverTerrainManager.load();
|
||||
@ -355,6 +360,10 @@ public class LoadingThread extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
static void initDataCellManager(){
|
||||
Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void initServerThread(){
|
||||
|
||||
@ -147,4 +147,20 @@ public class EntityDataStrings {
|
||||
public static final String IS_PARTICLE = "isParticle";
|
||||
public static final String PARTICLE_TREE = "particleTree";
|
||||
|
||||
|
||||
/*
|
||||
Structure entity
|
||||
*/
|
||||
public static final String STRUCTURE_IS_STRUCTURE = "structureIsStructure";
|
||||
public static final String STRUCTURE_TYPE = "structureType";
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Entity categories
|
||||
*/
|
||||
public static final int ENTITY_CATEGORY_CREATURE = 0;
|
||||
public static final int ENTITY_CATEGORY_ITEM = 1;
|
||||
public static final int ENTITY_CATEGORY_STRUCTURE = 2;
|
||||
|
||||
}
|
||||
|
||||
@ -188,7 +188,21 @@ public class MovementTree {
|
||||
activateGravityTree();
|
||||
|
||||
if(Globals.RUN_SERVER){
|
||||
Globals.server.broadcastMessage(
|
||||
// Globals.server.broadcastMessage(
|
||||
// EntityMessage.constructmoveUpdateMessage(
|
||||
// parent.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// newPosition.x,
|
||||
// newPosition.y,
|
||||
// newPosition.z,
|
||||
// movementVector.x,
|
||||
// movementVector.y,
|
||||
// movementVector.z,
|
||||
// velocity,
|
||||
// 0
|
||||
// )
|
||||
// );
|
||||
Globals.dataCellManager.sendNetworkMessageToChunk(
|
||||
EntityMessage.constructmoveUpdateMessage(
|
||||
parent.getId(),
|
||||
System.currentTimeMillis(),
|
||||
@ -200,7 +214,9 @@ public class MovementTree {
|
||||
movementVector.z,
|
||||
velocity,
|
||||
0
|
||||
)
|
||||
),
|
||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.x),
|
||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.z)
|
||||
);
|
||||
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||
Globals.clientConnection.queueOutgoingMessage(
|
||||
@ -246,7 +262,21 @@ public class MovementTree {
|
||||
activateGravityTree();
|
||||
|
||||
if(Globals.RUN_SERVER){
|
||||
Globals.server.broadcastMessage(
|
||||
// Globals.server.broadcastMessage(
|
||||
// EntityMessage.constructmoveUpdateMessage(
|
||||
// parent.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// newPosition.x,
|
||||
// newPosition.y,
|
||||
// newPosition.z,
|
||||
// movementVector.x,
|
||||
// movementVector.y,
|
||||
// movementVector.z,
|
||||
// velocity,
|
||||
// 1
|
||||
// )
|
||||
// );
|
||||
Globals.dataCellManager.sendNetworkMessageToChunk(
|
||||
EntityMessage.constructmoveUpdateMessage(
|
||||
parent.getId(),
|
||||
System.currentTimeMillis(),
|
||||
@ -258,7 +288,9 @@ public class MovementTree {
|
||||
movementVector.z,
|
||||
velocity,
|
||||
1
|
||||
)
|
||||
),
|
||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.x),
|
||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.z)
|
||||
);
|
||||
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||
Globals.clientConnection.queueOutgoingMessage(
|
||||
@ -308,7 +340,21 @@ public class MovementTree {
|
||||
activateGravityTree();
|
||||
|
||||
if(Globals.RUN_SERVER){
|
||||
Globals.server.broadcastMessage(
|
||||
// Globals.server.broadcastMessage(
|
||||
// EntityMessage.constructmoveUpdateMessage(
|
||||
// parent.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// newPosition.x,
|
||||
// newPosition.y,
|
||||
// newPosition.z,
|
||||
// movementVector.x,
|
||||
// movementVector.y,
|
||||
// movementVector.z,
|
||||
// velocity,
|
||||
// 2
|
||||
// )
|
||||
// );
|
||||
Globals.dataCellManager.sendNetworkMessageToChunk(
|
||||
EntityMessage.constructmoveUpdateMessage(
|
||||
parent.getId(),
|
||||
System.currentTimeMillis(),
|
||||
@ -320,7 +366,9 @@ public class MovementTree {
|
||||
movementVector.z,
|
||||
velocity,
|
||||
2
|
||||
)
|
||||
),
|
||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.x),
|
||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.z)
|
||||
);
|
||||
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||
Globals.clientConnection.queueOutgoingMessage(
|
||||
|
||||
@ -18,9 +18,13 @@ import electrosphere.game.collision.PhysicsUtils;
|
||||
import electrosphere.game.collision.collidable.Collidable;
|
||||
import electrosphere.game.config.creature.type.AttackMove;
|
||||
import electrosphere.game.config.creature.type.PhysicsObject;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.main.Main;
|
||||
import electrosphere.net.NetUtils;
|
||||
import electrosphere.net.parser.net.message.EntityMessage;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
import electrosphere.net.server.Player;
|
||||
import electrosphere.renderer.Actor;
|
||||
import electrosphere.renderer.ActorUtils;
|
||||
import electrosphere.renderer.Model;
|
||||
@ -136,6 +140,18 @@ public class CreatureUtils {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static void sendEntityToPlayer(Player player, Entity creature){
|
||||
int id = creature.getId();
|
||||
String type = CreatureUtils.getType(creature);
|
||||
Vector3f position = EntityUtils.getPosition(creature);
|
||||
NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_CREATURE, type, position.x, position.y, position.z);
|
||||
player.addMessage(message);
|
||||
if(CreatureUtils.hasControllerPlayerId(creature)){
|
||||
LoggerInterface.loggerNetworking.INFO("Sending controller packets");
|
||||
player.addMessage(NetUtils.createSetCreatureControllerIdEntityMessage(creature));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setMovementVector(Entity e, Vector3f vector){
|
||||
e.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, vector);
|
||||
}
|
||||
|
||||
@ -4,11 +4,15 @@ import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.state.movement.MovementTree;
|
||||
import electrosphere.entity.types.attach.AttachUtils;
|
||||
import electrosphere.entity.types.hitbox.HitboxData;
|
||||
import electrosphere.entity.types.hitbox.HitboxUtils;
|
||||
import electrosphere.game.config.creature.type.CreatureType;
|
||||
import electrosphere.game.config.item.type.Item;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.net.parser.net.message.EntityMessage;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
import electrosphere.net.server.Player;
|
||||
import electrosphere.renderer.Actor;
|
||||
import electrosphere.renderer.ActorUtils;
|
||||
import electrosphere.renderer.Model;
|
||||
@ -52,6 +56,23 @@ public class ItemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendEntityToPlayer(Player player, Entity item){
|
||||
int id = item.getId();
|
||||
String type = ItemUtils.getType(item);
|
||||
Vector3f position = EntityUtils.getPosition(item);
|
||||
NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_ITEM, type, position.x, position.y, position.z);
|
||||
player.addMessage(message);
|
||||
if(AttachUtils.isAttached(item)){
|
||||
player.addMessage(
|
||||
EntityMessage.constructattachEntityToEntityMessage(
|
||||
item.getId(),
|
||||
AttachUtils.getTargetBone(item),
|
||||
AttachUtils.getParent(item).getId()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isItem(Entity item){
|
||||
return item.getDataKeys().contains(EntityDataStrings.ITEM_IS_ITEM);
|
||||
}
|
||||
|
||||
@ -8,6 +8,9 @@ import electrosphere.game.collision.collidable.Collidable;
|
||||
import electrosphere.game.config.structure.type.model.CollisionObjectTemplate;
|
||||
import electrosphere.game.config.structure.type.model.StructureType;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.net.parser.net.message.EntityMessage;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
import electrosphere.net.server.Player;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
@ -41,6 +44,24 @@ public class StructureUtils {
|
||||
throw new UnsupportedOperationException("Haven't implemented plane collision on structures");
|
||||
}
|
||||
}
|
||||
rVal.putData(EntityDataStrings.STRUCTURE_IS_STRUCTURE,true);
|
||||
rVal.putData(EntityDataStrings.STRUCTURE_TYPE,type);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static boolean isStructure(Entity entity){
|
||||
return entity.getDataKeys().contains(EntityDataStrings.STRUCTURE_IS_STRUCTURE);
|
||||
}
|
||||
|
||||
public static String getType(Entity structure){
|
||||
return (String)structure.getData(EntityDataStrings.STRUCTURE_TYPE);
|
||||
}
|
||||
|
||||
public static void sendStructureToPlayer(Player player, Entity structure){
|
||||
int id = structure.getId();
|
||||
String type = StructureUtils.getType(structure);
|
||||
Vector3f position = EntityUtils.getPosition(structure);
|
||||
NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_STRUCTURE, type, position.x, position.y, position.z);
|
||||
player.addMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
package electrosphere.game.client.cells;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class ClientDataCell {
|
||||
List<Entity> entities = new LinkedList();
|
||||
|
||||
|
||||
public ClientDataCell(){
|
||||
|
||||
}
|
||||
|
||||
public void addEntity(Entity e){
|
||||
entities.add(e);
|
||||
}
|
||||
|
||||
public void removeEntity(Entity e){
|
||||
entities.remove(e);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package electrosphere.game.client.drawcell;
|
||||
package electrosphere.game.client.cells;
|
||||
|
||||
import electrosphere.collision.dispatch.CollisionObject;
|
||||
import electrosphere.dynamics.RigidBody;
|
||||
@ -1,4 +1,4 @@
|
||||
package electrosphere.game.client.drawcell;
|
||||
package electrosphere.game.client.cells;
|
||||
|
||||
import electrosphere.game.client.terrain.manager.ClientTerrainManager;
|
||||
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
|
||||
@ -5,6 +5,7 @@ import electrosphere.logger.LoggerInterface;
|
||||
public class ClientPlayerData {
|
||||
int initialDiscretePositionX;
|
||||
int initialDiscretePositionY;
|
||||
int simulationRadius = 3;
|
||||
|
||||
boolean loaded = false;
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ package electrosphere.game.client.world;
|
||||
|
||||
import electrosphere.game.server.world.*;
|
||||
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
|
||||
import electrosphere.game.server.world.datacell.DataCell;
|
||||
import electrosphere.game.server.world.datacell.ServerDataCell;
|
||||
import java.util.List;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
@ -130,7 +130,7 @@ public class CollisionEngine {
|
||||
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_CREATURE));
|
||||
break;
|
||||
case Collidable.TYPE_STRUCTURE:
|
||||
System.out.println(normal + " - " + magnitude);
|
||||
// System.out.println(normal + " - " + magnitude);
|
||||
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_STRUCTURE));
|
||||
// System.out.println("Structure-creature collision");
|
||||
break;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package electrosphere.game.server.world;
|
||||
|
||||
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
|
||||
import electrosphere.game.server.world.datacell.DataCell;
|
||||
import electrosphere.game.server.world.datacell.ServerDataCell;
|
||||
import java.util.List;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
|
||||
@ -1,7 +1,15 @@
|
||||
package electrosphere.game.server.world.datacell;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.game.collision.CommonWorldData;
|
||||
import electrosphere.game.server.world.ServerWorldData;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
import electrosphere.net.server.Player;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -9,11 +17,77 @@ import java.util.List;
|
||||
*/
|
||||
public class DataCellManager {
|
||||
|
||||
List<DataCell> loadedDataCells = new LinkedList();
|
||||
List<ServerDataCell> loadedDataCells = new LinkedList();
|
||||
ServerDataCell[][] dataCells;
|
||||
int discreteWorldSize;
|
||||
|
||||
DataCell[][] dataCells;
|
||||
List<Player> playerList = new LinkedList();
|
||||
|
||||
public DataCellManager() {
|
||||
|
||||
public DataCellManager(ServerWorldData data) {
|
||||
discreteWorldSize = data.getWorldSizeDiscrete();
|
||||
dataCells = new ServerDataCell[discreteWorldSize][discreteWorldSize];
|
||||
}
|
||||
|
||||
|
||||
public void addPlayer(Player player){
|
||||
playerList.add(player);
|
||||
}
|
||||
|
||||
public void movePlayer(Player player, int newX, int newY){
|
||||
int playerSimulationRadius = player.getSimulationRadius();
|
||||
int oldX = player.getWorldX();
|
||||
int oldY = player.getWorldY();
|
||||
player.setWorldX(newX);
|
||||
player.setWorldY(newY);
|
||||
for(int x = oldX - playerSimulationRadius; x < oldX + playerSimulationRadius + 1; x++){
|
||||
for(int y = oldY - playerSimulationRadius; y < oldY + playerSimulationRadius + 1; y++){
|
||||
if(x >= 0 && x < discreteWorldSize && y >= 0 && y < discreteWorldSize){
|
||||
if(dataCells[x][y] != null){
|
||||
if(dataCells[x][y].containsPlayer(player)){
|
||||
dataCells[x][y].removePlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int x = newX - playerSimulationRadius; x < newX + playerSimulationRadius + 1; x++){
|
||||
for(int y = newY - playerSimulationRadius; y < newY + playerSimulationRadius + 1; y++){
|
||||
if(x >= 0 && x < discreteWorldSize && y >= 0 && y < discreteWorldSize){
|
||||
if(dataCells[x][y] != null){
|
||||
dataCells[x][y].addPlayer(player);
|
||||
} else {
|
||||
//create data cell
|
||||
//add player
|
||||
}
|
||||
//stream cell to player
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(Player player){
|
||||
throw new UnsupportedOperationException("Removing players from the data cell manager isn't supported -- DataCellManager -- removePlayer(Player player)");
|
||||
}
|
||||
|
||||
public void updatePlayerPositions(){
|
||||
for(Player player : playerList){
|
||||
Entity playerEntity = player.getPlayerEntity();
|
||||
if(playerEntity != null){
|
||||
Vector3f position = EntityUtils.getPosition(playerEntity);
|
||||
int currentWorldX = Globals.serverWorldData.convertRealToChunkSpace(position.x);
|
||||
int currentWorldY = Globals.serverWorldData.convertRealToChunkSpace(position.z);
|
||||
if(currentWorldX != player.getWorldX() || currentWorldY != player.getWorldY()){
|
||||
movePlayer(player,currentWorldX,currentWorldY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendNetworkMessageToChunk(NetworkMessage message, int worldX, int worldY){
|
||||
if(dataCells[worldX][worldY] != null){
|
||||
dataCells[worldX][worldY].broadcastNetworkMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package electrosphere.game.server.world.datacell;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.entity.types.structure.StructureUtils;
|
||||
import electrosphere.net.server.Player;
|
||||
import electrosphere.game.server.character.Character;
|
||||
import electrosphere.game.server.world.virtualcell.VirtualCell;
|
||||
@ -15,7 +18,7 @@ import java.util.List;
|
||||
* network messages by location.
|
||||
*
|
||||
*/
|
||||
public class DataCell {
|
||||
public class ServerDataCell {
|
||||
|
||||
List<Entity> loadedEntities;
|
||||
List<Player> activePlayers;
|
||||
@ -26,7 +29,7 @@ public class DataCell {
|
||||
* first comes into range of the cell.
|
||||
* @param virtualCell
|
||||
*/
|
||||
public DataCell(VirtualCell virtualCell, Player p){
|
||||
public ServerDataCell(VirtualCell virtualCell, Player p){
|
||||
|
||||
}
|
||||
|
||||
@ -40,6 +43,7 @@ public class DataCell {
|
||||
public void addPlayer(Player p){
|
||||
if(!activePlayers.contains(p)){
|
||||
activePlayers.add(p);
|
||||
serializeStateToPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +94,36 @@ public class DataCell {
|
||||
*/
|
||||
public void broadcastNetworkMessage(NetworkMessage message){
|
||||
for(Player player : activePlayers){
|
||||
player.setMessage(message);
|
||||
player.addMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the current state of the datacell to the player
|
||||
* Commonly, this should be called when a player is added to the cell
|
||||
*/
|
||||
void serializeStateToPlayer(Player player){
|
||||
if(player != Globals.serverPlayer){
|
||||
for(Entity entity : loadedEntities){
|
||||
if(CreatureUtils.isCreature(entity)){
|
||||
CreatureUtils.sendEntityToPlayer(player, entity);
|
||||
}
|
||||
if(ItemUtils.isItem(entity)){
|
||||
ItemUtils.sendEntityToPlayer(player, entity);
|
||||
}
|
||||
if(StructureUtils.isStructure(entity)){
|
||||
StructureUtils.sendStructureToPlayer(player, entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if player is relevant to cell
|
||||
*/
|
||||
public boolean containsPlayer(Player player){
|
||||
return activePlayers.contains(player);
|
||||
}
|
||||
|
||||
}
|
||||
@ -98,6 +98,8 @@ public class MicroSimulation {
|
||||
}
|
||||
//clear collidable impulse lists
|
||||
Globals.collisionEngine.clearCollidableImpulseLists();
|
||||
//data cell manager update
|
||||
Globals.dataCellManager.updatePlayerPositions();
|
||||
}
|
||||
|
||||
public boolean isReady(){
|
||||
|
||||
@ -12,7 +12,7 @@ import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityManager;
|
||||
import electrosphere.game.collision.CollisionEngine;
|
||||
import electrosphere.entity.types.hitbox.HitboxManager;
|
||||
import electrosphere.game.client.drawcell.DrawCellManager;
|
||||
import electrosphere.game.client.cells.DrawCellManager;
|
||||
import electrosphere.game.client.player.ClientPlayerData;
|
||||
import electrosphere.game.client.terrain.manager.ClientTerrainManager;
|
||||
import electrosphere.game.client.world.ClientWorldData;
|
||||
@ -33,6 +33,8 @@ import electrosphere.game.server.world.virtualcell.VirtualCellManager;
|
||||
import electrosphere.game.state.MicroSimulation;
|
||||
import electrosphere.menu.Menu;
|
||||
import electrosphere.net.client.ClientNetworking;
|
||||
import electrosphere.net.server.Player;
|
||||
import electrosphere.net.server.PlayerManager;
|
||||
import electrosphere.net.server.Server;
|
||||
import electrosphere.renderer.ModelUtils;
|
||||
import electrosphere.renderer.RenderUtils;
|
||||
@ -112,10 +114,14 @@ public class Globals {
|
||||
//current world
|
||||
//
|
||||
public static ServerWorldData serverWorldData;
|
||||
VirtualCellManager virtualCellManager;
|
||||
DataCellManager dataCellManager;
|
||||
|
||||
public static VirtualCellManager virtualCellManager;
|
||||
public static DataCellManager dataCellManager;
|
||||
|
||||
//
|
||||
//Player manager
|
||||
//
|
||||
public static PlayerManager playerManager;
|
||||
public static Player serverPlayer;
|
||||
|
||||
//
|
||||
//Generic OpenGL Statements
|
||||
@ -285,6 +291,8 @@ public class Globals {
|
||||
//game config
|
||||
gameConfigDefault = electrosphere.game.config.Config.loadDefaultConfig();
|
||||
gameConfigCurrent = gameConfigDefault;
|
||||
//player manager
|
||||
playerManager = new PlayerManager();
|
||||
}
|
||||
|
||||
public static void initDefaultGraphicalResources(){
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package electrosphere.net.server;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -10,14 +12,59 @@ public class Player {
|
||||
|
||||
ServerConnectionHandler connectionHandler;
|
||||
int id;
|
||||
static Semaphore idIncrementerLock = new Semaphore(1);
|
||||
static int idIncrementer = 0;
|
||||
int worldX;
|
||||
int worldY;
|
||||
int simulationRadius = 3;
|
||||
Entity playerEntity;
|
||||
|
||||
public Player(){
|
||||
idIncrementerLock.acquireUninterruptibly();
|
||||
id = idIncrementer;
|
||||
idIncrementer++;
|
||||
idIncrementerLock.release();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setMessage(NetworkMessage message){
|
||||
public void addMessage(NetworkMessage message){
|
||||
connectionHandler.addMessagetoOutgoingQueue(message);
|
||||
}
|
||||
|
||||
public int getWorldX() {
|
||||
return worldX;
|
||||
}
|
||||
|
||||
public int getWorldY() {
|
||||
return worldY;
|
||||
}
|
||||
|
||||
public void setWorldX(int worldX) {
|
||||
this.worldX = worldX;
|
||||
}
|
||||
|
||||
public void setWorldY(int worldY) {
|
||||
this.worldY = worldY;
|
||||
}
|
||||
|
||||
public int getSimulationRadius() {
|
||||
return simulationRadius;
|
||||
}
|
||||
|
||||
public void setSimulationRadius(int simulationRadius) {
|
||||
this.simulationRadius = simulationRadius;
|
||||
}
|
||||
|
||||
public Entity getPlayerEntity() {
|
||||
return playerEntity;
|
||||
}
|
||||
|
||||
public void setPlayerEntity(Entity playerEntity) {
|
||||
this.playerEntity = playerEntity;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
29
src/main/java/electrosphere/net/server/PlayerManager.java
Normal file
29
src/main/java/electrosphere/net/server/PlayerManager.java
Normal file
@ -0,0 +1,29 @@
|
||||
package electrosphere.net.server;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class PlayerManager {
|
||||
|
||||
List<Player> playerList = new LinkedList();
|
||||
HashMap<Integer,Player> idMap = new HashMap();
|
||||
|
||||
public PlayerManager(){
|
||||
|
||||
}
|
||||
|
||||
public void addPlayer(Player player){
|
||||
playerList.add(player);
|
||||
idMap.put(player.getId(),player);
|
||||
}
|
||||
|
||||
public Player getPlayerFromId(int id){
|
||||
return idMap.get(id);
|
||||
}
|
||||
|
||||
}
|
||||
@ -93,10 +93,17 @@ public class ServerConnectionHandler implements Runnable {
|
||||
ex.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
Player newPlayerObject = new Player();
|
||||
Globals.playerManager.addPlayer(newPlayerObject);
|
||||
//spawn player in world
|
||||
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("Human");
|
||||
playerCharacterID = newPlayerCharacter.getId();
|
||||
CreatureUtils.positionCharacter(newPlayerCharacter, new Vector3f(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
|
||||
//attach player object to player character
|
||||
newPlayerObject.setPlayerEntity(newPlayerCharacter);
|
||||
newPlayerObject.setWorldX(Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x));
|
||||
newPlayerObject.setWorldY(Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z));
|
||||
Globals.dataCellManager.addPlayer(newPlayerObject);
|
||||
//spawn player sword
|
||||
Entity sword = ItemUtils.spawnBasicItem("Katana");
|
||||
AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.031");
|
||||
@ -104,6 +111,7 @@ public class ServerConnectionHandler implements Runnable {
|
||||
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
|
||||
if(Globals.RUN_SERVER && Main.playerId == -1){
|
||||
Globals.playerCharacter = newPlayerCharacter;
|
||||
Globals.serverPlayer = newPlayerObject;
|
||||
}
|
||||
//world metadata
|
||||
networkParser.addOutgoingMessage(
|
||||
@ -133,49 +141,49 @@ public class ServerConnectionHandler implements Runnable {
|
||||
//figure out what chunk they're in
|
||||
|
||||
//queue messages for that chunk
|
||||
if(Globals.RUN_SERVER && Main.playerId == -1){
|
||||
|
||||
} else {
|
||||
for(Entity currentEntity : Globals.entityManager.getMoveable()){
|
||||
networkParser.addOutgoingMessage(
|
||||
EntityMessage.constructCreateMessage(
|
||||
currentEntity.getId(),
|
||||
0, //0 for creatures
|
||||
CreatureUtils.getType(currentEntity),
|
||||
EntityUtils.getPosition(currentEntity).x,
|
||||
EntityUtils.getPosition(currentEntity).y,
|
||||
EntityUtils.getPosition(currentEntity).z
|
||||
)
|
||||
);
|
||||
if(CreatureUtils.isCreature(currentEntity)){
|
||||
if(CreatureUtils.hasControllerPlayerId(currentEntity)){
|
||||
LoggerInterface.loggerNetworking.INFO("Sending controller packets");
|
||||
networkParser.addOutgoingMessage(NetUtils.createSetCreatureControllerIdEntityMessage(currentEntity));
|
||||
}
|
||||
}
|
||||
}
|
||||
for(Entity currentEntity : Globals.entityManager.getItemEntities()){
|
||||
networkParser.addOutgoingMessage(
|
||||
EntityMessage.constructCreateMessage(
|
||||
currentEntity.getId(),
|
||||
1, //1 for items
|
||||
ItemUtils.getType(currentEntity),
|
||||
EntityUtils.getPosition(currentEntity).x,
|
||||
EntityUtils.getPosition(currentEntity).y,
|
||||
EntityUtils.getPosition(currentEntity).z
|
||||
)
|
||||
);
|
||||
if(AttachUtils.isAttached(currentEntity)){
|
||||
networkParser.addOutgoingMessage(
|
||||
EntityMessage.constructattachEntityToEntityMessage(
|
||||
currentEntity.getId(),
|
||||
AttachUtils.getTargetBone(currentEntity),
|
||||
AttachUtils.getParent(currentEntity).getId()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if(Globals.RUN_SERVER && Main.playerId == -1){
|
||||
//
|
||||
// } else {
|
||||
// for(Entity currentEntity : Globals.entityManager.getMoveable()){
|
||||
// networkParser.addOutgoingMessage(
|
||||
// EntityMessage.constructCreateMessage(
|
||||
// currentEntity.getId(),
|
||||
// 0, //0 for creatures
|
||||
// CreatureUtils.getType(currentEntity),
|
||||
// EntityUtils.getPosition(currentEntity).x,
|
||||
// EntityUtils.getPosition(currentEntity).y,
|
||||
// EntityUtils.getPosition(currentEntity).z
|
||||
// )
|
||||
// );
|
||||
// if(CreatureUtils.isCreature(currentEntity)){
|
||||
// if(CreatureUtils.hasControllerPlayerId(currentEntity)){
|
||||
// LoggerInterface.loggerNetworking.INFO("Sending controller packets");
|
||||
// networkParser.addOutgoingMessage(NetUtils.createSetCreatureControllerIdEntityMessage(currentEntity));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// for(Entity currentEntity : Globals.entityManager.getItemEntities()){
|
||||
// networkParser.addOutgoingMessage(
|
||||
// EntityMessage.constructCreateMessage(
|
||||
// currentEntity.getId(),
|
||||
// 1, //1 for items
|
||||
// ItemUtils.getType(currentEntity),
|
||||
// EntityUtils.getPosition(currentEntity).x,
|
||||
// EntityUtils.getPosition(currentEntity).y,
|
||||
// EntityUtils.getPosition(currentEntity).z
|
||||
// )
|
||||
// );
|
||||
// if(AttachUtils.isAttached(currentEntity)){
|
||||
// networkParser.addOutgoingMessage(
|
||||
// EntityMessage.constructattachEntityToEntityMessage(
|
||||
// currentEntity.getId(),
|
||||
// AttachUtils.getTargetBone(currentEntity),
|
||||
// AttachUtils.getParent(currentEntity).getId()
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
//let client know it's ready
|
||||
networkParser.addOutgoingMessage(StatusMessage.constructReadyMessage(1));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user