package electrosphere.engine.loadingthreads; import java.util.concurrent.TimeUnit; import electrosphere.auth.AuthenticationManager; import electrosphere.engine.Globals; import electrosphere.game.server.world.ServerWorldData; 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.fluid.generation.ArenaFluidGenerator; import electrosphere.server.fluid.manager.ServerFluidManager; import electrosphere.server.saves.SaveUtils; import electrosphere.server.terrain.generation.ArenaChunkGenerator; import electrosphere.server.terrain.generation.OverworldChunkGenerator; import electrosphere.server.terrain.manager.ServerTerrainManager; import electrosphere.util.FileUtils; /** * Loads the level editor */ public class LevelEditorLoading { /** * Loads the level editor */ protected static void loadLevelEditor(){ 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); Globals.serverTerrainManager = new ServerTerrainManager(3,1,0.0f,0, new ArenaChunkGenerator()); if(!SaveUtils.getSaves().contains(Globals.currentSaveName)){ //init save structure SaveUtils.createOrOverwriteSave(Globals.currentSaveName); //create world.json Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager); FileUtils.serializeObjectToSavePath(Globals.currentSaveName, "./world.json", Globals.serverWorldData); //create mock fluid sim manager Globals.serverFluidManager = new ServerFluidManager(Globals.serverTerrainManager, 3, 1, 0.0f, 0, new ArenaFluidGenerator()); //save terrain manager Globals.serverTerrainManager.save(Globals.currentSaveName); } //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(); } }