Search in sources :

Example 1 with StateHeadlessSetup

use of org.terasology.engine.subsystem.headless.mode.StateHeadlessSetup in project Terasology by MovingBlocks.

the class Terasology method main.

public static void main(String[] args) {
    handlePrintUsageRequest(args);
    handleLaunchArguments(args);
    SplashScreen splashScreen = splashEnabled ? configureSplashScreen() : SplashScreenBuilder.createStub();
    splashScreen.post("Java Runtime " + System.getProperty("java.version") + " loaded");
    setupLogging();
    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) {
                engine.getFromEngineContext(ThreadManager.class).submitTask("loadGame", () -> {
                    GameManifest gameManifest = getLatestGameManifest();
                    if (gameManifest != null) {
                        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);
    }
}
Also used : GameManifest(org.terasology.game.GameManifest) StateLoading(org.terasology.engine.modes.StateLoading) HeadlessStateChangeListener(org.terasology.engine.subsystem.headless.mode.HeadlessStateChangeListener) StateMainMenu(org.terasology.engine.modes.StateMainMenu) SplashScreen(org.terasology.splash.SplashScreen) StateHeadlessSetup(org.terasology.engine.subsystem.headless.mode.StateHeadlessSetup) ThreadManager(org.terasology.engine.subsystem.common.ThreadManager)

Aggregations

StateLoading (org.terasology.engine.modes.StateLoading)1 StateMainMenu (org.terasology.engine.modes.StateMainMenu)1 ThreadManager (org.terasology.engine.subsystem.common.ThreadManager)1 HeadlessStateChangeListener (org.terasology.engine.subsystem.headless.mode.HeadlessStateChangeListener)1 StateHeadlessSetup (org.terasology.engine.subsystem.headless.mode.StateHeadlessSetup)1 GameManifest (org.terasology.game.GameManifest)1 SplashScreen (org.terasology.splash.SplashScreen)1