Search in sources :

Example 1 with ComponentSystem

use of org.terasology.engine.entitySystem.systems.ComponentSystem in project Terasology by MovingBlocks.

the class ReadWriteStorageManager method startSaving.

private void startSaving() {
    logger.info("Saving - Creating game snapshot");
    PerformanceMonitor.startActivity("Saving");
    ComponentSystemManager componentSystemManager = CoreRegistry.get(ComponentSystemManager.class);
    for (ComponentSystem sys : componentSystemManager.getAllSystems()) {
        sys.preSave();
    }
    saveRequested = false;
    saveTransaction = createSaveTransaction();
    saveThreadManager.offer(saveTransaction);
    if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.NOT_ACTIVATED) {
        saveGamePreviewImage();
    }
    for (ComponentSystem sys : componentSystemManager.getAllSystems()) {
        sys.postSave();
    }
    PerformanceMonitor.endActivity();
    entitySetDeltaRecorder = new EntitySetDeltaRecorder(this.entityRefReplacingComponentLibrary);
    logger.info("Saving - Snapshot created: Writing phase starts");
}
Also used : ComponentSystem(org.terasology.engine.entitySystem.systems.ComponentSystem) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager)

Example 2 with ComponentSystem

use of org.terasology.engine.entitySystem.systems.ComponentSystem in project Terasology by MovingBlocks.

the class PreBeginSystems method begin.

@Override
public void begin() {
    ComponentSystemManager csm = context.get(ComponentSystemManager.class);
    final List<ComponentSystem> componentSystemList = csm.getAllSystems();
    componentSystems = componentSystemList.iterator();
    setTotalSteps(componentSystemList.size());
}
Also used : ComponentSystem(org.terasology.engine.entitySystem.systems.ComponentSystem) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager)

Example 3 with ComponentSystem

use of org.terasology.engine.entitySystem.systems.ComponentSystem in project Terasology by MovingBlocks.

the class ComponentSystemManager method shutdown.

public void shutdown() {
    for (ComponentSystem system : getAllSystems()) {
        system.shutdown();
    }
    updateSubscribers.clear();
    renderSubscribers.clear();
}
Also used : ComponentSystem(org.terasology.engine.entitySystem.systems.ComponentSystem)

Example 4 with ComponentSystem

use of org.terasology.engine.entitySystem.systems.ComponentSystem in project Terasology by MovingBlocks.

the class ComponentSystemManager method tryToLoadSystem.

/**
 * Try to load system. try to rollback changes, when fails.
 *
 * @param system system's class for creation and loading.
 * @param id id of system.
 */
private void tryToLoadSystem(Class<?> system, String id) {
    ComponentSystem newSystem = null;
    try {
        newSystem = (ComponentSystem) system.newInstance();
        InjectionHelper.share(newSystem);
        register(newSystem, id);
        logger.debug("Loaded system {}", id);
    } catch (RuntimeException | InstantiationException | IllegalAccessException e) {
        logger.error("Failed to load system {}", id, e);
        rollbackLoading(newSystem, id);
    }
}
Also used : ComponentSystem(org.terasology.engine.entitySystem.systems.ComponentSystem)

Example 5 with ComponentSystem

use of org.terasology.engine.entitySystem.systems.ComponentSystem in project Terasology by MovingBlocks.

the class ComponentSystemManager method loadSystems.

public void loadSystems(ModuleEnvironment environment, NetworkMode netMode) {
    DisplayDevice display = context.get(DisplayDevice.class);
    boolean isHeadless = display.isHeadless();
    ListMultimap<Name, Class<?>> systemsByModule = ArrayListMultimap.create();
    for (Class<?> type : environment.getTypesAnnotatedWith(RegisterSystem.class)) {
        if (!ComponentSystem.class.isAssignableFrom(type)) {
            logger.error("Cannot load {}, must be a subclass of ComponentSystem", type.getSimpleName());
            continue;
        }
        Name moduleId = environment.getModuleProviding(type);
        RegisterSystem registerInfo = type.getAnnotation(RegisterSystem.class);
        if (registerInfo.value().isValidFor(netMode.isAuthority(), isHeadless) && areOptionalRequirementsContained(registerInfo, environment)) {
            systemsByModule.put(moduleId, type);
        }
    }
    for (Module module : environment.getModulesOrderedByDependencies()) {
        for (Class<?> system : systemsByModule.get(module.getId())) {
            String id = module.getId() + ":" + system.getSimpleName();
            logger.debug("Registering system {}", id);
            if (checkOptionalDependenciesPresent(system)) {
                tryToLoadSystem(system, id);
            } else {
                logger.warn("Skip system {} for loading - possibly missing optional dependencies", id);
            }
        }
    }
}
Also used : DisplayDevice(org.terasology.engine.core.subsystem.DisplayDevice) RegisterSystem(org.terasology.engine.entitySystem.systems.RegisterSystem) ComponentSystem(org.terasology.engine.entitySystem.systems.ComponentSystem) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

Aggregations

ComponentSystem (org.terasology.engine.entitySystem.systems.ComponentSystem)8 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)4 DisplayDevice (org.terasology.engine.core.subsystem.DisplayDevice)1 RegisterSystem (org.terasology.engine.entitySystem.systems.RegisterSystem)1 Console (org.terasology.engine.logic.console.Console)1 Module (org.terasology.gestalt.module.Module)1 Name (org.terasology.gestalt.naming.Name)1