groundwork for headless server

This commit is contained in:
austin 2022-04-28 22:04:32 -04:00
parent c94ad0911c
commit 8ec6388477
2 changed files with 81 additions and 41 deletions

View File

@ -229,12 +229,16 @@ public class LoadingThread extends Thread {
case LOAD_ARENA:
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN), false);
WindowUtils.replaceMainMenuContents(MenuGenerators.createEmptyMainMenu());
loadingWindow.setVisible(true);
if(Globals.RUN_CLIENT){
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN), false);
WindowUtils.replaceMainMenuContents(MenuGenerators.createEmptyMainMenu());
loadingWindow.setVisible(true);
}
//disable menu input
Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.NO_INPUT);
if(Globals.RUN_CLIENT){
Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.NO_INPUT);
}
//init server arena terrain manager separately
initServerArenaTerrainManager();
@ -270,10 +274,14 @@ public class LoadingThread extends Thread {
}
//init client terrain manager
initClientTerrainManager();
if(Globals.RUN_CLIENT){
initClientTerrainManager();
}
//initialize the cell manager (client)
initDrawCellManager();
if(Globals.RUN_CLIENT){
initDrawCellManager();
}
//initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities();
@ -292,22 +300,26 @@ public class LoadingThread extends Thread {
setSimulationsToReady();
//hide cursor
Globals.controlHandler.hideMouse();
loadingWindow.setVisible(false);
Globals.controlHandler.setShouldRecapture(true);
Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = true;
Globals.RENDER_FLAG_RENDER_UI = true;
Globals.RENDER_FLAG_RENDER_BLACK_BACKGROUND = false;
Globals.RENDER_FLAG_RENDER_WHITE_BACKGROUND = false;
if(Globals.RUN_CLIENT){
Globals.controlHandler.hideMouse();
loadingWindow.setVisible(false);
Globals.controlHandler.setShouldRecapture(true);
Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = true;
Globals.RENDER_FLAG_RENDER_UI = true;
Globals.RENDER_FLAG_RENDER_BLACK_BACKGROUND = false;
Globals.RENDER_FLAG_RENDER_WHITE_BACKGROUND = false;
}
LoggerInterface.loggerEngine.INFO("Finished loading");
Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.MAIN_GAME);
if(Globals.RUN_CLIENT){
Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.MAIN_GAME);
}
break;

View File

@ -123,9 +123,13 @@ public class Main {
//load user settings
UserSettings.loadUserSettings();
// Globals.RUN_CLIENT = false;
//controls
initControlHandler();
if(Globals.RUN_CLIENT){
initControlHandler();
}
//init global variables
Globals.initGlobals();
@ -174,8 +178,10 @@ public class Main {
// TerrainViewer.runViewer();
//create the drawing context
Globals.renderingEngine = new RenderingEngine();
Globals.renderingEngine.createOpenglContext();
if(Globals.RUN_CLIENT){
Globals.renderingEngine = new RenderingEngine();
Globals.renderingEngine.createOpenglContext();
}
//uncomment to test loading a model into engine
// if(1==1){
@ -199,22 +205,32 @@ public class Main {
// }
//create the audio context
Globals.audioEngine = new AudioEngine();
Globals.audioEngine.init();
Globals.audioEngine.setGain(0.1f);
if(Globals.RUN_CLIENT){
Globals.audioEngine = new AudioEngine();
Globals.audioEngine.init();
Globals.audioEngine.setGain(0.1f);
}
//init default resources
Globals.initDefaultGraphicalResources();
Globals.initDefaultAudioResources();
if(Globals.RUN_CLIENT){
Globals.initDefaultGraphicalResources();
Globals.initDefaultAudioResources();
}
//fire off a loading thread for the title menus/screen
LoggerInterface.loggerStartup.INFO("Fire off loading thread");
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_TITLE_MENU);
if(Globals.RUN_CLIENT){
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_TITLE_MENU);
} else {
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA);
}
Globals.loadingThread.start();
//recapture the screen for rendering
LoggerInterface.loggerStartup.INFO("Recapture screen");
Globals.controlHandler.setShouldRecapture(true);
if(Globals.RUN_CLIENT){
LoggerInterface.loggerStartup.INFO("Recapture screen");
Globals.controlHandler.setShouldRecapture(true);
}
// RenderUtils.recaptureScreen();
///
@ -237,7 +253,9 @@ public class Main {
///
/// A S S E T M A N A G E R S T U F F
///
Globals.assetManager.loadAssetsInQueue();
if(Globals.RUN_CLIENT){
Globals.assetManager.loadAssetsInQueue();
}
@ -256,19 +274,25 @@ public class Main {
/// I N P U T C O N T R O L S
///
//Poll controls
Globals.controlHandler.pollControls();
Globals.controlHandler.recaptureIfNecessary();
if(Globals.RUN_CLIENT){
Globals.controlHandler.pollControls();
Globals.controlHandler.recaptureIfNecessary();
}
///
/// C L I E N T S I M U L A T I O N S T U F F
///
ClientFunctions.runBeforeSimulationFunctions();
if(Globals.RUN_CLIENT){
ClientFunctions.runBeforeSimulationFunctions();
}
if(Globals.microSimulation != null && Globals.microSimulation.isReady()){
Globals.microSimulation.simulate();
}
ClientFunctions.runClientFunctions();
if(Globals.RUN_CLIENT){
ClientFunctions.runClientFunctions();
}
///
/// M A C R O S I M U L A T I O N S T U F F
@ -278,11 +302,11 @@ public class Main {
}
if(Globals.RUN_CLIENT){
Globals.renderingEngine.drawScreen();
}
Globals.renderingEngine.drawScreen();
if(glfwWindowShouldClose(Globals.window) || Globals.ENGINE_SHUTDOWN_FLAG){
if(Globals.ENGINE_SHUTDOWN_FLAG || (Globals.RUN_CLIENT && glfwWindowShouldClose(Globals.window))){
running = false;
}
@ -299,7 +323,9 @@ public class Main {
// S H U T D O W N
//
//Terminate the program.
glfwTerminate();
if(Globals.RUN_CLIENT){
glfwTerminate();
}
//used to signal threads to stop
running = false;
if(Globals.server != null){
@ -307,7 +333,9 @@ public class Main {
Globals.serverThread.interrupt();
}
//shut down audio engine
Globals.audioEngine.shutdown();
if(Globals.RUN_CLIENT){
Globals.audioEngine.shutdown();
}
}