Search in sources :

Example 1 with StateMainMenu

use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.

the class JoinServer method step.

@Override
public boolean step() {
    if (applyModuleThread != null) {
        if (!applyModuleThread.isAlive()) {
            if (oldEnvironment != null) {
                oldEnvironment.close();
            }
            return true;
        }
        return false;
    } else if (joinStatus.getStatus() == JoinStatus.Status.COMPLETE) {
        Server server = networkSystem.getServer();
        ServerInfoMessage serverInfo = networkSystem.getServer().getInfo();
        // If no GameName, use Server IP Address
        if (serverInfo.getGameName().length() > 0) {
            gameManifest.setTitle(serverInfo.getGameName());
        } else {
            gameManifest.setTitle(server.getRemoteAddress());
        }
        for (WorldInfo worldInfo : serverInfo.getWorldInfoList()) {
            gameManifest.addWorld(worldInfo);
        }
        Map<String, Short> blockMap = Maps.newHashMap();
        for (Entry<Integer, String> entry : serverInfo.getBlockIds().entrySet()) {
            String name = entry.getValue();
            short id = entry.getKey().shortValue();
            Short oldId = blockMap.put(name, id);
            if (oldId != null && oldId != id) {
                logger.warn("Overwriting Id {} for {} with Id {}", oldId, name, id);
            }
        }
        gameManifest.setRegisteredBlockFamilies(serverInfo.getRegisterBlockFamilyList());
        gameManifest.setBlockIdMap(blockMap);
        gameManifest.setTime(networkSystem.getServer().getInfo().getTime());
        ModuleManager moduleManager = context.get(ModuleManager.class);
        Set<Module> moduleSet = Sets.newLinkedHashSet();
        for (NameVersion moduleInfo : networkSystem.getServer().getInfo().getModuleList()) {
            Module module = moduleManager.getRegistry().getModule(moduleInfo.getName(), moduleInfo.getVersion());
            if (module == null) {
                StateMainMenu mainMenu = new StateMainMenu("Missing required module: " + moduleInfo);
                context.get(GameEngine.class).changeState(mainMenu);
                return false;
            } else {
                logger.info("Activating module: {}:{}", moduleInfo.getName(), moduleInfo.getVersion());
                gameManifest.addModule(module.getId(), module.getVersion());
                moduleSet.add(module);
            }
        }
        oldEnvironment = moduleManager.getEnvironment();
        moduleManager.loadEnvironment(moduleSet, true);
        context.get(Game.class).load(gameManifest);
        EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
        applyModuleThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
        applyModuleThread.start();
        return false;
    } else if (joinStatus.getStatus() == JoinStatus.Status.FAILED) {
        StateMainMenu mainMenu = new StateMainMenu("Failed to connect to server: " + joinStatus.getErrorMessage());
        context.get(GameEngine.class).changeState(mainMenu);
        networkSystem.shutdown();
    }
    return false;
}
Also used : Set(java.util.Set) Server(org.terasology.engine.network.Server) NameVersion(org.terasology.gestalt.naming.NameVersion) GameEngine(org.terasology.engine.core.GameEngine) ModuleManager(org.terasology.engine.core.module.ModuleManager) Entry(java.util.Map.Entry) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ServerInfoMessage(org.terasology.engine.network.ServerInfoMessage) Module(org.terasology.gestalt.module.Module) Map(java.util.Map) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 2 with StateMainMenu

use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.

the class RegisterMods method step.

@Override
public boolean step() {
    if (applyModulesThread != null) {
        if (!applyModulesThread.isAlive()) {
            if (oldEnvironment != null) {
                oldEnvironment.close();
            }
            return true;
        }
        return false;
    } else {
        ModuleManager moduleManager = context.get(ModuleManager.class);
        List<Name> moduleIds = gameManifest.getModules().stream().map(NameVersion::getName).collect(Collectors.toCollection(ArrayList::new));
        DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
        ResolutionResult result = resolver.resolve(moduleIds);
        if (result.isSuccess()) {
            oldEnvironment = moduleManager.getEnvironment();
            ModuleEnvironment env = moduleManager.loadEnvironment(result.getModules(), true);
            for (Module moduleInfo : env.getModulesOrderedByDependencies()) {
                logger.info("Activating module: {}:{}", moduleInfo.getId(), moduleInfo.getVersion());
            }
            EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
            applyModulesThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
            applyModulesThread.start();
            return false;
        } else {
            logger.warn("Missing at least one required module (or dependency) from the following list: {}", moduleIds);
            context.get(GameEngine.class).changeState(new StateMainMenu("Missing required module or dependency"));
            return true;
        }
    }
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) GameEngine(org.terasology.engine.core.GameEngine) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 3 with StateMainMenu

use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.

the class WorldRendererImpl method initRenderingModules.

private void initRenderingModules() {
    renderingModuleRegistry = context.get(RenderingModuleRegistry.class);
    // registry not populated by new ModuleRendering instances in UI, populate now
    if (renderingModuleRegistry.getOrderedRenderingModules().isEmpty()) {
        List<ModuleRendering> renderingModules = renderingModuleRegistry.updateRenderingModulesOrder(context.get(ModuleManager.class).getEnvironment(), context);
        if (renderingModules.isEmpty()) {
            GameEngine gameEngine = context.get(GameEngine.class);
            gameEngine.changeState(new StateMainMenu("No rendering module loaded, unable to render. Try enabling " + "CoreRendering."));
        }
    } else {
        // registry populated by new ModuleRendering instances in UI
        // Switch module's context from gamecreation subcontext to gamerunning context
        renderingModuleRegistry.updateModulesContext(context);
    }
    for (ModuleRendering moduleRenderingInstance : renderingModuleRegistry.getOrderedRenderingModules()) {
        if (moduleRenderingInstance.isEnabled()) {
            logger.info(String.format("\nInitialising rendering class %s from %s module.\n", moduleRenderingInstance.getClass().getSimpleName(), moduleRenderingInstance.getProvidingModule()));
            moduleRenderingInstance.initialise();
        }
    }
    requestTaskListRefresh();
}
Also used : ModuleRendering(org.terasology.engine.rendering.dag.ModuleRendering) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) GameEngine(org.terasology.engine.core.GameEngine) RenderingModuleRegistry(org.terasology.engine.core.module.rendering.RenderingModuleRegistry)

