Search in sources :

Example 1 with MapRenderer

use of com.badlogic.gdx.maps.MapRenderer in project gdx-graph by MarcinSc.

the class MapsLayerIdsRendererPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(final JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String mapId = data.getString("id");
    final String[] layerIds = data.getString("layers").split(",");
    final int[] ids = new int[layerIds.length];
    for (int i = 0; i < layerIds.length; i++) {
        ids[i] = Integer.parseInt(layerIds[i]);
    }
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput<RenderPipeline> output = new DefaultFieldOutput<>(PipelineFieldType.RenderPipeline);
    result.put("output", output);
    return new SingleInputsPipelineNode(result) {

        private MapsPluginPrivateData mapsPluginData;

        @Override
        public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
            mapsPluginData = pipelineDataProvider.getPrivatePluginData(MapsPluginPrivateData.class);
        }

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            final PipelineNode.FieldOutput<Boolean> processorEnabled = (PipelineNode.FieldOutput<Boolean>) inputs.get("enabled");
            final PipelineNode.FieldOutput<Camera> cameraInput = (PipelineNode.FieldOutput<Camera>) inputs.get("camera");
            final PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            Camera camera = cameraInput.getValue();
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            Map map = mapsPluginData.getMap(mapId);
            MapRenderer mapRenderer = mapsPluginData.getMapRenderer(mapId);
            if (enabled && map != null) {
                // Sadly need to switch off (and then on) the RenderContext
                pipelineRenderingContext.getRenderContext().end();
                RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
                currentBuffer.beginColor();
                mapRenderer.setView((OrthographicCamera) camera);
                mapRenderer.render(ids);
                currentBuffer.endColor();
                pipelineRenderingContext.getRenderContext().begin();
            }
            output.setValue(renderPipeline);
        }
    };
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) Camera(com.badlogic.gdx.graphics.Camera) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) MapsPluginPrivateData(com.gempukku.libgdx.graph.plugin.maps.MapsPluginPrivateData) RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) MapRenderer(com.badlogic.gdx.maps.MapRenderer) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Map(com.badlogic.gdx.maps.Map) RenderPipeline(com.gempukku.libgdx.graph.pipeline.RenderPipeline)

Example 2 with MapRenderer

use of com.badlogic.gdx.maps.MapRenderer in project gdx-graph by MarcinSc.

the class MapsLayersRendererPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(final JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String mapId = data.getString("id");
    final String[] layerNames = data.getString("layers").split(",");
    final int[] ids = new int[layerNames.length];
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput<RenderPipeline> output = new DefaultFieldOutput<>(PipelineFieldType.RenderPipeline);
    result.put("output", output);
    return new SingleInputsPipelineNode(result) {

        private MapsPluginPrivateData mapsPluginData;

        @Override
        public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
            mapsPluginData = pipelineDataProvider.getPrivatePluginData(MapsPluginPrivateData.class);
        }

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            final PipelineNode.FieldOutput<Boolean> processorEnabled = (PipelineNode.FieldOutput<Boolean>) inputs.get("enabled");
            final PipelineNode.FieldOutput<Camera> cameraInput = (PipelineNode.FieldOutput<Camera>) inputs.get("camera");
            final PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            Camera camera = cameraInput.getValue();
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            Map map = mapsPluginData.getMap(mapId);
            MapRenderer mapRenderer = mapsPluginData.getMapRenderer(mapId);
            if (enabled && map != null) {
                // Sadly need to switch off (and then on) the RenderContext
                pipelineRenderingContext.getRenderContext().end();
                RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
                for (int i = 0; i < layerNames.length; i++) {
                    ids[i] = map.getLayers().getIndex(layerNames[i].trim());
                }
                currentBuffer.beginColor();
                mapRenderer.setView((OrthographicCamera) camera);
                mapRenderer.render(ids);
                currentBuffer.endColor();
                pipelineRenderingContext.getRenderContext().begin();
            }
            output.setValue(renderPipeline);
        }
    };
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) Camera(com.badlogic.gdx.graphics.Camera) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) MapsPluginPrivateData(com.gempukku.libgdx.graph.plugin.maps.MapsPluginPrivateData) RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) MapRenderer(com.badlogic.gdx.maps.MapRenderer) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Map(com.badlogic.gdx.maps.Map) RenderPipeline(com.gempukku.libgdx.graph.pipeline.RenderPipeline)

Example 3 with MapRenderer

use of com.badlogic.gdx.maps.MapRenderer in project gdx-graph by MarcinSc.

the class MapsRendererPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String mapId = data.getString("id");
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput<RenderPipeline> output = new DefaultFieldOutput<>(PipelineFieldType.RenderPipeline);
    result.put("output", output);
    return new SingleInputsPipelineNode(result) {

        private MapsPluginPrivateData mapsPluginData;

        @Override
        public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
            mapsPluginData = pipelineDataProvider.getPrivatePluginData(MapsPluginPrivateData.class);
        }

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            final PipelineNode.FieldOutput<Boolean> processorEnabled = (PipelineNode.FieldOutput<Boolean>) inputs.get("enabled");
            final PipelineNode.FieldOutput<Camera> cameraInput = (PipelineNode.FieldOutput<Camera>) inputs.get("camera");
            final PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            Camera camera = cameraInput.getValue();
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            Map map = mapsPluginData.getMap(mapId);
            MapRenderer mapRenderer = mapsPluginData.getMapRenderer(mapId);
            if (enabled && map != null) {
                // Sadly need to switch off (and then on) the RenderContext
                pipelineRenderingContext.getRenderContext().end();
                RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
                currentBuffer.beginColor();
                mapRenderer.setView((OrthographicCamera) camera);
                mapRenderer.render();
                currentBuffer.endColor();
                pipelineRenderingContext.getRenderContext().begin();
            }
            output.setValue(renderPipeline);
        }
    };
}
Also used : MapsPluginPrivateData(com.gempukku.libgdx.graph.plugin.maps.MapsPluginPrivateData) RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) ObjectMap(com.badlogic.gdx.utils.ObjectMap) MapRenderer(com.badlogic.gdx.maps.MapRenderer) Camera(com.badlogic.gdx.graphics.Camera) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Map(com.badlogic.gdx.maps.Map) RenderPipeline(com.gempukku.libgdx.graph.pipeline.RenderPipeline)

Aggregations

Camera (com.badlogic.gdx.graphics.Camera)3 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)3 Map (com.badlogic.gdx.maps.Map)3 MapRenderer (com.badlogic.gdx.maps.MapRenderer)3 ObjectMap (com.badlogic.gdx.utils.ObjectMap)3 RenderPipeline (com.gempukku.libgdx.graph.pipeline.RenderPipeline)3 RenderPipelineBuffer (com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer)3 PipelineRenderingContext (com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext)3 MapsPluginPrivateData (com.gempukku.libgdx.graph.plugin.maps.MapsPluginPrivateData)3