some work on networking, fix for vsc perf
This commit is contained in:
parent
a8644582cb
commit
40ce8dd161
@ -1 +1,10 @@
|
|||||||
org.eclipse.jdt.core.compiler.problem.unusedImport=ignore
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=17
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedImport=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=17
|
||||||
|
|||||||
@ -262,7 +262,7 @@
|
|||||||
"maxHealth" : 100,
|
"maxHealth" : 100,
|
||||||
"onDamageIFrames" : 30
|
"onDamageIFrames" : 30
|
||||||
},
|
},
|
||||||
"modelPath" : "Models/baseman2.fbx"
|
"modelPath" : "Models/baseman4.fbx"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"files" : []
|
"files" : []
|
||||||
|
|||||||
Binary file not shown.
BIN
assets/Models/baseman4.fbx
Normal file
BIN
assets/Models/baseman4.fbx
Normal file
Binary file not shown.
@ -413,6 +413,7 @@ public class LoadingThread extends Thread {
|
|||||||
|
|
||||||
static void initDataCellManager(){
|
static void initDataCellManager(){
|
||||||
Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
|
Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
|
||||||
|
Globals.dataCellManager.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -20,19 +20,23 @@ import org.joml.Vector3f;
|
|||||||
public class DataCellManager {
|
public class DataCellManager {
|
||||||
|
|
||||||
List<ServerDataCell> loadedDataCells = new LinkedList<ServerDataCell>();
|
List<ServerDataCell> loadedDataCells = new LinkedList<ServerDataCell>();
|
||||||
ServerDataCell[][] dataCells;
|
//these are going to be the natural ground grid of data cells, but we're going to have more than this
|
||||||
|
ServerDataCell[][] groundDataCells;
|
||||||
int discreteWorldSize;
|
int discreteWorldSize;
|
||||||
|
//this is the cell that all players loading into the game (via connection startup, death, etc) reside in
|
||||||
List<Player> playerList = new LinkedList<Player>();
|
ServerDataCell loadingCell;
|
||||||
|
|
||||||
public DataCellManager(ServerWorldData data) {
|
public DataCellManager(ServerWorldData data) {
|
||||||
discreteWorldSize = data.getWorldSizeDiscrete();
|
discreteWorldSize = data.getWorldSizeDiscrete();
|
||||||
dataCells = new ServerDataCell[discreteWorldSize][discreteWorldSize];
|
groundDataCells = new ServerDataCell[discreteWorldSize][discreteWorldSize];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(){
|
||||||
|
loadingCell = new ServerDataCell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addPlayer(Player player){
|
public void addPlayerToGroundCells(Player player){
|
||||||
playerList.add(player);
|
|
||||||
int playerSimulationRadius = player.getSimulationRadius();
|
int playerSimulationRadius = player.getSimulationRadius();
|
||||||
int oldX = player.getWorldX();
|
int oldX = player.getWorldX();
|
||||||
int oldY = player.getWorldY();
|
int oldY = player.getWorldY();
|
||||||
@ -43,20 +47,20 @@ public class DataCellManager {
|
|||||||
y >= 0 && y < discreteWorldSize
|
y >= 0 && y < discreteWorldSize
|
||||||
){
|
){
|
||||||
LoggerInterface.loggerEngine.DEBUG("DataCellManager: Add player to " + x + " " + y);
|
LoggerInterface.loggerEngine.DEBUG("DataCellManager: Add player to " + x + " " + y);
|
||||||
if(dataCells[x][y] != null){
|
if(groundDataCells[x][y] != null){
|
||||||
dataCells[x][y].addPlayer(player);
|
groundDataCells[x][y].addPlayer(player);
|
||||||
} else {
|
} else {
|
||||||
//create data cell
|
//create data cell
|
||||||
dataCells[x][y] = ServerDataCell.loadCellAtWorldCoord(x, y);
|
groundDataCells[x][y] = ServerDataCell.loadCellAtWorldCoord(x, y);
|
||||||
//add player
|
//add player
|
||||||
dataCells[x][y].addPlayer(player);
|
groundDataCells[x][y].addPlayer(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void movePlayer(Player player, int newX, int newY){
|
public void movePlayerGroundCells(Player player, int newX, int newY){
|
||||||
int playerSimulationRadius = player.getSimulationRadius();
|
int playerSimulationRadius = player.getSimulationRadius();
|
||||||
int oldX = player.getWorldX();
|
int oldX = player.getWorldX();
|
||||||
int oldY = player.getWorldY();
|
int oldY = player.getWorldY();
|
||||||
@ -72,10 +76,10 @@ public class DataCellManager {
|
|||||||
y >= 0 && y < discreteWorldSize &&
|
y >= 0 && y < discreteWorldSize &&
|
||||||
(x < newX - playerSimulationRadius || x > newX + playerSimulationRadius || y < newY - playerSimulationRadius || y > newY + playerSimulationRadius)
|
(x < newX - playerSimulationRadius || x > newX + playerSimulationRadius || y < newY - playerSimulationRadius || y > newY + playerSimulationRadius)
|
||||||
){
|
){
|
||||||
if(dataCells[x][y] != null){
|
if(groundDataCells[x][y] != null){
|
||||||
if(dataCells[x][y].containsPlayer(player)){
|
if(groundDataCells[x][y].containsPlayer(player)){
|
||||||
// removals++;
|
// removals++;
|
||||||
dataCells[x][y].removePlayer(player);
|
groundDataCells[x][y].removePlayer(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,13 +93,13 @@ public class DataCellManager {
|
|||||||
(x < oldX - playerSimulationRadius || x > oldX + playerSimulationRadius || y < oldY - playerSimulationRadius || y > oldY + playerSimulationRadius)
|
(x < oldX - playerSimulationRadius || x > oldX + playerSimulationRadius || y < oldY - playerSimulationRadius || y > oldY + playerSimulationRadius)
|
||||||
){
|
){
|
||||||
// System.out.println("Add player to " + x + " " + y);
|
// System.out.println("Add player to " + x + " " + y);
|
||||||
if(dataCells[x][y] != null){
|
if(groundDataCells[x][y] != null){
|
||||||
dataCells[x][y].addPlayer(player);
|
groundDataCells[x][y].addPlayer(player);
|
||||||
} else {
|
} else {
|
||||||
//create data cell
|
//create data cell
|
||||||
dataCells[x][y] = ServerDataCell.loadCellAtWorldCoord(x, y);
|
groundDataCells[x][y] = ServerDataCell.loadCellAtWorldCoord(x, y);
|
||||||
//add player
|
//add player
|
||||||
dataCells[x][y].addPlayer(player);
|
groundDataCells[x][y].addPlayer(player);
|
||||||
}
|
}
|
||||||
// additions++;
|
// additions++;
|
||||||
} else {
|
} else {
|
||||||
@ -111,16 +115,16 @@ public class DataCellManager {
|
|||||||
throw new UnsupportedOperationException("Removing players from the data cell manager isn't supported -- DataCellManager -- removePlayer(Player player)");
|
throw new UnsupportedOperationException("Removing players from the data cell manager isn't supported -- DataCellManager -- removePlayer(Player player)");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updatePlayerPositions(){
|
public boolean updatePlayerGroundCellPositions(){
|
||||||
boolean playerChangedChunk = false;
|
boolean playerChangedChunk = false;
|
||||||
for(Player player : playerList){
|
for(Player player : Globals.playerManager.getPlayers()){
|
||||||
Entity playerEntity = player.getPlayerEntity();
|
Entity playerEntity = player.getPlayerEntity();
|
||||||
if(playerEntity != null){
|
if(playerEntity != null && !loadingCell.containsPlayer(player)){
|
||||||
Vector3d position = EntityUtils.getPosition(playerEntity);
|
Vector3d position = EntityUtils.getPosition(playerEntity);
|
||||||
int currentWorldX = Globals.serverWorldData.convertRealToChunkSpace(position.x);
|
int currentWorldX = Globals.serverWorldData.convertRealToChunkSpace(position.x);
|
||||||
int currentWorldY = Globals.serverWorldData.convertRealToChunkSpace(position.z);
|
int currentWorldY = Globals.serverWorldData.convertRealToChunkSpace(position.z);
|
||||||
if(currentWorldX != player.getWorldX() || currentWorldY != player.getWorldY()){
|
if(currentWorldX != player.getWorldX() || currentWorldY != player.getWorldY()){
|
||||||
movePlayer(player,currentWorldX,currentWorldY);
|
movePlayerGroundCells(player,currentWorldX,currentWorldY);
|
||||||
playerChangedChunk = true;
|
playerChangedChunk = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,17 +135,17 @@ public class DataCellManager {
|
|||||||
public void sendNetworkMessageToChunk(NetworkMessage message, int worldX, int worldY){
|
public void sendNetworkMessageToChunk(NetworkMessage message, int worldX, int worldY){
|
||||||
if(
|
if(
|
||||||
//in bounds of array
|
//in bounds of array
|
||||||
worldX >= 0 && worldX < dataCells.length &&
|
worldX >= 0 && worldX < groundDataCells.length &&
|
||||||
worldY >= 0 && worldY < dataCells[0].length &&
|
worldY >= 0 && worldY < groundDataCells[0].length &&
|
||||||
//isn't null
|
//isn't null
|
||||||
dataCells[worldX][worldY] != null
|
groundDataCells[worldX][worldY] != null
|
||||||
){
|
){
|
||||||
dataCells[worldX][worldY].broadcastNetworkMessage(message);
|
groundDataCells[worldX][worldY].broadcastNetworkMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unloadPlayerlessChunks(){
|
public void unloadPlayerlessChunks(){
|
||||||
|
//TODO: implement and actually call it
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,6 +81,7 @@ public class SaveUtils {
|
|||||||
SaveUtils.loadTerrainAndDB(Globals.currentSaveName);
|
SaveUtils.loadTerrainAndDB(Globals.currentSaveName);
|
||||||
Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager);
|
Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager);
|
||||||
Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
|
Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
|
||||||
|
Globals.dataCellManager.init();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -128,7 +128,7 @@ public class MicroSimulation {
|
|||||||
Globals.entityManager.simulateBehaviorTrees();
|
Globals.entityManager.simulateBehaviorTrees();
|
||||||
//data cell manager update
|
//data cell manager update
|
||||||
if(Globals.dataCellManager != null){
|
if(Globals.dataCellManager != null){
|
||||||
boolean playerHasChangedChunk = Globals.dataCellManager.updatePlayerPositions();
|
boolean playerHasChangedChunk = Globals.dataCellManager.updatePlayerGroundCellPositions();
|
||||||
if(playerHasChangedChunk){
|
if(playerHasChangedChunk){
|
||||||
Globals.dataCellManager.unloadPlayerlessChunks();
|
Globals.dataCellManager.unloadPlayerlessChunks();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package electrosphere.net.server;
|
package electrosphere.net.server;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,20 +12,22 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class PlayerManager {
|
public class PlayerManager {
|
||||||
|
|
||||||
List<Player> playerList = new LinkedList<Player>();
|
|
||||||
Map<Integer,Player> idMap = new HashMap<Integer,Player>();
|
Map<Integer,Player> idMap = new HashMap<Integer,Player>();
|
||||||
|
|
||||||
public PlayerManager(){
|
public PlayerManager(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayer(Player player){
|
public void registerPlayer(Player player){
|
||||||
playerList.add(player);
|
|
||||||
idMap.put(player.getId(),player);
|
idMap.put(player.getId(),player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayerFromId(int id){
|
public Player getPlayerFromId(int id){
|
||||||
return idMap.get(id);
|
return idMap.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Player> getPlayers(){
|
||||||
|
return new LinkedList<Player>(idMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,29 +95,7 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
Player newPlayerObject = new Player(this);
|
spawnPlayerCharacter();
|
||||||
Globals.playerManager.addPlayer(newPlayerObject);
|
|
||||||
//spawn player in world
|
|
||||||
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("human");
|
|
||||||
playerCharacterID = newPlayerCharacter.getId();
|
|
||||||
CollisionObjUtils.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));
|
|
||||||
System.out.println(EntityUtils.getRotation(newPlayerCharacter).set(0,1,0,1).normalize());
|
|
||||||
Globals.dataCellManager.addPlayer(newPlayerObject);
|
|
||||||
Globals.dataCellManager.movePlayer(newPlayerObject, Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x), Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z));
|
|
||||||
IronSightTree.attachIronSightTree(newPlayerCharacter);
|
|
||||||
// //spawn player sword
|
|
||||||
// Entity sword = ItemUtils.spawnBasicItem("Katana");
|
|
||||||
// AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.031");
|
|
||||||
//set controller id
|
|
||||||
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
|
|
||||||
if(Globals.RUN_SERVER && Main.playerId == -1){
|
|
||||||
Globals.playerCharacter = newPlayerCharacter;
|
|
||||||
Globals.serverPlayer = newPlayerObject;
|
|
||||||
}
|
|
||||||
//world metadata
|
//world metadata
|
||||||
networkParser.addOutgoingMessage(
|
networkParser.addOutgoingMessage(
|
||||||
WorldMessage.constructMetadataMessage(
|
WorldMessage.constructMetadataMessage(
|
||||||
@ -213,7 +191,31 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void spawnPlayerCharacter(){
|
||||||
|
Player newPlayerObject = new Player(this);
|
||||||
|
Globals.playerManager.registerPlayer(newPlayerObject);
|
||||||
|
//spawn player in world
|
||||||
|
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("human");
|
||||||
|
playerCharacterID = newPlayerCharacter.getId();
|
||||||
|
CollisionObjUtils.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));
|
||||||
|
// System.out.println(EntityUtils.getRotation(newPlayerCharacter).set(0,1,0,1).normalize());
|
||||||
|
Globals.dataCellManager.addPlayerToGroundCells(newPlayerObject);
|
||||||
|
Globals.dataCellManager.movePlayerGroundCells(newPlayerObject, Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x), Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z));
|
||||||
|
IronSightTree.attachIronSightTree(newPlayerCharacter);
|
||||||
|
// //spawn player sword
|
||||||
|
// Entity sword = ItemUtils.spawnBasicItem("Katana");
|
||||||
|
// AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.031");
|
||||||
|
//set controller id
|
||||||
|
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
|
||||||
|
if(Globals.RUN_SERVER && Main.playerId == -1){
|
||||||
|
Globals.playerCharacter = newPlayerCharacter;
|
||||||
|
Globals.serverPlayer = newPlayerObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user