Skip to content

Commit

Permalink
Fixed layered spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
pianoman911 committed Apr 4, 2023
1 parent 3969637 commit 0d010b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package de.pianoman911.mapengine.api.drawing;

import de.pianoman911.mapengine.api.pipeline.IPipelineContext;
import de.pianoman911.mapengine.api.pipeline.IPipelineInput;
import de.pianoman911.mapengine.api.util.FullSpacedColorBuffer;

import java.util.List;

public interface ILayeredDrawingSpace {
public interface ILayeredDrawingSpace extends IPipelineInput {

/**
* Returns all layers of this drawing space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.pianoman911.mapengine.api.pipeline.IPipelineContext;
import de.pianoman911.mapengine.api.util.FullSpacedColorBuffer;
import de.pianoman911.mapengine.core.pipeline.PipelineContext;
import it.unimi.dsi.fastutil.Pair;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -15,8 +16,8 @@ public class LayeredDrawingSpace implements ILayeredDrawingSpace {
private final FullSpacedColorBuffer resultBuffer;
private final PipelineContext context;

public LayeredDrawingSpace(FullSpacedColorBuffer resultSpace, PipelineContext context) {
this.resultBuffer = resultSpace;
public LayeredDrawingSpace(FullSpacedColorBuffer initialBuffer, PipelineContext context) {
this.resultBuffer = initialBuffer;
this.context = context;
}

Expand All @@ -30,6 +31,24 @@ public FullSpacedColorBuffer resultBuffer() {
return resultBuffer;
}

@Override
public Pair<FullSpacedColorBuffer, IPipelineContext> combined() {
return Pair.of(resultBuffer, context);
}

@Override
public FullSpacedColorBuffer buffer() {
if (layers.isEmpty()) {
return resultBuffer;
} else {
FullSpacedColorBuffer result = resultBuffer.copy();
for (IDrawingSpace layer : layers) {
result.buffer(layer.buffer(), 0, 0);
}
return result;
}
}

@Override
public IPipelineContext ctx() {
return context;
Expand All @@ -42,7 +61,7 @@ public IDrawingSpace layer(int index) {

@Override
public IDrawingSpace newLayer() {
DrawingSpace drawingSpace = new DrawingSpace(resultBuffer, context);
DrawingSpace drawingSpace = new DrawingSpace(resultBuffer.copy(), context);
layers.add(drawingSpace);
return drawingSpace;
}
Expand Down

0 comments on commit 0d010b6

Please sign in to comment.