Search in sources :

Example 1 with GameEngine

use of org.terasology.engine.core.GameEngine 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 2 with GameEngine

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

the class LoadingChunkEventSystem method onNewChunk.

/**
 * Event handler which waits for new chunk events, then sends those
 * events to the current game state
 * @param chunkAvailable an event which includes the position of the new chunk
 * @param worldEntity the world entity that this event was sent to
 */
@ReceiveEvent(components = WorldComponent.class)
public void onNewChunk(OnChunkLoaded chunkAvailable, EntityRef worldEntity) {
    GameEngine gameEngine = context.get(GameEngine.class);
    GameState gameState = gameEngine.getState();
    gameState.onChunkLoaded(chunkAvailable, worldEntity);
}
Also used : GameEngine(org.terasology.engine.core.GameEngine) GameState(org.terasology.engine.core.modes.GameState) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 3 with GameEngine

use of org.terasology.engine.core.GameEngine 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)

Example 4 with GameEngine

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

the class RenderingModuleSettingScreen method postInit.

public void postInit() {
    moduleEnvironment = subContext.get(ModuleEnvironment.class);
    renderingModuleRegistry = context.get(RenderingModuleRegistry.class);
    orderedModuleRenderingInstances = renderingModuleRegistry.updateRenderingModulesOrder(moduleEnvironment, subContext);
    if (orderedModuleRenderingInstances.isEmpty()) {
        logger.error("No rendering module found!");
        GameEngine gameEngine = context.get(GameEngine.class);
        gameEngine.changeState(new StateMainMenu("No rendering module installed, unable to render. Try enabling CoreRendering."));
        return;
    }
    renderingModuleInfo = find("modulesInfo", UIText.class);
    recalculateOrder = find("update", UIButton.class);
    setEnabledRenderingClassButton = find("setEnabledRenderingClassButton", UIButton.class);
    // List<Name> orderedModuleNames = new ArrayList<>();
    // orderedModuleRenderingInstances.forEach(module->orderedModuleNames.add(module.getProvidingModule()));
    initPrioritySlider = find("moduleInitPrioritySlider", UISlider.class);
    if (initPrioritySlider != null) {
        initPrioritySlider.setValue(2f);
        initPrioritySlider.setUiSliderOnChangeTriggeredListener(this);
    }
    moduleList = find("moduleNameList", UIDropdownScrollable.class);
    if (moduleList != null) {
        moduleList.bindSelection(new Binding<ModuleRendering>() {

            ModuleRendering selected;

            @Override
            public ModuleRendering get() {
                return selected;
            }

            @Override
            public void set(ModuleRendering value) {
                if (initPrioritySlider != null) {
                    initPrioritySlider.setValue(value.getInitPriority());
                }
                selected = value;
            }
        });
        moduleList.setOptions(orderedModuleRenderingInstances);
        moduleList.setVisibleOptions(5);
        moduleList.setSelection(orderedModuleRenderingInstances.get(0));
        if (initPrioritySlider != null) {
            initPrioritySlider.setValue(moduleList.getSelection().getInitPriority());
        }
        moduleList.setOptionRenderer(new StringTextRenderer<ModuleRendering>() {

            @Override
            public String getString(ModuleRendering value) {
                if (value != null) {
                    StringBuilder stringBuilder = new StringBuilder().append(String.format("%s", value.getClass().getSimpleName()));
                    return stringBuilder.toString();
                }
                return "";
            }

            @Override
            public void draw(ModuleRendering value, Canvas canvas) {
                canvas.drawText(getString(value), canvas.getRegion());
            }
        });
    }
    if (recalculateOrder != null) {
        updateRenderingModuleInfo();
        recalculateOrder.subscribe(button -> {
            renderingModuleRegistry.updateRenderingModulesOrder(moduleEnvironment, subContext);
            orderedModuleRenderingInstances = renderingModuleRegistry.getOrderedRenderingModules();
            updateRenderingModuleInfo();
        });
    }
    if (setEnabledRenderingClassButton != null && moduleList != null) {
        setEnabledRenderingClassButton.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return (moduleList.getSelection().isEnabled()) ? translationSystem.translate("${engine:menu#disable-rendering-class}") : translationSystem.translate("${engine:menu#enable-rendering-class}");
            }
        });
        setEnabledRenderingClassButton.subscribe(button -> {
            moduleList.getSelection().toggleEnabled();
            updateRenderingModuleInfo();
        });
    }
    // TODO returns one more screen every time...gradually
    WidgetUtil.trySubscribe(this, "return", widget -> getManager().pushScreen(StartPlayingScreen.ASSET_URI));
// Update slider if module selection changes
// if (initPrioritySlider != null && moduleList != null) {
// moduleList. (this, "moduleNameList", widget->initPrioritySlider.setValue(moduleList.getSelection().getInitPriority()));
// }
}
Also used : UISlider(org.terasology.nui.widgets.UISlider) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) Canvas(org.terasology.nui.Canvas) GameEngine(org.terasology.engine.core.GameEngine) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) ModuleRendering(org.terasology.engine.rendering.dag.ModuleRendering) UIButton(org.terasology.nui.widgets.UIButton) UIText(org.terasology.nui.widgets.UIText) RenderingModuleRegistry(org.terasology.engine.core.module.rendering.RenderingModuleRegistry)

Aggregations

GameEngine (org.terasology.engine.core.GameEngine)4 StateMainMenu (org.terasology.engine.core.modes.StateMainMenu)2 RenderingModuleRegistry (org.terasology.engine.core.module.rendering.RenderingModuleRegistry)2 ModuleRendering (org.terasology.engine.rendering.dag.ModuleRendering)2 EngineTime (org.terasology.engine.core.EngineTime)1 Time (org.terasology.engine.core.Time)1 GameState (org.terasology.engine.core.modes.GameState)1 AwaitCharacterSpawn (org.terasology.engine.core.modes.loadProcesses.AwaitCharacterSpawn)1 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)1 Canvas (org.terasology.nui.Canvas)1 UIButton (org.terasology.nui.widgets.UIButton)1 UIDropdownScrollable (org.terasology.nui.widgets.UIDropdownScrollable)1 UISlider (org.terasology.nui.widgets.UISlider)1 UIText (org.terasology.nui.widgets.UIText)1