111 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			111 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
package electrosphere.engine.loadingthreads;
 | 
						|
 | 
						|
import java.util.concurrent.TimeUnit;
 | 
						|
 | 
						|
import electrosphere.auth.AuthenticationManager;
 | 
						|
import electrosphere.engine.Globals;
 | 
						|
import electrosphere.entity.scene.SceneFile;
 | 
						|
import electrosphere.logger.LoggerInterface;
 | 
						|
import electrosphere.menu.MenuGenerators;
 | 
						|
import electrosphere.menu.WindowStrings;
 | 
						|
import electrosphere.menu.WindowUtils;
 | 
						|
import electrosphere.menu.mainmenu.MenuGeneratorsLevelEditor.LevelDescription;
 | 
						|
import electrosphere.net.parser.net.message.TerrainMessage;
 | 
						|
import electrosphere.net.server.ServerConnectionHandler;
 | 
						|
import electrosphere.renderer.ui.elements.Window;
 | 
						|
import electrosphere.server.saves.SaveUtils;
 | 
						|
 | 
						|
/**
 | 
						|
 * Loads the level editor
 | 
						|
 */
 | 
						|
public class LevelEditorLoading {
 | 
						|
 | 
						|
    /**
 | 
						|
     * Loads the level editor
 | 
						|
     */
 | 
						|
    protected static void loadLevelEditor(Object[] params){
 | 
						|
 | 
						|
        //
 | 
						|
        // Get params to create the level with
 | 
						|
        //
 | 
						|
        if(params.length < 1){
 | 
						|
            throw new IllegalStateException("Trying to load level editor with insufficient params");
 | 
						|
        }
 | 
						|
 | 
						|
        String saveName = null;
 | 
						|
        SceneFile sceneFile = null;
 | 
						|
        //figure out scene stuff
 | 
						|
        if(params[0] instanceof LevelDescription){
 | 
						|
            //fires when creating a level for the first time
 | 
						|
            LevelDescription description = (LevelDescription)params[0];
 | 
						|
            saveName = description.getName();
 | 
						|
            sceneFile= description.getSceneFile();
 | 
						|
        } else {
 | 
						|
            //fires when subsequently editing
 | 
						|
            saveName = (String)params[0];
 | 
						|
        }
 | 
						|
 | 
						|
        //
 | 
						|
        //Set params we would expect to run with this thread
 | 
						|
        //
 | 
						|
        Globals.RUN_CLIENT = true;
 | 
						|
        Globals.RUN_SERVER = true;
 | 
						|
        Globals.aiManager.setActive(false);
 | 
						|
 | 
						|
        
 | 
						|
        Window loadingWindow = (Window)Globals.elementService.getWindow(WindowStrings.WINDOW_LOADING);
 | 
						|
        //show loading
 | 
						|
        WindowUtils.recursiveSetVisible(Globals.elementService.getWindow(WindowStrings.WINDOW_MENU_MAIN), false);
 | 
						|
        WindowUtils.replaceMainMenuContents(MenuGenerators.createEmptyMainMenu());
 | 
						|
        loadingWindow.setVisible(true);
 | 
						|
 | 
						|
        if(!SaveUtils.getSaves().contains(saveName)){
 | 
						|
            //init save structure
 | 
						|
            SaveUtils.createOrOverwriteSave(saveName,sceneFile);
 | 
						|
        }
 | 
						|
        //load just-created save
 | 
						|
        SaveUtils.loadSave(saveName, true);
 | 
						|
 | 
						|
        LoggerInterface.loggerEngine.INFO("run server: " + Globals.RUN_SERVER + " run client: " + Globals.RUN_CLIENT);
 | 
						|
        //init authentication
 | 
						|
        LoadingUtils.initAuthenticationManager(false);
 | 
						|
        //initialize the local connection
 | 
						|
        Globals.clientUsername = "leveleditor";
 | 
						|
        Globals.clientPassword = AuthenticationManager.getHashedString("leveleditor");
 | 
						|
        ServerConnectionHandler serverPlayerConnection = LoadingUtils.initLocalConnection(true);
 | 
						|
        //wait for player object creation
 | 
						|
        while(Globals.playerManager.getPlayers().size() < 1 || !Globals.clientConnection.isInitialized()){
 | 
						|
            try {
 | 
						|
                TimeUnit.MILLISECONDS.sleep(1);
 | 
						|
            } 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(1);
 | 
						|
            } catch (InterruptedException ex) {}
 | 
						|
        }
 | 
						|
        
 | 
						|
        //spawn player character
 | 
						|
        LoadingUtils.spawnLocalPlayerTestEntity(serverPlayerConnection);
 | 
						|
 | 
						|
        //request terrain data
 | 
						|
        Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage());
 | 
						|
 | 
						|
        //Run client startup process
 | 
						|
        ClientLoading.loadClientWorld(params);
 | 
						|
    }
 | 
						|
    
 | 
						|
}
 |