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,
|
||||
"onDamageIFrames" : 30
|
||||
},
|
||||
"modelPath" : "Models/baseman2.fbx"
|
||||
"modelPath" : "Models/baseman4.fbx"
|
||||
}
|
||||
],
|
||||
"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(){
|
||||
Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
|
||||
Globals.dataCellManager.init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -20,19 +20,23 @@ import org.joml.Vector3f;
|
||||
public class DataCellManager {
|
||||
|
||||
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;
|
||||
|
||||
List<Player> playerList = new LinkedList<Player>();
|
||||
//this is the cell that all players loading into the game (via connection startup, death, etc) reside in
|
||||
ServerDataCell loadingCell;
|
||||
|
||||
public DataCellManager(ServerWorldData data) {
|
||||
discreteWorldSize = data.getWorldSizeDiscrete();
|
||||
dataCells = new ServerDataCell[discreteWorldSize][discreteWorldSize];
|
||||
groundDataCells = new ServerDataCell[discreteWorldSize][discreteWorldSize];
|
||||
}
|
||||
|
||||
public void init(){
|
||||
loadingCell = new ServerDataCell();
|
||||
}
|
||||
|
||||
|
||||
public void addPlayer(Player player){
|
||||
playerList.add(player);
|
||||
public void addPlayerToGroundCells(Player player){
|
||||
int playerSimulationRadius = player.getSimulationRadius();
|
||||
int oldX = player.getWorldX();
|
||||
int oldY = player.getWorldY();
|
||||
@ -43,20 +47,20 @@ public class DataCellManager {
|
||||
y >= 0 && y < discreteWorldSize
|
||||
){
|
||||
LoggerInterface.loggerEngine.DEBUG("DataCellManager: Add player to " + x + " " + y);
|
||||
if(dataCells[x][y] != null){
|
||||
dataCells[x][y].addPlayer(player);
|
||||
if(groundDataCells[x][y] != null){
|
||||
groundDataCells[x][y].addPlayer(player);
|
||||
} else {
|
||||
//create data cell
|
||||
dataCells[x][y] = ServerDataCell.loadCellAtWorldCoord(x, y);
|
||||
groundDataCells[x][y] = ServerDataCell.loadCellAtWorldCoord(x, y);
|
||||
//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 oldX = player.getWorldX();
|
||||
int oldY = player.getWorldY();
|
||||
@ -72,10 +76,10 @@ public class DataCellManager {
|
||||
y >= 0 && y < discreteWorldSize &&
|
||||
(x < newX - playerSimulationRadius || x > newX + playerSimulationRadius || y < newY - playerSimulationRadius || y > newY + playerSimulationRadius)
|
||||
){
|
||||
if(dataCells[x][y] != null){
|
||||
if(dataCells[x][y].containsPlayer(player)){
|
||||
if(groundDataCells[x][y] != null){
|
||||
if(groundDataCells[x][y].containsPlayer(player)){
|
||||
// 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)
|
||||
){
|
||||
// System.out.println("Add player to " + x + " " + y);
|
||||
if(dataCells[x][y] != null){
|
||||
dataCells[x][y].addPlayer(player);
|
||||
if(groundDataCells[x][y] != null){
|
||||
groundDataCells[x][y].addPlayer(player);
|
||||
} else {
|
||||
//create data cell
|
||||
dataCells[x][y] = ServerDataCell.loadCellAtWorldCoord(x, y);
|
||||
groundDataCells[x][y] = ServerDataCell.loadCellAtWorldCoord(x, y);
|
||||
//add player
|
||||
dataCells[x][y].addPlayer(player);
|
||||
groundDataCells[x][y].addPlayer(player);
|
||||
}
|
||||
// additions++;
|
||||
} 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)");
|
||||
}
|
||||
|
||||
public boolean updatePlayerPositions(){
|
||||
public boolean updatePlayerGroundCellPositions(){
|
||||
boolean playerChangedChunk = false;
|
||||
for(Player player : playerList){
|
||||
for(Player player : Globals.playerManager.getPlayers()){
|
||||
Entity playerEntity = player.getPlayerEntity();
|
||||
if(playerEntity != null){
|
||||
if(playerEntity != null && !loadingCell.containsPlayer(player)){
|
||||
Vector3d 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);
|
||||
movePlayerGroundCells(player,currentWorldX,currentWorldY);
|
||||
playerChangedChunk = true;
|
||||
}
|
||||
}
|
||||
@ -131,17 +135,17 @@ public class DataCellManager {
|
||||
public void sendNetworkMessageToChunk(NetworkMessage message, int worldX, int worldY){
|
||||
if(
|
||||
//in bounds of array
|
||||
worldX >= 0 && worldX < dataCells.length &&
|
||||
worldY >= 0 && worldY < dataCells[0].length &&
|
||||
worldX >= 0 && worldX < groundDataCells.length &&
|
||||
worldY >= 0 && worldY < groundDataCells[0].length &&
|
||||
//isn't null
|
||||
dataCells[worldX][worldY] != null
|
||||
groundDataCells[worldX][worldY] != null
|
||||
){
|
||||
dataCells[worldX][worldY].broadcastNetworkMessage(message);
|
||||
groundDataCells[worldX][worldY].broadcastNetworkMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadPlayerlessChunks(){
|
||||
|
||||
//TODO: implement and actually call it
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -81,6 +81,7 @@ public class SaveUtils {
|
||||
SaveUtils.loadTerrainAndDB(Globals.currentSaveName);
|
||||
Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager);
|
||||
Globals.dataCellManager = new DataCellManager(Globals.serverWorldData);
|
||||
Globals.dataCellManager.init();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -128,7 +128,7 @@ public class MicroSimulation {
|
||||
Globals.entityManager.simulateBehaviorTrees();
|
||||
//data cell manager update
|
||||
if(Globals.dataCellManager != null){
|
||||
boolean playerHasChangedChunk = Globals.dataCellManager.updatePlayerPositions();
|
||||
boolean playerHasChangedChunk = Globals.dataCellManager.updatePlayerGroundCellPositions();
|
||||
if(playerHasChangedChunk){
|
||||
Globals.dataCellManager.unloadPlayerlessChunks();
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package electrosphere.net.server;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -11,20 +12,22 @@ import java.util.Map;
|
||||
*/
|
||||
public class PlayerManager {
|
||||
|
||||
List<Player> playerList = new LinkedList<Player>();
|
||||
Map<Integer,Player> idMap = new HashMap<Integer,Player>();
|
||||
|
||||
public PlayerManager(){
|
||||
|
||||
}
|
||||
|
||||
public void addPlayer(Player player){
|
||||
playerList.add(player);
|
||||
public void registerPlayer(Player player){
|
||||
idMap.put(player.getId(),player);
|
||||
}
|
||||
|
||||
public Player getPlayerFromId(int 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();
|
||||
System.exit(1);
|
||||
}
|
||||
Player newPlayerObject = new Player(this);
|
||||
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;
|
||||
}
|
||||
spawnPlayerCharacter();
|
||||
//world metadata
|
||||
networkParser.addOutgoingMessage(
|
||||
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