Search in sources :

Example 1 with Time

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

the class ReadWriteStorageManager method addGameManifestToSaveTransaction.

private void addGameManifestToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder) {
    BlockManager blockManager = CoreRegistry.get(BlockManager.class);
    BiomeManager biomeManager = CoreRegistry.get(BiomeManager.class);
    WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
    Time time = CoreRegistry.get(Time.class);
    Game game = CoreRegistry.get(Game.class);
    GameManifest gameManifest = new GameManifest(game.getName(), game.getSeed(), time.getGameTimeInMs());
    for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    List<String> registeredBlockFamilies = Lists.newArrayList();
    for (BlockFamily family : blockManager.listRegisteredBlockFamilies()) {
        registeredBlockFamilies.add(family.getURI().toString());
    }
    gameManifest.setRegisteredBlockFamilies(registeredBlockFamilies);
    gameManifest.setBlockIdMap(blockManager.getBlockIdMap());
    List<Biome> biomes = biomeManager.getBiomes();
    Map<String, Short> biomeIdMap = new HashMap<>(biomes.size());
    for (Biome biome : biomes) {
        short shortId = biomeManager.getBiomeShortId(biome);
        String id = biomeManager.getBiomeId(biome);
        biomeIdMap.put(id, shortId);
    }
    gameManifest.setBiomeIdMap(biomeIdMap);
    gameManifest.addWorld(worldProvider.getWorldInfo());
    saveTransactionBuilder.setGameManifest(gameManifest);
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) HashMap(java.util.HashMap) Time(org.terasology.engine.Time) ModuleManager(org.terasology.engine.module.ModuleManager) Game(org.terasology.game.Game) Biome(org.terasology.world.biomes.Biome) GameManifest(org.terasology.game.GameManifest) BlockManager(org.terasology.world.block.BlockManager) WorldProvider(org.terasology.world.WorldProvider) BlockFamily(org.terasology.world.block.family.BlockFamily) Module(org.terasology.module.Module)

Example 2 with Time

use of org.terasology.engine.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.EngineTime) Time(org.terasology.engine.Time) EngineTime(org.terasology.engine.EngineTime)

Example 3 with Time

use of org.terasology.engine.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()) {
        if (current.step()) {
            popStep();
        }
    }
    if (current == 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;
        loadingScreen.updateStatus(current.getMessage(), progressValue);
        nuiManager.update(delta);
    }
}
Also used : EngineTime(org.terasology.engine.EngineTime) GameEngine(org.terasology.engine.GameEngine) Time(org.terasology.engine.Time) EngineTime(org.terasology.engine.EngineTime)

Example 4 with Time

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

the class StateLoading method init.

@Override
public void init(GameEngine engine) {
    this.context = engine.createChildContext();
    CoreRegistry.setContext(context);
    this.nuiManager = new NUIManagerInternal(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();
    loadingScreen = nuiManager.pushScreen("engine:loadingScreen", LoadingScreen.class);
    loadingScreen.updateStatus(current.getMessage(), current.getProgress());
}
Also used : Game(org.terasology.game.Game) EngineTime(org.terasology.engine.EngineTime) Time(org.terasology.engine.Time) EngineTime(org.terasology.engine.EngineTime) LoadingScreen(org.terasology.rendering.nui.layers.mainMenu.loadingScreen.LoadingScreen) NUIManagerInternal(org.terasology.rendering.nui.internal.NUIManagerInternal)

Example 5 with Time

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

the class PrepareWorld method begin.

@Override
public void begin() {
    worldRenderer = context.get(WorldRenderer.class);
    EngineTime time = (EngineTime) context.get(Time.class);
    startTime = time.getRealTimeInMs();
}
Also used : EngineTime(org.terasology.engine.EngineTime) EngineTime(org.terasology.engine.EngineTime) Time(org.terasology.engine.Time) WorldRenderer(org.terasology.rendering.world.WorldRenderer)

Aggregations

Time (org.terasology.engine.Time)6 EngineTime (org.terasology.engine.EngineTime)5 Game (org.terasology.game.Game)2 HashMap (java.util.HashMap)1 GameEngine (org.terasology.engine.GameEngine)1 ModuleManager (org.terasology.engine.module.ModuleManager)1 GameManifest (org.terasology.game.GameManifest)1 Module (org.terasology.module.Module)1 NUIManagerInternal (org.terasology.rendering.nui.internal.NUIManagerInternal)1 LoadingScreen (org.terasology.rendering.nui.layers.mainMenu.loadingScreen.LoadingScreen)1 WorldRenderer (org.terasology.rendering.world.WorldRenderer)1 WorldProvider (org.terasology.world.WorldProvider)1 Biome (org.terasology.world.biomes.Biome)1 BiomeManager (org.terasology.world.biomes.BiomeManager)1 BlockManager (org.terasology.world.block.BlockManager)1 BlockFamily (org.terasology.world.block.family.BlockFamily)1