move thread manager into engineState

This commit is contained in:
austin 2025-05-15 14:09:52 -04:00
parent 70f76202b1
commit 038da702e7
28 changed files with 97 additions and 77 deletions

View File

@ -1816,6 +1816,8 @@ Move realmManager to serverState
Move characterService to serverState Move characterService to serverState
Move entityValueTrackingService to serverState Move entityValueTrackingService to serverState
Move playerManager to serverState Move playerManager to serverState
Create EngineState global
Move threadManager into engineState

View File

@ -43,7 +43,7 @@ public class MenuCharacterCreation {
Div charNameContainer = Div.createRow(Button.createButton(buttonTitle, () -> { Div charNameContainer = Div.createRow(Button.createButton(buttonTitle, () -> {
Globals.clientState.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestSpawnCharacterMessage(description.getId())); Globals.clientState.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestSpawnCharacterMessage(description.getId()));
Globals.clientState.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage()); Globals.clientState.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage());
Globals.threadManager.start(new LoadingThread(LoadingThreadType.CLIENT_WORLD)); Globals.engineState.threadManager.start(new LoadingThread(LoadingThreadType.CLIENT_WORLD));
})); }));
selectContainer.addChild(charNameContainer); selectContainer.addChild(charNameContainer);
} }

View File

@ -134,7 +134,7 @@ public class MenuGeneratorsLevelEditor {
LoadingThread loadingThread = new LoadingThread(LoadingThreadType.LEVEL, saveName); LoadingThread loadingThread = new LoadingThread(LoadingThreadType.LEVEL, saveName);
Globals.RUN_CLIENT = true; Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true; Globals.RUN_SERVER = true;
Globals.threadManager.start(loadingThread); Globals.engineState.threadManager.start(loadingThread);
}).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE); }).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE);
// //
@ -143,7 +143,7 @@ public class MenuGeneratorsLevelEditor {
Button editButton = Button.createButton("Edit", () -> { Button editButton = Button.createButton("Edit", () -> {
//launch level editor //launch level editor
LoadingThread loadingThread = new LoadingThread(LoadingThreadType.LEVEL_EDITOR, saveName); LoadingThread loadingThread = new LoadingThread(LoadingThreadType.LEVEL_EDITOR, saveName);
Globals.threadManager.start(loadingThread); Globals.engineState.threadManager.start(loadingThread);
}).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE); }).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE);
//create row //create row
@ -282,7 +282,7 @@ public class MenuGeneratorsLevelEditor {
Button createButton = Button.createButton("Create Level", () -> { Button createButton = Button.createButton("Create Level", () -> {
//launch level editor //launch level editor
LoadingThread loadingThread = new LoadingThread(LoadingThreadType.LEVEL_EDITOR, inFlightLevel); LoadingThread loadingThread = new LoadingThread(LoadingThreadType.LEVEL_EDITOR, inFlightLevel);
Globals.threadManager.start(loadingThread); Globals.engineState.threadManager.start(loadingThread);
}).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE); }).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE);
createButton.setAlignSelf(YogaAlignment.Center); createButton.setAlignSelf(YogaAlignment.Center);
rVal.addChild(createButton); rVal.addChild(createButton);

View File

@ -91,8 +91,8 @@ public class MenuGeneratorsMultiplayer {
LoadingThread serverThread = new LoadingThread(LoadingThreadType.MAIN_GAME); LoadingThread serverThread = new LoadingThread(LoadingThreadType.MAIN_GAME);
Globals.RUN_CLIENT = true; Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true; Globals.RUN_SERVER = true;
Globals.threadManager.start(serverThread); Globals.engineState.threadManager.start(serverThread);
Globals.threadManager.start(clientThread); Globals.engineState.threadManager.start(clientThread);
})); }));
//button (join) //button (join)
@ -184,7 +184,7 @@ public class MenuGeneratorsMultiplayer {
LoadingThread clientThread = new LoadingThread(LoadingThreadType.CHARACTER_SERVER); LoadingThread clientThread = new LoadingThread(LoadingThreadType.CHARACTER_SERVER);
Globals.RUN_CLIENT = true; Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = false; Globals.RUN_SERVER = false;
Globals.threadManager.start(clientThread); Globals.engineState.threadManager.start(clientThread);
})); }));
//button (back) //button (back)

View File

