Search in sources :

Example 1 with DisplayDevice

use of org.terasology.engine.subsystem.DisplayDevice 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, 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);
            try {
                ComponentSystem newSystem = (ComponentSystem) system.newInstance();
                InjectionHelper.share(newSystem);
                register(newSystem, id);
                logger.debug("Loaded system {}", id);
            } catch (RuntimeException | IllegalAccessException | InstantiationException | NoClassDefFoundError e) {
                logger.error("Failed to load system {}", id, e);
            }
        }
    }
}
Also used : DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) ComponentSystem(org.terasology.entitySystem.systems.ComponentSystem) Name(org.terasology.naming.Name) RegisterSystem(org.terasology.entitySystem.systems.RegisterSystem) Module(org.terasology.module.Module)

Example 2 with DisplayDevice

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

the class Metric method filterMetricMap.

/**
 * Filter the metric map by the binding map.
 * If the user doesn't want the field to be sent, its value will be covered by "Disabled Field".
 * @param bindingMap the binding map.
 * @return a new metric map that covers the field that the user doesn't want to send by "Disabled Field".
 */
protected Map<String, Object> filterMetricMap(Map<String, Boolean> bindingMap) {
    TelemetryCategory telemetryCategory = this.getClass().getAnnotation(TelemetryCategory.class);
    Context context = CoreRegistry.get(Context.class);
    DisplayDevice display = context.get(DisplayDevice.class);
    if (display.isHeadless() || telemetryCategory.isOneMapMetric()) {
        return telemetryFieldToValue;
    }
    Map<String, Object> metricMapAfterPermission = new HashMap<>();
    for (String fieldName : telemetryFieldToValue.keySet()) {
        String fieldNameWithID = telemetryCategory.id() + ":" + fieldName;
        if (bindingMap.containsKey(fieldNameWithID)) {
            if (bindingMap.get(fieldNameWithID)) {
                metricMapAfterPermission.put(fieldName, telemetryFieldToValue.get(fieldName));
            } else {
                metricMapAfterPermission.put(fieldName, "Disabled Field");
            }
        }
    }
    return metricMapAfterPermission;
}
Also used : Context(org.terasology.context.Context) TelemetryCategory(org.terasology.telemetry.TelemetryCategory) DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) HashMap(java.util.HashMap)

Example 3 with DisplayDevice

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

the class Metric method filterMetricMap.

/**
 * Filter the metric map by the binding map.
 * If the user doesn't want the field to be sent, its value will be covered by "Disabled Field".
 * This method could be used in module since {@link org.terasology.config.facade.TelemetryConfiguration} is exposed to modules
 * @param telemetryConfiguration the telemetry configuration exposed modules
 * @return a new metric map that covers the field that the user doesn't want to send by "Disabled Field".
 */
protected Map<String, Object> filterMetricMap(TelemetryConfiguration telemetryConfiguration) {
    TelemetryCategory telemetryCategory = this.getClass().getAnnotation(TelemetryCategory.class);
    Context context = CoreRegistry.get(Context.class);
    DisplayDevice display = context.get(DisplayDevice.class);
    if (display.isHeadless() || telemetryCategory.isOneMapMetric()) {
        return telemetryFieldToValue;
    }
    Map<String, Object> metricMapAfterPermission = new HashMap<>();
    for (String fieldName : telemetryFieldToValue.keySet()) {
        String fieldNameWithID = telemetryCategory.id() + ":" + fieldName;
        if (telemetryConfiguration.containsField(fieldNameWithID)) {
            if (telemetryConfiguration.get(fieldNameWithID)) {
                metricMapAfterPermission.put(fieldName, telemetryFieldToValue.get(fieldName));
            } else {
                metricMapAfterPermission.put(fieldName, "Disabled Field");
            }
        }
    }
    return metricMapAfterPermission;
}
Also used : Context(org.terasology.context.Context) TelemetryCategory(org.terasology.telemetry.TelemetryCategory) DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) HashMap(java.util.HashMap)

Example 4 with DisplayDevice

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

the class StateIngame method render.

@Override
public void render() {
    DisplayDevice display = context.get(DisplayDevice.class);
    display.prepareToRender();
    if (worldRenderer != null) {
        if (!context.get(Config.class).getRendering().isVrSupport()) {
            worldRenderer.render(RenderingStage.MONO);
        } else {
            worldRenderer.render(RenderingStage.LEFT_EYE);
            worldRenderer.render(RenderingStage.RIGHT_EYE);
        }
    }
    /* UI */
    PerformanceMonitor.startActivity("Render and Update UI");
    renderUserInterface();
    PerformanceMonitor.endActivity();
}
Also used : DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) Config(org.terasology.config.Config)

Aggregations

DisplayDevice (org.terasology.engine.subsystem.DisplayDevice)4 HashMap (java.util.HashMap)2 Context (org.terasology.context.Context)2 TelemetryCategory (org.terasology.telemetry.TelemetryCategory)2 Config (org.terasology.config.Config)1 ComponentSystem (org.terasology.entitySystem.systems.ComponentSystem)1 RegisterSystem (org.terasology.entitySystem.systems.RegisterSystem)1 Module (org.terasology.module.Module)1 Name (org.terasology.naming.Name)1