Search in sources :

Example 1 with Time

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

the class StateLoading method init.

@Override
public void init(GameEngine engine) {
    this.context = engine.createChildContext();
    headless = context.get(DisplayDevice.class).isHeadless();
    CoreRegistry.setContext(context);
    systemConfig = context.get(SystemConfig.class);
    if (!headless) {
        this.nuiManager = new NUIManagerInternal((TerasologyCanvasRenderer) context.get(CanvasRenderer.class), context);
        context.put(NUIManager.class, nuiManager);
    }
    EngineTime time = (EngineTime) context.get(Time.class);
    time.setPaused(true);
    time.setGameTime(gameManifest.getTime());
    context.get(Game.class).load(gameManifest);
    switch(netMode) {
        case CLIENT:
            initClient();
            break;
        default:
            initHost();
            break;
    }
    progress = 0;
    maxProgress = 0;
    for (LoadProcess process : loadProcesses) {
        maxProgress += process.getExpectedCost();
    }
    popStep();
    if (nuiManager != null) {
        loadingScreen = nuiManager.pushScreen("engine:loadingScreen", LoadingScreen.class);
        loadingScreen.updateStatus(current.getMessage(), current.getProgress());
    }
    chunkGenerationStarted = false;
}
Also used : SystemConfig(org.terasology.engine.config.SystemConfig) Game(org.terasology.engine.game.Game) CanvasRenderer(org.terasology.nui.canvas.CanvasRenderer) TerasologyCanvasRenderer(org.terasology.engine.rendering.nui.internal.TerasologyCanvasRenderer) EngineTime(org.terasology.engine.core.EngineTime) EngineTime(org.terasology.engine.core.EngineTime) Time(org.terasology.engine.core.Time) LoadingScreen(org.terasology.engine.rendering.nui.layers.mainMenu.loadingScreen.LoadingScreen) TerasologyCanvasRenderer(org.terasology.engine.rendering.nui.internal.TerasologyCanvasRenderer) NUIManagerInternal(org.terasology.engine.rendering.nui.internal.NUIManagerInternal)

Example 2 with Time

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

the class StateLoading method onChunkLoaded.

@Override
public void onChunkLoaded(OnChunkLoaded chunkAvailable, EntityRef worldEntity) {
    EngineTime time = (EngineTime) context.get(Time.class);
    timeLastChunkGenerated = time.getRealTimeInMs();
}
Also used : EngineTime(org.terasology.engine.core.EngineTime) EngineTime(org.terasology.engine.core.EngineTime) Time(org.terasology.engine.core.Time)

Example 3 with Time

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

the class StateLoading method dispose.

@Override
public void dispose(boolean shuttingDown) {
    EngineTime time = (EngineTime) context.get(Time.class);
    time.setPaused(false);
}
Also used : EngineTime(org.terasology.engine.core.EngineTime) EngineTime(org.terasology.engine.core.EngineTime) Time(org.terasology.engine.core.Time)

Example 4 with Time

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

the class PrepareWorld method step.

@Override
public boolean step() {
    if (worldRenderer.pregenerateChunks()) {
        return true;
    }
    EngineTime time = (EngineTime) context.get(Time.class);
    timeElapsed = time.getRealTimeInMs() - startTime;
    return timeElapsed > 5000;
}
Also used : EngineTime(org.terasology.engine.core.EngineTime) EngineTime(org.terasology.engine.core.EngineTime) Time(org.terasology.engine.core.Time)

Example 5 with Time

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

the class StateLoading method update.

@Override
public void update(float delta) {
    GameEngine gameEngine = context.get(GameEngine.class);
    EngineTime time = (EngineTime) context.get(Time.class);
    long startTime = time.getRealTimeInMs();
    while (current != null && time.getRealTimeInMs() - startTime < 20 && !gameEngine.hasPendingState()) {
        try {
            if (current.step()) {
                popStep();
            }
        } catch (Exception e) {
            logger.error("Error while loading {}", current, e);
            String errorMessage = String.format("Failed to load game. There was an error during \"%s\".", current == null ? "the last part" : current.getMessage());
            gameEngine.changeState(new StateMainMenu(errorMessage));
            CrashReporter.report(e, LoggingContext.getLoggingPath());
            return;
        }
    }
    if (current == null) {
        if (nuiManager != null) {
            nuiManager.closeScreen(loadingScreen);
            nuiManager.setHUDVisible(true);
        }
        context.get(GameEngine.class).changeState(new StateIngame(gameManifest, context));
    } else {
        float progressValue = (progress + current.getExpectedCost() * current.getProgress()) / maxProgress;
        if (nuiManager != null) {
            loadingScreen.updateStatus(current.getMessage(), progressValue);
            nuiManager.update(delta);
        }
        // chunk generation begins at the AwaitCharacterSpawn step
        if (current instanceof AwaitCharacterSpawn && !chunkGenerationStarted) {
            chunkGenerationStarted = true;
            // in case no chunks generate, this should be set for a basis
            timeLastChunkGenerated = time.getRealTimeInMs();
        }
        if (chunkGenerationStarted) {
            long timeSinceLastChunk = time.getRealTimeInMs() - timeLastChunkGenerated;
            long chunkGenerationTimeout = systemConfig.chunkGenerationFailTimeoutInMs.get();
            if (timeSinceLastChunk > chunkGenerationTimeout) {
                String errorMessage = "World generation timed out, check the log for more info";
                gameEngine.changeState(new StateMainMenu(errorMessage));
            }
        }
    }
}
Also used : EngineTime(org.terasology.engine.core.EngineTime) GameEngine(org.terasology.engine.core.GameEngine) EngineTime(org.terasology.engine.core.EngineTime) Time(org.terasology.engine.core.Time) AwaitCharacterSpawn(org.terasology.engine.core.modes.loadProcesses.AwaitCharacterSpawn)

Aggregations

Time (org.terasology.engine.core.Time)7 EngineTime (org.terasology.engine.core.EngineTime)6 Game (org.terasology.engine.game.Game)2 SystemConfig (org.terasology.engine.config.SystemConfig)1 UniverseConfig (org.terasology.engine.config.UniverseConfig)1 GameEngine (org.terasology.engine.core.GameEngine)1 AwaitCharacterSpawn (org.terasology.engine.core.modes.loadProcesses.AwaitCharacterSpawn)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 GameManifest (org.terasology.engine.game.GameManifest)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 ClientComponent (org.terasology.engine.network.ClientComponent)1 NUIManagerInternal (org.terasology.engine.rendering.nui.internal.NUIManagerInternal)1 TerasologyCanvasRenderer (org.terasology.engine.rendering.nui.internal.TerasologyCanvasRenderer)1 LoadingScreen (org.terasology.engine.rendering.nui.layers.mainMenu.loadingScreen.LoadingScreen)1 WorldRenderer (org.terasology.engine.rendering.world.WorldRenderer)1 BlockManager (org.terasology.engine.world.block.BlockManager)1 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)1 WorldConfigurator (org.terasology.engine.world.generator.WorldConfigurator)1 WorldGenerator (org.terasology.engine.world.generator.WorldGenerator)1 WorldInfo (org.terasology.engine.world.internal.WorldInfo)1