Renderer/src/main/java/electrosphere/engine/loadingthreads/LevelLoading.java
austin 45ce4ca9a9
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
rudimentary scene saving
2024-03-24 21:51:11 -04:00

85 lines
3.1 KiB
Java

package electrosphere.engine.loadingthreads;
import java.util.concurrent.TimeUnit;
import electrosphere.auth.AuthenticationManager;
import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface;
import electrosphere.menu.MenuGenerators;
import electrosphere.menu.WindowStrings;
import electrosphere.menu.WindowUtils;
import electrosphere.net.parser.net.message.TerrainMessage;
import electrosphere.net.server.ServerConnectionHandler;
import electrosphere.renderer.ui.Window;
import electrosphere.server.content.ServerContentManager;
import electrosphere.server.saves.SaveUtils;
/**
* Loads a given level
*/
public class LevelLoading {
/**
* Loads the level editor
*/
protected static void loadLevel(){
Window loadingWindow = (Window)Globals.elementManager.getWindow(WindowStrings.WINDOW_LOADING);
//show loading
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_MAIN), false);
WindowUtils.replaceMainMenuContents(MenuGenerators.createEmptyMainMenu());
loadingWindow.setVisible(true);
//load just-created save
SaveUtils.loadSave(Globals.currentSaveName);
//init server content manager
Globals.serverContentManager = ServerContentManager.createServerContentManager(false);
//creates a gridded realm
LoadingUtils.initGriddedRealm();
LoggerInterface.loggerEngine.INFO("run server: " + Globals.RUN_SERVER + " run client: " + Globals.RUN_CLIENT);
//init authentication
LoadingUtils.initAuthenticationManager();
//initialize the local connection
Globals.clientUsername = "leveleditor";
Globals.clientPassword = AuthenticationManager.getHashedString("leveleditor");
ServerConnectionHandler serverPlayerConnection = LoadingUtils.initLocalConnection();
//wait for player object creation
while(Globals.playerManager.getPlayers().size() < 1){
try {
TimeUnit.MILLISECONDS.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//initialize the "real" objects simulation
LoadingUtils.initMicroSimulation();
//init game specific stuff (ie different skybox colors)
LoadingUtils.initGameGraphicalEntities();
//set simulations to ready if they exist
LoadingUtils.setSimulationsToReady();
//log
LoggerInterface.loggerEngine.INFO("[Server]Finished loading level editor");
//the less juicy client setup part
while(Globals.gameConfigCurrent.getCreatureTypeLoader().getPlayableRaces().size() == 0){
try {
TimeUnit.MILLISECONDS.sleep(5);
} catch (InterruptedException ex) {}
}
//spawn player character
LoadingUtils.spawnLocalPlayerTestEntity(serverPlayerConnection);
//request terrain data
Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage());
//Run client startup process
ClientLoading.loadClientWorld();
}
}