Example 4 with StateMainMenu

use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.

the class Terasology method call.

@Override
public Integer call() throws IOException {
    handleLaunchArguments();
    setupLogging();
    SplashScreen splashScreen;
    if (splashEnabled) {
        CountDownLatch splashInitLatch = new CountDownLatch(1);
        GLFWSplashScreen glfwSplash = new GLFWSplashScreen(splashInitLatch);
        Thread thread = new Thread(glfwSplash, "splashscreen-loop");
        thread.setDaemon(true);
        thread.start();
        try {
            // wait splash initialize... we will lose some post messages otherwise.
            // noinspection ResultOfMethodCallIgnored
            splashInitLatch.await(1, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
        // ignore
        }
        splashScreen = glfwSplash;
    } else {
        splashScreen = SplashScreenBuilder.createStub();
    }
    splashScreen.post("Java Runtime " + System.getProperty("java.version") + " loaded");
    try {
        TerasologyEngineBuilder builder = new TerasologyEngineBuilder();
        populateSubsystems(builder);
        TerasologyEngine engine = builder.build();
        engine.subscribe(newStatus -> {
            if (newStatus == StandardGameStatus.RUNNING) {
                splashScreen.close();
            } else {
                splashScreen.post(newStatus.getDescription());
            }
        });
        if (isHeadless) {
            engine.subscribeToStateChange(new HeadlessStateChangeListener(engine));
            engine.run(new StateHeadlessSetup());
        } else if (loadLastGame) {
            // initialize the managers first
            engine.initialize();
            GameScheduler.scheduleParallel("loadGame", () -> {
                GameManifest gameManifest = getLatestGameManifest();
                if (gameManifest != null) {
                    engine.changeState(new StateLoading(gameManifest, NetworkMode.NONE));
                }
            });
        } else {
            if (createLastGame) {
                engine.initialize();
                GameScheduler.scheduleParallel("createLastGame", () -> {
                    GameManifest gameManifest = getLatestGameManifest();
                    if (gameManifest != null) {
                        String title = gameManifest.getTitle();
                        if (!title.startsWith("New Created")) {
                            // if first time run
                            gameManifest.setTitle("New Created " + title + " 1");
                        } else {
                            // if not first time run
                            gameManifest.setTitle(getNewTitle(title));
                        }
                        engine.changeState(new StateLoading(gameManifest, NetworkMode.NONE));
                    }
                });
            }
            engine.run(new StateMainMenu());
        }
    } catch (Throwable e) {
        // also catch Errors such as UnsatisfiedLink, NoSuchMethodError, etc.
        splashScreen.close();
        reportException(e);
    }
    return 0;
}
Also used : TerasologyEngineBuilder(org.terasology.engine.core.TerasologyEngineBuilder) StateLoading(org.terasology.engine.core.modes.StateLoading) CountDownLatch(java.util.concurrent.CountDownLatch) StateHeadlessSetup(org.terasology.engine.core.subsystem.headless.mode.StateHeadlessSetup) TerasologyEngine(org.terasology.engine.core.TerasologyEngine) GameManifest(org.terasology.engine.game.GameManifest) HeadlessStateChangeListener(org.terasology.engine.core.subsystem.headless.mode.HeadlessStateChangeListener) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) SplashScreen(org.terasology.splash.SplashScreen)

Example 5 with StateMainMenu

use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.

the class DeathScreen method initialise.

@Override
public void initialise() {
    deathDetails = find("deathDetails", UILabel.class);
    WidgetUtil.trySubscribe(this, "respawn", widget -> {
        localPlayer.getClientEntity().send(new RespawnRequestEvent());
        getManager().closeScreen(DeathScreen.this);
    });
    WidgetUtil.trySubscribe(this, "settings", widget -> getManager().pushScreen("settingsMenuScreen"));
    WidgetUtil.trySubscribe(this, "mainMenu", widget -> {
        localPlayer.getClientEntity().send(new RespawnRequestEvent());
        gameEngine.changeState(new StateMainMenu());
    });
    WidgetUtil.trySubscribe(this, "exitGame", widget -> CoreRegistry.get(GameEngine.class).shutdown());
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) RespawnRequestEvent(org.terasology.engine.logic.players.event.RespawnRequestEvent) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu)

Aggregations

StateMainMenu (org.terasology.engine.core.modes.StateMainMenu)8 GameEngine (org.terasology.engine.core.GameEngine)4 ModuleManager (org.terasology.engine.core.module.ModuleManager)3 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)3 TerasologyEngineBuilder (org.terasology.engine.core.TerasologyEngineBuilder)2 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)2 RenderingModuleRegistry (org.terasology.engine.core.module.rendering.RenderingModuleRegistry)2 ModuleRendering (org.terasology.engine.rendering.dag.ModuleRendering)2 Module (org.terasology.gestalt.module.Module)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 UIManager (javax.swing.UIManager)1 AWTGLCanvas (org.lwjgl.opengl.awt.AWTGLCanvas)1 SceneProperties (org.terasology.editor.properties.SceneProperties)1 AwtInput (org.terasology.editor.subsystem.AwtInput)1 LwjglPortlet (org.terasology.editor.subsystem.LwjglPortlet)1