explicit ServerState object
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
austin 2025-05-15 12:57:56 -04:00
parent 56ffc5b879
commit 4e488e43cd
15 changed files with 51 additions and 29 deletions

View File

@ -1811,6 +1811,7 @@ Move playerEntity to clientState
Move playerCamera to clientState Move playerCamera to clientState
Move global cursor entities into cursorState Move global cursor entities into cursorState
Move lots of global state to clientState Move lots of global state to clientState
Create ServerState global

View File

@ -143,8 +143,8 @@ public class ImGuiPlayerEntity {
ImGui.text("View yaw (Server): " + ServerPlayerViewDirTree.getTree(serverPlayerEntity).getYaw()); ImGui.text("View yaw (Server): " + ServerPlayerViewDirTree.getTree(serverPlayerEntity).getYaw());
ImGui.text("View pitch (Server): " + ServerPlayerViewDirTree.getTree(serverPlayerEntity).getPitch()); ImGui.text("View pitch (Server): " + ServerPlayerViewDirTree.getTree(serverPlayerEntity).getPitch());
} }
if(Globals.server != null && Globals.server.getFirstConnection() != null && Globals.server.getFirstConnection().getPlayer() != null){ if(Globals.serverState.server != null && Globals.serverState.server.getFirstConnection() != null && Globals.serverState.server.getFirstConnection().getPlayer() != null){
ImGui.text("Player Object World Pos (Server): " + Globals.server.getFirstConnection().getPlayer().getWorldPos()); ImGui.text("Player Object World Pos (Server): " + Globals.serverState.server.getFirstConnection().getPlayer().getWorldPos());
} }
} }

View File

