Search in sources :

Example 1 with EngineSubsystem

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

the class TerasologyEngine method cleanup.

public void cleanup() {
    logger.info("Shutting down Terasology...");
    changeStatus(StandardGameStatus.SHUTTING_DOWN);
    if (currentState != null) {
        currentState.dispose(true);
        currentState = null;
    }
    Iterator<EngineSubsystem> preshutdownIter = allSubsystems.descendingIterator();
    while (preshutdownIter.hasNext()) {
        EngineSubsystem subsystem = preshutdownIter.next();
        try {
            subsystem.preShutdown();
        } catch (RuntimeException e) {
            logger.error("Error preparing to shutdown {} subsystem", subsystem.getName(), e);
        }
    }
    Iterator<EngineSubsystem> shutdownIter = allSubsystems.descendingIterator();
    while (shutdownIter.hasNext()) {
        EngineSubsystem subsystem = shutdownIter.next();
        try {
            subsystem.shutdown();
        } catch (RuntimeException e) {
            logger.error("Error shutting down {} subsystem", subsystem.getName(), e);
        }
    }
}
Also used : EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem)

Example 2 with EngineSubsystem

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

the class TerasologyEngine method postInitSubsystems.

/**
 * Gives a chance to subsystems to do something AFTER managers and Time are initialized.
 */
private void postInitSubsystems() {
    for (EngineSubsystem subsystem : getSubsystems()) {
        changeStatus(() -> "Post-Initialising " + subsystem.getName() + " subsystem");
        subsystem.postInitialise(rootContext);
    }
}
Also used : EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem)

Example 3 with EngineSubsystem

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

the class TerasologyEngine method initAssets.

private void initAssets() {
    // cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
    assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    assetTypeManager.createAssetType(BlockShape.class, BlockShapeImpl::new, "shapes");
    assetTypeManager.createAssetType(BlockSounds.class, BlockSounds::new, "blockSounds");
    assetTypeManager.createAssetType(BlockTile.class, BlockTile::new, "blockTiles");
    AssetType<BlockFamilyDefinition, BlockFamilyDefinitionData> blockFamilyDefinitionAssetType = assetTypeManager.createAssetType(BlockFamilyDefinition.class, BlockFamilyDefinition::new, "blocks");
    assetTypeManager.getAssetFileDataProducer(blockFamilyDefinitionAssetType).addAssetFormat(new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager()));
    assetTypeManager.createAssetType(UISkinAsset.class, UISkinAsset::new, "skins");
    assetTypeManager.createAssetType(BehaviorTree.class, BehaviorTree::new, "behaviors");
    assetTypeManager.createAssetType(UIElement.class, UIElement::new, "ui");
    assetTypeManager.createAssetType(ByteBufferAsset.class, ByteBufferAsset::new, "mesh");
    for (EngineSubsystem subsystem : allSubsystems) {
        subsystem.registerCoreAssetTypes(assetTypeManager);
    }
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) BlockShapeImpl(org.terasology.engine.world.block.shapes.BlockShapeImpl) UIElement(org.terasology.nui.asset.UIElement) UISkinAsset(org.terasology.nui.skin.UISkinAsset) BlockFamilyDefinitionFormat(org.terasology.engine.world.block.loader.BlockFamilyDefinitionFormat) BlockTile(org.terasology.engine.world.block.tiles.BlockTile) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree) ByteBufferAsset(org.terasology.engine.rendering.gltf.ByteBufferAsset) BlockSounds(org.terasology.engine.world.block.sounds.BlockSounds) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition)

Example 4 with EngineSubsystem

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

the class TerasologyEngine method tick.

/**
 * Runs a single "tick" of the engine
 *
 * @return true if the loop requesting a tick should continue running
 */