@ -106,7 +106,7 @@ public class MenuGeneratorsTitleMenu {
//button (Viewport Test) //button (Viewport Test)
{ {
Button button = Button.createButtonCentered("Viewport Test", 1.0f, () -> { Button button = Button.createButtonCentered("Viewport Test", 1.0f, () -> {
Globals.threadManager.start(new LoadingThread(LoadingThreadType.LOAD_VIEWPORT)); Globals.engineState.threadManager.start(new LoadingThread(LoadingThreadType.LOAD_VIEWPORT));
}).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE); }).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE);
button.setMarginTop(BUTTON_SPACING); button.setMarginTop(BUTTON_SPACING);
optionPanel.addChild(button); optionPanel.addChild(button);

View File

@ -60,7 +60,7 @@ public class MenuWorldSelect {
LoadingThread serverThread = new LoadingThread(LoadingThreadType.MAIN_GAME, saveName, Globals.clientState.clientUsername, Globals.clientState.clientPassword); LoadingThread serverThread = new LoadingThread(LoadingThreadType.MAIN_GAME, saveName, Globals.clientState.clientUsername, Globals.clientState.clientPassword);
Globals.RUN_CLIENT = true; Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true; Globals.RUN_SERVER = true;
Globals.threadManager.start(serverThread); Globals.engineState.threadManager.start(serverThread);
} else { } else {
SaveUtils.loadSave(saveName.toLowerCase(), false); SaveUtils.loadSave(saveName.toLowerCase(), false);
WindowUtils.replaceMainMenuContents(MenuWorldSelect.createSaveCreationMenu()); WindowUtils.replaceMainMenuContents(MenuWorldSelect.createSaveCreationMenu());

View File

@ -0,0 +1,15 @@
package electrosphere.engine;
import electrosphere.engine.threads.ThreadManager;
/**
* State of the engine
*/
public class EngineState {
/**
* The thread manager
*/
public final ThreadManager threadManager = new ThreadManager();
}

View File

@ -36,7 +36,6 @@ import electrosphere.engine.profiler.Profiler;
import electrosphere.engine.service.ServiceManager; import electrosphere.engine.service.ServiceManager;
import electrosphere.engine.signal.SignalSystem; import electrosphere.engine.signal.SignalSystem;
import electrosphere.engine.signal.sync.MainThreadSignalService; import electrosphere.engine.signal.sync.MainThreadSignalService;
import electrosphere.engine.threads.ThreadManager;
import electrosphere.engine.time.Timekeeper; import electrosphere.engine.time.Timekeeper;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.net.config.NetConfig; import electrosphere.net.config.NetConfig;
@ -74,11 +73,6 @@ public class Globals {
// //
public static String javaPID; public static String javaPID;
//
//Thread manager
//
public static ThreadManager threadManager;
// //
//Service manager //Service manager
// //
@ -99,6 +93,21 @@ public class Globals {
// //
public static Timekeeper timekeeper; public static Timekeeper timekeeper;
/**
* State for the engine
*/
public static EngineState engineState;
/**
* State for the client
*/
public static ClientState clientState;
/**
* State for the server
*/
public static ServerState serverState;
// //
//Rendering Engine //Rendering Engine
// //
@ -312,16 +321,6 @@ public class Globals {
//collision world data //collision world data
public static CollisionWorldData commonWorldData; public static CollisionWorldData commonWorldData;
/**
* State for the client
*/
public static ClientState clientState = new ClientState();
/**
* State for the server
*/
public static ServerState serverState = new ServerState();
// //
@ -368,8 +367,8 @@ public class Globals {
UserSettings.loadUserSettings(); UserSettings.loadUserSettings();
//timekeeper //timekeeper
timekeeper = new Timekeeper(); timekeeper = new Timekeeper();
Globals.threadManager = new ThreadManager(); Globals.engineState = new EngineState();
Globals.threadManager.init(); Globals.engineState.threadManager.init();
//render flags //render flags
RENDER_FLAG_RENDER_SHADOW_MAP = false; RENDER_FLAG_RENDER_SHADOW_MAP = false;
@ -590,26 +589,29 @@ public class Globals {
* Unloads scene * Unloads scene
*/ */
public static void unloadScene(){ public static void unloadScene(){
Globals.serverState.aiManager.shutdown(); if(Globals.serverState != null){
Globals.serverState.realmManager.reset(); Globals.serverState.aiManager.shutdown();
Globals.serverState.realmManager.reset();
}
Globals.dbController.disconnect();
Globals.serviceManager.unloadScene();
Globals.clientState = new ClientState(); Globals.clientState = new ClientState();
Globals.serverState = new ServerState(); Globals.serverState = new ServerState();
if(Globals.serviceManager != null){ if(Globals.serviceManager != null){
Globals.serverState.characterService = (CharacterService)Globals.serviceManager.registerService(new CharacterService()); Globals.serverState.characterService = (CharacterService)Globals.serviceManager.registerService(new CharacterService());
} }
Globals.dbController.disconnect();
Globals.serviceManager.unloadScene();
} }
/** /**
* Resets global values * Resets global values
*/ */
public static void resetGlobals(){ public static void resetGlobals(){
Globals.unloadScene(); if(Globals.serverState != null){
if(Globals.serverState != null && Globals.serverState.aiManager != null){
Globals.serverState.aiManager.shutdown(); Globals.serverState.aiManager.shutdown();
Globals.serverState.realmManager.reset();
} }
Globals.dbController.disconnect();
// //
//Actual globals to destroy //Actual globals to destroy
Globals.assetManager = null; Globals.assetManager = null;
@ -617,8 +619,8 @@ public class Globals {
Globals.clientState = null; Globals.clientState = null;
Globals.serverState = null; Globals.serverState = null;
Globals.audioEngine = null; Globals.audioEngine = null;
Globals.engineState = null;
Globals.renderingEngine = null; Globals.renderingEngine = null;
Globals.threadManager = null;
Globals.signalSystem = null; Globals.signalSystem = null;
Globals.serviceManager = null; Globals.serviceManager = null;
Globals.fileWatcherService = null; Globals.fileWatcherService = null;

View File

@ -112,7 +112,7 @@ public class Main {
//init scripting engine //init scripting engine
if(Globals.RUN_SCRIPTS){ if(Globals.RUN_SCRIPTS){
Globals.threadManager.start(new LoadingThread(LoadingThreadType.SCRIPT_ENGINE)); Globals.engineState.threadManager.start(new LoadingThread(LoadingThreadType.SCRIPT_ENGINE));
} }
//controls //controls
@ -138,7 +138,7 @@ public class Main {
Globals.controlHandler.hintUpdateControlState(ControlsState.TITLE_MENU); Globals.controlHandler.hintUpdateControlState(ControlsState.TITLE_MENU);
//start initial asset loading //start initial asset loading
Globals.threadManager.start(new LoadingThread(LoadingThreadType.INIT_ASSETS)); Globals.engineState.threadManager.start(new LoadingThread(LoadingThreadType.INIT_ASSETS));
} }
//Sets a hook that fires when the engine process stops //Sets a hook that fires when the engine process stops
@ -165,10 +165,10 @@ public class Main {
LoggerInterface.loggerStartup.INFO("Fire off loading thread"); LoggerInterface.loggerStartup.INFO("Fire off loading thread");
if(Globals.RUN_DEMO){ if(Globals.RUN_DEMO){
LoadingThread serverThread = new LoadingThread(LoadingThreadType.DEMO_MENU); LoadingThread serverThread = new LoadingThread(LoadingThreadType.DEMO_MENU);
Globals.threadManager.start(serverThread); Globals.engineState.threadManager.start(serverThread);
} else if(Globals.RUN_CLIENT){ } else if(Globals.RUN_CLIENT){
LoadingThread serverThread = new LoadingThread(LoadingThreadType.TITLE_MENU); LoadingThread serverThread = new LoadingThread(LoadingThreadType.TITLE_MENU);
Globals.threadManager.start(serverThread); Globals.engineState.threadManager.start(serverThread);
} else { } else {
throw new IllegalStateException("Need to add handling for only running server again"); throw new IllegalStateException("Need to add handling for only running server again");
} }
@ -208,7 +208,7 @@ public class Main {
//Update timekeeper, thread manager, and process all main thread signals //Update timekeeper, thread manager, and process all main thread signals
// //
Globals.timekeeper.update(); Globals.timekeeper.update();
Globals.threadManager.update(); Globals.engineState.threadManager.update();
@ -431,8 +431,8 @@ public class Main {
Globals.renderingEngine.destroy(); Globals.renderingEngine.destroy();
} }
//used to signal threads to stop //used to signal threads to stop
if(Globals.threadManager != null){ if(Globals.engineState != null && Globals.engineState.threadManager != null){
Globals.threadManager.close(); Globals.engineState.threadManager.close();
} }
//shut down audio engine //shut down audio engine
if(Globals.audioEngine != null && Globals.audioEngine.initialized()){ if(Globals.audioEngine != null && Globals.audioEngine.initialized()){

View File

@ -205,7 +205,7 @@ public class ClientLoading {
//start client networking //start client networking
if(Globals.RUN_CLIENT){ if(Globals.RUN_CLIENT){
Globals.clientState.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort()); Globals.clientState.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort());
Globals.threadManager.start(ThreadLabel.NETWORKING_CLIENT, new Thread(Globals.clientState.clientConnection)); Globals.engineState.threadManager.start(ThreadLabel.NETWORKING_CLIENT, new Thread(Globals.clientState.clientConnection));
} }
} }
@ -320,7 +320,7 @@ public class ClientLoading {
static void initDrawCellManager(boolean blockForInit){ static void initDrawCellManager(boolean blockForInit){
int iterations = 0; int iterations = 0;
WindowUtils.updateLoadingWindow("WAITING ON WORLD DATA"); WindowUtils.updateLoadingWindow("WAITING ON WORLD DATA");
while(blockForInit && (Globals.clientState.clientWorldData == null || InitialAssetLoading.atlasQueuedTexture == null || !InitialAssetLoading.atlasQueuedTexture.hasLoaded()) && Globals.threadManager.shouldKeepRunning()){ while(blockForInit && (Globals.clientState.clientWorldData == null || InitialAssetLoading.atlasQueuedTexture == null || !InitialAssetLoading.atlasQueuedTexture.hasLoaded()) && Globals.engineState.threadManager.shouldKeepRunning()){
try { try {
TimeUnit.MILLISECONDS.sleep(10); TimeUnit.MILLISECONDS.sleep(10);
iterations++; iterations++;
@ -344,7 +344,7 @@ public class ClientLoading {
while( while(
blockForInit && blockForInit &&
!Globals.clientState.clientDrawCellManager.isInitialized() && !Globals.clientState.clientDrawCellManager.isInitialized() &&
Globals.threadManager.shouldKeepRunning() Globals.engineState.threadManager.shouldKeepRunning()
){ ){
i++; i++;
if(i % DRAW_CELL_UPDATE_RATE == 0){ if(i % DRAW_CELL_UPDATE_RATE == 0){
@ -366,7 +366,7 @@ public class ClientLoading {
//wait for world data //wait for world data
WindowUtils.updateLoadingWindow("WAITING ON WORLD DATA"); WindowUtils.updateLoadingWindow("WAITING ON WORLD DATA");
while(blockForInit && Globals.clientState.clientWorldData == null && Globals.threadManager.shouldKeepRunning()){ while(blockForInit && Globals.clientState.clientWorldData == null && Globals.engineState.threadManager.shouldKeepRunning()){
try { try {
TimeUnit.MILLISECONDS.sleep(10); TimeUnit.MILLISECONDS.sleep(10);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
@ -380,7 +380,7 @@ public class ClientLoading {
//wait for all the terrain data to arrive //wait for all the terrain data to arrive
WindowUtils.updateLoadingWindow("REQUESTING FLUID CHUNKS FROM SERVER (" + Globals.fluidCellManager.getUnrequestedSize() + ")"); WindowUtils.updateLoadingWindow("REQUESTING FLUID CHUNKS FROM SERVER (" + Globals.fluidCellManager.getUnrequestedSize() + ")");
while(blockForInit && Globals.fluidCellManager.containsUnrequestedCell() && Globals.threadManager.shouldKeepRunning() && Globals.RUN_FLUIDS){ while(blockForInit && Globals.fluidCellManager.containsUnrequestedCell() && Globals.engineState.threadManager.shouldKeepRunning() && Globals.RUN_FLUIDS){
try { try {
TimeUnit.MILLISECONDS.sleep(10); TimeUnit.MILLISECONDS.sleep(10);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
@ -406,7 +406,7 @@ public class ClientLoading {
static void initBlockCellManager(boolean blockForInit){ static void initBlockCellManager(boolean blockForInit){
int iterations = 0; int iterations = 0;
WindowUtils.updateLoadingWindow("WAITING ON WORLD DATA"); WindowUtils.updateLoadingWindow("WAITING ON WORLD DATA");
while(blockForInit && (Globals.clientState.clientWorldData == null || InitialAssetLoading.atlasQueuedTexture == null || !InitialAssetLoading.atlasQueuedTexture.hasLoaded()) && Globals.threadManager.shouldKeepRunning()){ while(blockForInit && (Globals.clientState.clientWorldData == null || InitialAssetLoading.atlasQueuedTexture == null || !InitialAssetLoading.atlasQueuedTexture.hasLoaded()) && Globals.engineState.threadManager.shouldKeepRunning()){
try { try {
TimeUnit.MILLISECONDS.sleep(10); TimeUnit.MILLISECONDS.sleep(10);
iterations++; iterations++;
@ -428,7 +428,7 @@ public class ClientLoading {
while( while(
blockForInit && blockForInit &&
!Globals.clientState.clientBlockCellManager.isInitialized() && !Globals.clientState.clientBlockCellManager.isInitialized() &&
Globals.threadManager.shouldKeepRunning() Globals.engineState.threadManager.shouldKeepRunning()
){ ){
i++; i++;
if(i % DRAW_CELL_UPDATE_RATE == 0){ if(i % DRAW_CELL_UPDATE_RATE == 0){

View File

@ -52,7 +52,7 @@ public class LoadingUtils {
if(Globals.RUN_SERVER){ if(Globals.RUN_SERVER){
Globals.serverState.server = new Server(NetUtils.getPort()); Globals.serverState.server = new Server(NetUtils.getPort());
Thread serverThread = new Thread(Globals.serverState.server); Thread serverThread = new Thread(Globals.serverState.server);
Globals.threadManager.start(ThreadLabel.NETWORKING_SERVER, serverThread); Globals.engineState.threadManager.start(ThreadLabel.NETWORKING_SERVER, serverThread);
} }
} }
@ -72,7 +72,7 @@ public class LoadingUtils {
//start client networking //start client networking
if(Globals.RUN_CLIENT){ if(Globals.RUN_CLIENT){
Globals.clientState.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort()); Globals.clientState.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort());
Globals.threadManager.start(ThreadLabel.NETWORKING_CLIENT, new Thread(Globals.clientState.clientConnection)); Globals.engineState.threadManager.start(ThreadLabel.NETWORKING_CLIENT, new Thread(Globals.clientState.clientConnection));
} }
} }
@ -101,7 +101,7 @@ public class LoadingUtils {
rVal = Globals.serverState.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.engineState.threadManager.start(ThreadLabel.NETWORKING_CLIENT, new Thread(Globals.clientState.clientConnection));
} catch (IOException e) { } catch (IOException e) {
LoggerInterface.loggerNetworking.ERROR(e); LoggerInterface.loggerNetworking.ERROR(e);
} }

View File

@ -35,10 +35,10 @@ public class MainMenuLoading {
MainMenuLoading.resetClientState(); MainMenuLoading.resetClientState();
MainMenuLoading.resetServerState(); MainMenuLoading.resetServerState();
Globals.unloadScene(); Globals.unloadScene();
Globals.threadManager.interruptLabel(ThreadLabel.NETWORKING_CLIENT); Globals.engineState.threadManager.interruptLabel(ThreadLabel.NETWORKING_CLIENT);
Globals.threadManager.interruptLabel(ThreadLabel.NETWORKING_SERVER); Globals.engineState.threadManager.interruptLabel(ThreadLabel.NETWORKING_SERVER);
Globals.threadManager.awaitThreadClose(ThreadLabel.NETWORKING_CLIENT); Globals.engineState.threadManager.awaitThreadClose(ThreadLabel.NETWORKING_CLIENT);
Globals.threadManager.awaitThreadClose(ThreadLabel.NETWORKING_SERVER); Globals.engineState.threadManager.awaitThreadClose(ThreadLabel.NETWORKING_SERVER);
// //
//reveal in game main menu //reveal in game main menu

View File

@ -178,7 +178,7 @@ public class ClientNetworking implements Runnable {
//start parsing messages //start parsing messages
initialized = true; initialized = true;
while(Globals.threadManager.shouldKeepRunning() && !this.shouldDisconnect){ while(Globals.engineState.threadManager.shouldKeepRunning() && !this.shouldDisconnect){
// //
//attempt poll incoming messages //attempt poll incoming messages

View File

@ -31,7 +31,7 @@ public class CharacterProtocol implements ClientProtocolTemplate<CharacterMessag
Globals.clientState.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestSpawnCharacterMessage(electrosphere.net.server.protocol.CharacterProtocol.SPAWN_EXISTING_TEMPLATE + "")); Globals.clientState.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestSpawnCharacterMessage(electrosphere.net.server.protocol.CharacterProtocol.SPAWN_EXISTING_TEMPLATE + ""));
Globals.clientState.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage()); Globals.clientState.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage());
LoadingThread clientThread = new LoadingThread(LoadingThreadType.CLIENT_WORLD); LoadingThread clientThread = new LoadingThread(LoadingThreadType.CLIENT_WORLD);
Globals.threadManager.start(clientThread); Globals.engineState.threadManager.start(clientThread);
} break; } break;
case RESPONSECHARACTERLIST: { case RESPONSECHARACTERLIST: {
Globals.clientState.clientCharacterManager.setCharacterList(new Gson().fromJson(message.getdata(), ClientCharacterListDTO.class)); Globals.clientState.clientCharacterManager.setCharacterList(new Gson().fromJson(message.getdata(), ClientCharacterListDTO.class));

View File

@ -95,7 +95,7 @@ public class Server implements Runnable {
} catch (IOException ex) { } catch (IOException ex) {
LoggerInterface.loggerNetworking.ERROR("Failed to start server socket!",ex); LoggerInterface.loggerNetworking.ERROR("Failed to start server socket!",ex);
} }
while(Globals.threadManager.shouldKeepRunning() && !serverSocket.isClosed()){ while(Globals.engineState.threadManager.shouldKeepRunning() && !serverSocket.isClosed()){
Socket newSocket; Socket newSocket;
try { try {
newSocket = serverSocket.accept(); newSocket = serverSocket.accept();
@ -104,7 +104,7 @@ public class Server implements Runnable {
// clientMap.put(newSocket.getInetAddress().getHostAddress(), newClient); // clientMap.put(newSocket.getInetAddress().getHostAddress(), newClient);
socketConnectionMap.put(newSocket, newClient); socketConnectionMap.put(newSocket, newClient);
activeConnections.add(newClient); activeConnections.add(newClient);
Globals.threadManager.start(ThreadLabel.NETWORKING_SERVER, new Thread(newClient)); Globals.engineState.threadManager.start(ThreadLabel.NETWORKING_SERVER, new Thread(newClient));
connectListLock.release(); connectListLock.release();
} catch (SocketException ex){ } catch (SocketException ex){
LoggerInterface.loggerNetworking.DEBUG("Server Socket closed!",ex); LoggerInterface.loggerNetworking.DEBUG("Server Socket closed!",ex);
@ -172,7 +172,7 @@ public class Server implements Runnable {
connectListLock.acquireUninterruptibly(); connectListLock.acquireUninterruptibly();
ServerConnectionHandler newClient = new ServerConnectionHandler(serverInputStream,serverOutputStream); ServerConnectionHandler newClient = new ServerConnectionHandler(serverInputStream,serverOutputStream);
activeConnections.add(newClient); activeConnections.add(newClient);
Globals.threadManager.start(ThreadLabel.NETWORKING_SERVER, new Thread(newClient)); Globals.engineState.threadManager.start(ThreadLabel.NETWORKING_SERVER, new Thread(newClient));
connectListLock.release(); connectListLock.release();
return newClient; return newClient;
} }

View File

@ -230,7 +230,7 @@ public class ServerConnectionHandler implements Runnable {
initialized = true; initialized = true;
while(Globals.threadManager.shouldKeepRunning() && this.isConnected == true && Globals.serverState.server != null && Globals.serverState.server.isOpen()){ while(Globals.engineState.threadManager.shouldKeepRunning() && this.isConnected == true && Globals.serverState.server != null && Globals.serverState.server.isOpen()){
boolean receivedMessageThisLoop = false; boolean receivedMessageThisLoop = false;
// //

View File

@ -40,7 +40,7 @@ public class GriddedDataCellLoaderService {
* Constructor * Constructor
*/ */
public GriddedDataCellLoaderService(){ public GriddedDataCellLoaderService(){
this.ioThreadService = Globals.threadManager.requestFixedThreadPool(ThreadCounts.GRIDDED_DATACELL_LOADING_THREADS); this.ioThreadService = Globals.engineState.threadManager.requestFixedThreadPool(ThreadCounts.GRIDDED_DATACELL_LOADING_THREADS);
} }
/** /**

View File

@ -206,7 +206,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
} }
this.pathfinder = new VoxelPathfinder(); this.pathfinder = new VoxelPathfinder();
this.loaderService = new GriddedDataCellLoaderService(); this.loaderService = new GriddedDataCellLoaderService();
this.generationService = Globals.threadManager.requestFixedThreadPool(ThreadCounts.GRIDDED_DATACELL_PHYSICS_GEN_THREADS); this.generationService = Globals.engineState.threadManager.requestFixedThreadPool(ThreadCounts.GRIDDED_DATACELL_PHYSICS_GEN_THREADS);
} }
/** /**

View File

@ -107,7 +107,7 @@ public class ServerBlockChunkGenerationThread implements Runnable {
BlockChunkData chunk = null; BlockChunkData chunk = null;
int i = 0; int i = 0;
try { try {
while(chunk == null && i < MAX_TIME_TO_WAIT && Globals.threadManager.shouldKeepRunning()){ while(chunk == null && i < MAX_TIME_TO_WAIT && Globals.engineState.threadManager.shouldKeepRunning()){
if(chunkCache.containsChunk(worldX, worldY, worldZ, stride)){ if(chunkCache.containsChunk(worldX, worldY, worldZ, stride)){
chunk = chunkCache.get(worldX, worldY, worldZ, stride); chunk = chunkCache.get(worldX, worldY, worldZ, stride);
} else { } else {

View File

@ -45,7 +45,7 @@ public class ServerBlockManager {
* The threadpool for chunk generation * The threadpool for chunk generation
*/ */
@Exclude @Exclude
ExecutorService chunkExecutorService = Globals.threadManager.requestFixedThreadPool(ThreadCounts.SERVER_BLOCK_GENERATION_THREADS); ExecutorService chunkExecutorService = Globals.engineState.threadManager.requestFixedThreadPool(ThreadCounts.SERVER_BLOCK_GENERATION_THREADS);
/** /**
* Constructor * Constructor

View File

@ -97,7 +97,7 @@ public class ChunkGenerationThread implements Runnable {
try { try {
int i = 0; int i = 0;
ServerTerrainChunk chunk = null; ServerTerrainChunk chunk = null;
while(chunk == null && i < MAX_TIME_TO_WAIT && Globals.threadManager.shouldKeepRunning()){ while(chunk == null && i < MAX_TIME_TO_WAIT && Globals.engineState.threadManager.shouldKeepRunning()){
if(chunkCache.containsChunk(worldX, worldY, worldZ, stride)){ if(chunkCache.containsChunk(worldX, worldY, worldZ, stride)){
chunk = chunkCache.get(worldX, worldY, worldZ, stride); chunk = chunkCache.get(worldX, worldY, worldZ, stride);
} else { } else {

View File

@ -77,7 +77,7 @@ public class ServerTerrainManager {
* The threadpool for chunk generation * The threadpool for chunk generation
*/ */
@Exclude @Exclude
ExecutorService chunkExecutorService = Globals.threadManager.requestFixedThreadPool(ThreadCounts.SERVER_TERRAIN_GENERATION_THREADS); ExecutorService chunkExecutorService = Globals.engineState.threadManager.requestFixedThreadPool(ThreadCounts.SERVER_TERRAIN_GENERATION_THREADS);
/** /**
* Constructor * Constructor

View File

@ -6,6 +6,7 @@ import org.joml.Vector3f;
import org.joml.Vector3i; import org.joml.Vector3i;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import electrosphere.client.ClientState;
import electrosphere.client.scene.ClientWorldData; import electrosphere.client.scene.ClientWorldData;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.engine.Main; import electrosphere.engine.Main;
@ -35,6 +36,7 @@ public class ClientDrawCellManagerTests {
public void testJoinCase(){ public void testJoinCase(){
int worldDiscreteSize = 64; int worldDiscreteSize = 64;
Globals.clientState = new ClientState();
Globals.clientState.clientWorldData = new ClientWorldData(new Vector3f(0), new Vector3f(worldDiscreteSize * ServerTerrainChunk.CHUNK_DIMENSION), worldDiscreteSize); Globals.clientState.clientWorldData = new ClientWorldData(new Vector3f(0), new Vector3f(worldDiscreteSize * ServerTerrainChunk.CHUNK_DIMENSION), worldDiscreteSize);
ClientDrawCellManager manager = new ClientDrawCellManager(null, 64); ClientDrawCellManager manager = new ClientDrawCellManager(null, 64);
Vector3i playerPos = new Vector3i(0,0,0); Vector3i playerPos = new Vector3i(0,0,0);

View File

@ -6,7 +6,6 @@ import org.joml.Vector3d;
import electrosphere.test.annotations.UnitTest; import electrosphere.test.annotations.UnitTest;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.server.ServerState;
import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.Realm;
import electrosphere.server.service.CharacterService; import electrosphere.server.service.CharacterService;
@ -18,7 +17,7 @@ public class ServerEntityUtilsUnitTests {
@UnitTest @UnitTest
public void destroyEntity_ValidEntity_NoRealm(){ public void destroyEntity_ValidEntity_NoRealm(){
//setup //setup
Globals.serverState = new ServerState(); Globals.initGlobals();
Globals.serverState.characterService = (CharacterService)Globals.serviceManager.registerService(new CharacterService()); Globals.serverState.characterService = (CharacterService)Globals.serviceManager.registerService(new CharacterService());
Realm realm = Globals.serverState.realmManager.createViewportRealm(new Vector3d(0,0,0), new Vector3d(1,1,1)); Realm realm = Globals.serverState.realmManager.createViewportRealm(new Vector3d(0,0,0), new Vector3d(1,1,1));
Entity entity = EntityCreationUtils.createServerEntity(realm, new Vector3d()); Entity entity = EntityCreationUtils.createServerEntity(realm, new Vector3d());

View File

@ -16,12 +16,12 @@ public class StateCleanupCheckerExtension implements AfterEachCallback {
public void afterEach(ExtensionContext context) throws Exception { public void afterEach(ExtensionContext context) throws Exception {
Object[] objectsToCheck = new Object[]{ Object[] objectsToCheck = new Object[]{
Globals.signalSystem, Globals.signalSystem,
Globals.threadManager,
Globals.renderingEngine, Globals.renderingEngine,
Globals.audioEngine, Globals.audioEngine,
Globals.javaPID, Globals.javaPID,
LoggerInterface.loggerEngine, LoggerInterface.loggerEngine,
RenderingEngine.screenFramebuffer, RenderingEngine.screenFramebuffer,
Globals.engineState,
Globals.clientState, Globals.clientState,
Globals.serverState, Globals.serverState,
}; };

View File

@ -60,12 +60,12 @@ public class EngineInit {
// //
//load the scene //load the scene
LoadingThread loadingThread = new LoadingThread(LoadingThreadType.LEVEL,"testscene1"); LoadingThread loadingThread = new LoadingThread(LoadingThreadType.LEVEL,"testscene1");
Globals.threadManager.start(loadingThread); Globals.engineState.threadManager.start(loadingThread);
// //
//wait for client to be fully init'd //wait for client to be fully init'd
int frames = 0; int frames = 0;
while(Globals.threadManager.isLoading()){ while(Globals.engineState.threadManager.isLoading()){
TestEngineUtils.simulateFrames(1); TestEngineUtils.simulateFrames(1);
try { try {
TimeUnit.MILLISECONDS.sleep(1); TimeUnit.MILLISECONDS.sleep(1);
@ -77,7 +77,7 @@ public class EngineInit {
String errorMessage = "Failed to setup connected test scene!\n" + String errorMessage = "Failed to setup connected test scene!\n" +
"Still running threads are:\n" "Still running threads are:\n"
; ;
for(LoadingThread thread : Globals.threadManager.getLoadingThreads()){ for(LoadingThread thread : Globals.engineState.threadManager.getLoadingThreads()){
errorMessage = errorMessage + thread.getType() + "\n"; errorMessage = errorMessage + thread.getType() + "\n";
} }
Assertions.fail("Failed to startup"); Assertions.fail("Failed to startup");
@ -92,7 +92,7 @@ public class EngineInit {
// //
//load the scene //load the scene
LoadingThread loadingThread = new LoadingThread(LoadingThreadType.LOAD_VIEWPORT); LoadingThread loadingThread = new LoadingThread(LoadingThreadType.LOAD_VIEWPORT);
Globals.threadManager.start(loadingThread); Globals.engineState.threadManager.start(loadingThread);
TestEngineUtils.flush(); TestEngineUtils.flush();
} }

View File

@ -122,7 +122,7 @@ public class TestEngineUtils {
//wait for client to be fully init'd //wait for client to be fully init'd
int frames = 0; int frames = 0;
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
while(Globals.threadManager.isLoading()){ while(Globals.engineState.threadManager.isLoading()){
TestEngineUtils.simulateFrames(1); TestEngineUtils.simulateFrames(1);
try { try {
TimeUnit.MILLISECONDS.sleep(1); TimeUnit.MILLISECONDS.sleep(1);
@ -137,7 +137,7 @@ public class TestEngineUtils {
String errorMessage = "Failed to setup connected test scene!\n" + String errorMessage = "Failed to setup connected test scene!\n" +
"Still running threads are:\n" "Still running threads are:\n"
; ;
for(LoadingThread thread : Globals.threadManager.getLoadingThreads()){ for(LoadingThread thread : Globals.engineState.threadManager.getLoadingThreads()){
errorMessage = errorMessage + thread.getType() + "\n"; errorMessage = errorMessage + thread.getType() + "\n";
} }
errorMessage = errorMessage + "frames: " + frames + "\n"; errorMessage = errorMessage + "frames: " + frames + "\n";

View File

@ -57,7 +57,7 @@ public class TestViewportUtils {
String errorMessage = "Failed to spawn player character!\n" + String errorMessage = "Failed to spawn player character!\n" +
"Still running threads are:\n" "Still running threads are:\n"
; ;
for(LoadingThread thread : Globals.threadManager.getLoadingThreads()){ for(LoadingThread thread : Globals.engineState.threadManager.getLoadingThreads()){
errorMessage = errorMessage + thread.getType() + "\n"; errorMessage = errorMessage + thread.getType() + "\n";
} }
throw new IllegalStateException(errorMessage); throw new IllegalStateException(errorMessage);