@ -54,8 +54,8 @@ public class ImGuiNetworkMonitor {
clientNetworkBandwith.draw(); clientNetworkBandwith.draw();
//server network pressure //server network pressure
if(Globals.server != null && Globals.server.getFirstConnection() != null){ if(Globals.serverState.server != null && Globals.serverState.server.getFirstConnection() != null){
long serverPressureNewTotal = Globals.server.getFirstConnection().getNumBytesRead(); long serverPressureNewTotal = Globals.serverState.server.getFirstConnection().getNumBytesRead();
long serverPressureDelta = serverPressureNewTotal - serverPressureLastValue; long serverPressureDelta = serverPressureNewTotal - serverPressureLastValue;
serverPressureDataset.addPoint(serverPressureDelta); serverPressureDataset.addPoint(serverPressureDelta);
serverPressureLastValue = serverPressureNewTotal; serverPressureLastValue = serverPressureNewTotal;

View File

@ -382,7 +382,7 @@ public class MenuGeneratorsInGame {
* @return True if should show button, false otherwise * @return True if should show button, false otherwise
*/ */
private static boolean shouldShowLevelEditor(){ private static boolean shouldShowLevelEditor(){
return Globals.server != null; return Globals.serverState.server != null;
} }
} }

View File

@ -41,7 +41,6 @@ import electrosphere.engine.time.Timekeeper;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.net.config.NetConfig; import electrosphere.net.config.NetConfig;
import electrosphere.net.monitor.NetMonitor; import electrosphere.net.monitor.NetMonitor;
import electrosphere.net.server.Server;
import electrosphere.net.server.player.PlayerManager; import electrosphere.net.server.player.PlayerManager;
import electrosphere.net.synchronization.server.EntityValueTrackingService; import electrosphere.net.synchronization.server.EntityValueTrackingService;
import electrosphere.net.synchronization.server.ServerSynchronizationManager; import electrosphere.net.synchronization.server.ServerSynchronizationManager;
@ -60,6 +59,7 @@ import electrosphere.renderer.ui.ElementService;
import electrosphere.renderer.ui.elements.ImagePanel; import electrosphere.renderer.ui.elements.ImagePanel;
import electrosphere.renderer.ui.font.FontManager; import electrosphere.renderer.ui.font.FontManager;
import electrosphere.script.ScriptEngine; import electrosphere.script.ScriptEngine;
import electrosphere.server.ServerState;
import electrosphere.server.ai.AIManager; import electrosphere.server.ai.AIManager;
import electrosphere.server.datacell.EntityDataCellMapper; import electrosphere.server.datacell.EntityDataCellMapper;
import electrosphere.server.datacell.RealmManager; import electrosphere.server.datacell.RealmManager;
@ -166,7 +166,6 @@ public class Globals {
// //
//Server manager thing //Server manager thing
// //
public static Server server;
public static ServerSynchronizationManager serverSynchronizationManager; public static ServerSynchronizationManager serverSynchronizationManager;
public static boolean RUN_SERVER = true; public static boolean RUN_SERVER = true;
@ -352,7 +351,11 @@ public class Globals {
* State for the client * State for the client
*/ */
public static ClientState clientState = new ClientState(); public static ClientState clientState = new ClientState();
/**
* State for the server
*/
public static ServerState serverState = new ServerState();
@ -415,6 +418,9 @@ public class Globals {
//client state //client state
Globals.clientState = new ClientState(); Globals.clientState = new ClientState();
//server state
Globals.serverState = new ServerState();
//load in default texture map //load in default texture map
textureMapDefault = TextureMap.construct("Textures/default_texture_map.json"); textureMapDefault = TextureMap.construct("Textures/default_texture_map.json");
//load model pretransforms //load model pretransforms
@ -630,7 +636,7 @@ public class Globals {
public static void unloadScene(){ public static void unloadScene(){
Globals.playerManager = new PlayerManager(); Globals.playerManager = new PlayerManager();
Globals.clientState = new ClientState(); Globals.clientState = new ClientState();
Globals.server = null; Globals.serverState = new ServerState();
Globals.serverSynchronizationManager = new ServerSynchronizationManager(); Globals.serverSynchronizationManager = new ServerSynchronizationManager();
if(Globals.aiManager != null){ if(Globals.aiManager != null){
Globals.aiManager.shutdown(); Globals.aiManager.shutdown();
@ -656,13 +662,13 @@ public class Globals {
Globals.elementService = null; Globals.elementService = null;
Globals.realmManager = null; Globals.realmManager = null;
Globals.clientState = null; Globals.clientState = null;
Globals.serverState = null;
Globals.audioEngine = null; Globals.audioEngine = null;
Globals.renderingEngine = null; Globals.renderingEngine = null;
Globals.threadManager = null; Globals.threadManager = null;
Globals.signalSystem = null; Globals.signalSystem = null;
Globals.serviceManager = null; Globals.serviceManager = null;
Globals.fileWatcherService = null; Globals.fileWatcherService = null;
Globals.server = null;
Globals.serverSynchronizationManager = null; Globals.serverSynchronizationManager = null;
Globals.aiManager = null; Globals.aiManager = null;
Globals.playerManager = null; Globals.playerManager = null;

View File

@ -50,8 +50,8 @@ public class LoadingUtils {
static void initServerThread(){ static void initServerThread(){
//start server networking //start server networking
if(Globals.RUN_SERVER){ if(Globals.RUN_SERVER){
Globals.server = new Server(NetUtils.getPort()); Globals.serverState.server = new Server(NetUtils.getPort());
Thread serverThread = new Thread(Globals.server); Thread serverThread = new Thread(Globals.serverState.server);
Globals.threadManager.start(ThreadLabel.NETWORKING_SERVER, serverThread); Globals.threadManager.start(ThreadLabel.NETWORKING_SERVER, serverThread);
} }
} }
@ -88,7 +88,7 @@ public class LoadingUtils {
if(runServerThread){ if(runServerThread){
LoadingUtils.initServerThread(); LoadingUtils.initServerThread();
} else { } else {
Globals.server = new Server(NetUtils.getPort()); Globals.serverState.server = new Server(NetUtils.getPort());
} }
//client -> server pipe //client -> server pipe
PipedInputStream clientInput = new PipedInputStream(STREAM_BUFFER_SIZE); PipedInputStream clientInput = new PipedInputStream(STREAM_BUFFER_SIZE);
@ -98,7 +98,7 @@ public class LoadingUtils {
PipedOutputStream clientOutput; PipedOutputStream clientOutput;
clientOutput = new PipedOutputStream(serverInput); clientOutput = new PipedOutputStream(serverInput);
//start server communication thread //start server communication thread
rVal = Globals.server.addLocalPlayer(serverInput, serverOutput); rVal = Globals.serverState.server.addLocalPlayer(serverInput, serverOutput);
//start client communication thread //start client communication thread
Globals.clientState.clientConnection = new ClientNetworking(clientInput,clientOutput); Globals.clientState.clientConnection = new ClientNetworking(clientInput,clientOutput);
Globals.threadManager.start(ThreadLabel.NETWORKING_CLIENT, new Thread(Globals.clientState.clientConnection)); Globals.threadManager.start(ThreadLabel.NETWORKING_CLIENT, new Thread(Globals.clientState.clientConnection));

View File

@ -60,8 +60,8 @@ public class MainMenuLoading {
* Resets the server state * Resets the server state
*/ */
private static void resetServerState(){ private static void resetServerState(){
Globals.server.close(); Globals.serverState.server.close();
Globals.server = null; Globals.serverState.server = null;
Globals.serverSynchronizationManager = null; Globals.serverSynchronizationManager = null;
Globals.realmManager.reset(); Globals.realmManager.reset();
Globals.realmManager = new RealmManager(); Globals.realmManager = new RealmManager();

View File

@ -145,8 +145,8 @@ public class ThreadManager {
threadLock.lock(); threadLock.lock();
//for some reason, server must be explicitly closed //for some reason, server must be explicitly closed
if(Globals.server != null){ if(Globals.serverState.server != null){
Globals.server.close(); Globals.serverState.server.close();
} }
if(Globals.realmManager != null && Globals.realmManager.getRealms() != null){ if(Globals.realmManager != null && Globals.realmManager.getRealms() != null){

View File

@ -119,7 +119,7 @@ public class Server implements Runnable {
} }
this.close(); this.close();
//null out global state //null out global state
Globals.server = null; Globals.serverState.server = null;
LoggerInterface.loggerNetworking.INFO("Server socket thread ended"); LoggerInterface.loggerNetworking.INFO("Server socket thread ended");
} }

View File

@ -230,7 +230,7 @@ public class ServerConnectionHandler implements Runnable {
initialized = true; initialized = true;
while(Globals.threadManager.shouldKeepRunning() && this.isConnected == true && Globals.server != null && Globals.server.isOpen()){ while(Globals.threadManager.shouldKeepRunning() && this.isConnected == true && Globals.serverState.server != null && Globals.serverState.server.isOpen()){
boolean receivedMessageThisLoop = false; boolean receivedMessageThisLoop = false;
// //
@ -494,8 +494,8 @@ public class ServerConnectionHandler implements Runnable {
this.synchronousMessageLock.release(); this.synchronousMessageLock.release();
this.isConnected = false; this.isConnected = false;
//add connection to server list of connections to cleanup //add connection to server list of connections to cleanup
if(Globals.server != null){ if(Globals.serverState.server != null){
Globals.server.addClientToCleanup(this); Globals.serverState.server.addClientToCleanup(this);
} }
} }

View File

@ -16,15 +16,15 @@ public class MainServerFunctions {
// //
//Cleanup disconnected clients //Cleanup disconnected clients
if(Globals.server != null){ if(Globals.serverState.server != null){
Globals.server.cleanupDeadConnections(); Globals.serverState.server.cleanupDeadConnections();
} }
// //
//Synchronous player message parsing\ //Synchronous player message parsing\
Globals.profiler.beginCpuSample("MainServerFunctions.simulate - Server synchronous packet parsing"); Globals.profiler.beginCpuSample("MainServerFunctions.simulate - Server synchronous packet parsing");
if(Globals.server != null){ if(Globals.serverState.server != null){
Globals.server.synchronousPacketHandling(); Globals.serverState.server.synchronousPacketHandling();
} }
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
Globals.profiler.beginCpuSample("MainServerFunctions.simulate - Server process synchronization messages"); Globals.profiler.beginCpuSample("MainServerFunctions.simulate - Server process synchronization messages");

View File

@ -0,0 +1,15 @@
package electrosphere.server;
import electrosphere.net.server.Server;
/**
* Server state
*/
public class ServerState {
/**
* Server networking
*/
public Server server;
}

View File

@ -21,12 +21,12 @@ public class StateCleanupCheckerExtension implements AfterEachCallback {
Globals.renderingEngine, Globals.renderingEngine,
Globals.audioEngine, Globals.audioEngine,
Globals.javaPID, Globals.javaPID,
Globals.server,
Globals.serverSynchronizationManager, Globals.serverSynchronizationManager,
Globals.playerManager, Globals.playerManager,
LoggerInterface.loggerEngine, LoggerInterface.loggerEngine,
RenderingEngine.screenFramebuffer, RenderingEngine.screenFramebuffer,
Globals.clientState, Globals.clientState,
Globals.serverState,
}; };
for(Object object : objectsToCheck){ for(Object object : objectsToCheck){
if(object != null){ if(object != null){

View File

@ -163,7 +163,7 @@ public class TestEngineUtils {
*/ */
public static void spawnPlayerEntity(){ public static void spawnPlayerEntity(){
ObjectTemplate creatureTemplate = ObjectTemplate.createDefault(EntityType.CREATURE, "human"); ObjectTemplate creatureTemplate = ObjectTemplate.createDefault(EntityType.CREATURE, "human");
ServerConnectionHandler serverConnection = Globals.server.getFirstConnection(); ServerConnectionHandler serverConnection = Globals.serverState.server.getFirstConnection();
serverConnection.setCreatureTemplate(creatureTemplate); serverConnection.setCreatureTemplate(creatureTemplate);
Character chara = Globals.characterService.createCharacter(creatureTemplate, serverConnection.getPlayerId()); Character chara = Globals.characterService.createCharacter(creatureTemplate, serverConnection.getPlayerId());
serverConnection.setCharacterId(chara.getId()); serverConnection.setCharacterId(chara.getId());

View File

@ -34,7 +34,7 @@ public class TestViewportUtils {
Entity creature = CreatureUtils.serverSpawnBasicCreature(Globals.realmManager.first(), new Vector3d(0,0,0), creatureType, creatureTemplate); Entity creature = CreatureUtils.serverSpawnBasicCreature(Globals.realmManager.first(), new Vector3d(0,0,0), creatureType, creatureTemplate);
//get required data //get required data
ServerConnectionHandler connectionHandler = Globals.server.getFirstConnection(); ServerConnectionHandler connectionHandler = Globals.serverState.server.getFirstConnection();
Player playerObj = Globals.playerManager.getFirstPlayer(); Player playerObj = Globals.playerManager.getFirstPlayer();
//attach //attach