public boolean tick() {
    if (shutdownRequested) {
        return false;
    }
    if (assetTypeManager instanceof AutoReloadAssetTypeManager) {
        ((AutoReloadAssetTypeManager) assetTypeManager).reloadChangedAssets();
    }
    processPendingState();
    if (currentState == null) {
        shutdown();
        return false;
    }
    Iterator<Float> updateCycles = timeSubsystem.getEngineTime().tick();
    CoreRegistry.setContext(currentState.getContext());
    rootContext.get(NetworkSystem.class).setContext(currentState.getContext());
    for (EngineSubsystem subsystem : allSubsystems) {
        try (Activity ignored = PerformanceMonitor.startActivity(subsystem.getName() + " PreUpdate")) {
            subsystem.preUpdate(currentState, timeSubsystem.getEngineTime().getRealDelta());
        }
    }
    while (updateCycles.hasNext()) {
        // gameTime gets updated here!
        float updateDelta = updateCycles.next();
        try (Activity ignored = PerformanceMonitor.startActivity("Main Update")) {
            currentState.update(updateDelta);
        }
    }
    // Waiting processes are set by modules via GameThread.a/synch() methods.
    GameThread.processWaitingProcesses();
    for (EngineSubsystem subsystem : getSubsystems()) {
        try (Activity ignored = PerformanceMonitor.startActivity(subsystem.getName() + " Subsystem postUpdate")) {
            subsystem.postUpdate(currentState, timeSubsystem.getEngineTime().getRealDelta());
        }
    }
    assetTypeManager.disposedUnusedAssets();
    PerformanceMonitor.rollCycle();
    PerformanceMonitor.startActivity("Other");
    return true;
}
Also used : EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem) NetworkSystem(org.terasology.engine.network.NetworkSystem) Activity(org.terasology.engine.monitoring.Activity) AutoReloadAssetTypeManager(org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager)

Example 5 with EngineSubsystem

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

the class Terasology method populateSubsystems.

private void populateSubsystems(TerasologyEngineBuilder builder) {
    if (isHeadless) {
        builder.add(new HeadlessGraphics()).add(new HeadlessTimer()).add(new HeadlessAudio());
    } else {
        EngineSubsystem audio = soundEnabled ? new LwjglAudio() : new HeadlessAudio();
        builder.add(audio).add(new LwjglGraphics()).add(new LwjglTimer()).add(new LwjglInput()).add(new BindsSubsystem()).add(new OpenVRInput());
        builder.add(new DiscordRPCSubSystem());
    }
    builder.add(new HibernationSubsystem());
}
Also used : LwjglAudio(org.terasology.engine.core.subsystem.lwjgl.LwjglAudio) HeadlessTimer(org.terasology.engine.core.subsystem.headless.HeadlessTimer) BindsSubsystem(org.terasology.engine.core.subsystem.config.BindsSubsystem) HeadlessGraphics(org.terasology.engine.core.subsystem.headless.HeadlessGraphics) EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem) OpenVRInput(org.terasology.engine.core.subsystem.openvr.OpenVRInput) LwjglTimer(org.terasology.engine.core.subsystem.lwjgl.LwjglTimer) LwjglInput(org.terasology.engine.core.subsystem.lwjgl.LwjglInput) LwjglGraphics(org.terasology.engine.core.subsystem.lwjgl.LwjglGraphics) HeadlessAudio(org.terasology.engine.core.subsystem.headless.HeadlessAudio) DiscordRPCSubSystem(org.terasology.subsystem.discordrpc.DiscordRPCSubSystem) HibernationSubsystem(org.terasology.engine.core.subsystem.common.hibernation.HibernationSubsystem)

Aggregations

EngineSubsystem (org.terasology.engine.core.subsystem.EngineSubsystem)8 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)1 GameEngine (org.terasology.engine.core.GameEngine)1 TerasologyEngine (org.terasology.engine.core.TerasologyEngine)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 HibernationSubsystem (org.terasology.engine.core.subsystem.common.hibernation.HibernationSubsystem)1 BindsSubsystem (org.terasology.engine.core.subsystem.config.BindsSubsystem)1 HeadlessAudio (org.terasology.engine.core.subsystem.headless.HeadlessAudio)1 HeadlessGraphics (org.terasology.engine.core.subsystem.headless.HeadlessGraphics)1 HeadlessTimer (org.terasology.engine.core.subsystem.headless.HeadlessTimer)1 LwjglAudio (org.terasology.engine.core.subsystem.lwjgl.LwjglAudio)1 LwjglGraphics (org.terasology.engine.core.subsystem.lwjgl.LwjglGraphics)1 LwjglInput (org.terasology.engine.core.subsystem.lwjgl.LwjglInput)1 LwjglTimer (org.terasology.engine.core.subsystem.lwjgl.LwjglTimer)1 OpenVRInput (org.terasology.engine.core.subsystem.openvr.OpenVRInput)1 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)1 BehaviorTree (org.terasology.engine.logic.behavior.asset.BehaviorTree)1 Activity (org.terasology.engine.monitoring.Activity)1 NetworkSystem (org.terasology.engine.network.NetworkSystem)1 ByteBufferAsset (org.terasology.engine.rendering.gltf.ByteBufferAsset)1