Skip to content

Commit

Permalink
Use lists instead of sets in BatchManager
Browse files Browse the repository at this point in the history
  • Loading branch information
jonafanho committed Jun 19, 2024
1 parent f03a835 commit 16f5293
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import org.mtr.mapping.render.shader.ShaderManager;
import org.mtr.mapping.render.vertex.VertexAttributeState;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BatchManager {

private final Map<MaterialProperties, Set<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> translucentBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> translucentBatches = new HashMap<>();

public void queue(List<VertexArray> vertexArrays, VertexAttributeState vertexAttributeState) {
vertexArrays.forEach(vertexArray -> queue(vertexArray, vertexAttributeState));
}

public void queue(VertexArray vertexArray, VertexAttributeState vertexAttributeState) {
final MaterialProperties materialProperties = vertexArray.materialProperties;
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new HashSet<>()).add(new RenderCall(vertexArray, vertexAttributeState));
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new ArrayList<>()).add(new RenderCall(vertexArray, vertexAttributeState));
}

public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
Expand All @@ -29,7 +32,7 @@ public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
}
}

private static void drawBatch(Map<MaterialProperties, Set<RenderCall>> batches, ShaderManager shaderManager) {
private static void drawBatch(Map<MaterialProperties, List<RenderCall>> batches, ShaderManager shaderManager) {
batches.forEach((materialProperties, renderCalls) -> {
shaderManager.setupShaderBatchState(materialProperties);
renderCalls.forEach(RenderCall::draw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import org.mtr.mapping.render.shader.ShaderManager;
import org.mtr.mapping.render.vertex.VertexAttributeState;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BatchManager {

private final Map<MaterialProperties, Set<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> translucentBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> translucentBatches = new HashMap<>();

public void queue(List<VertexArray> vertexArrays, VertexAttributeState vertexAttributeState) {
vertexArrays.forEach(vertexArray -> queue(vertexArray, vertexAttributeState));
}

public void queue(VertexArray vertexArray, VertexAttributeState vertexAttributeState) {
final MaterialProperties materialProperties = vertexArray.materialProperties;
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new HashSet<>()).add(new RenderCall(vertexArray, vertexAttributeState));
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new ArrayList<>()).add(new RenderCall(vertexArray, vertexAttributeState));
}

public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
Expand All @@ -29,7 +32,7 @@ public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
}
}

private static void drawBatch(Map<MaterialProperties, Set<RenderCall>> batches, ShaderManager shaderManager) {
private static void drawBatch(Map<MaterialProperties, List<RenderCall>> batches, ShaderManager shaderManager) {
batches.forEach((materialProperties, renderCalls) -> {
shaderManager.setupShaderBatchState(materialProperties);
renderCalls.forEach(RenderCall::draw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import org.mtr.mapping.render.shader.ShaderManager;
import org.mtr.mapping.render.vertex.VertexAttributeState;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BatchManager {

private final Map<MaterialProperties, Set<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> translucentBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> translucentBatches = new HashMap<>();

public void queue(List<VertexArray> vertexArrays, VertexAttributeState vertexAttributeState) {
vertexArrays.forEach(vertexArray -> queue(vertexArray, vertexAttributeState));
}

public void queue(VertexArray vertexArray, VertexAttributeState vertexAttributeState) {
final MaterialProperties materialProperties = vertexArray.materialProperties;
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new HashSet<>()).add(new RenderCall(vertexArray, vertexAttributeState));
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new ArrayList<>()).add(new RenderCall(vertexArray, vertexAttributeState));
}

public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
Expand All @@ -29,7 +32,7 @@ public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
}
}

private static void drawBatch(Map<MaterialProperties, Set<RenderCall>> batches, ShaderManager shaderManager) {
private static void drawBatch(Map<MaterialProperties, List<RenderCall>> batches, ShaderManager shaderManager) {
batches.forEach((materialProperties, renderCalls) -> {
shaderManager.setupShaderBatchState(materialProperties);
renderCalls.forEach(RenderCall::draw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import org.mtr.mapping.render.shader.ShaderManager;
import org.mtr.mapping.render.vertex.VertexAttributeState;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BatchManager {

private final Map<MaterialProperties, Set<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> translucentBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> translucentBatches = new HashMap<>();

public void queue(List<VertexArray> vertexArrays, VertexAttributeState vertexAttributeState) {
vertexArrays.forEach(vertexArray -> queue(vertexArray, vertexAttributeState));
}

public void queue(VertexArray vertexArray, VertexAttributeState vertexAttributeState) {
final MaterialProperties materialProperties = vertexArray.materialProperties;
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new HashSet<>()).add(new RenderCall(vertexArray, vertexAttributeState));
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new ArrayList<>()).add(new RenderCall(vertexArray, vertexAttributeState));
}

public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
Expand All @@ -29,7 +32,7 @@ public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
}
}

private static void drawBatch(Map<MaterialProperties, Set<RenderCall>> batches, ShaderManager shaderManager) {
private static void drawBatch(Map<MaterialProperties, List<RenderCall>> batches, ShaderManager shaderManager) {
batches.forEach((materialProperties, renderCalls) -> {
shaderManager.setupShaderBatchState(materialProperties);
renderCalls.forEach(RenderCall::draw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import org.mtr.mapping.render.shader.ShaderManager;
import org.mtr.mapping.render.vertex.VertexAttributeState;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BatchManager {

private final Map<MaterialProperties, Set<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> translucentBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> translucentBatches = new HashMap<>();

public void queue(List<VertexArray> vertexArrays, VertexAttributeState vertexAttributeState) {
vertexArrays.forEach(vertexArray -> queue(vertexArray, vertexAttributeState));
}

public void queue(VertexArray vertexArray, VertexAttributeState vertexAttributeState) {
final MaterialProperties materialProperties = vertexArray.materialProperties;
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new HashSet<>()).add(new RenderCall(vertexArray, vertexAttributeState));
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new ArrayList<>()).add(new RenderCall(vertexArray, vertexAttributeState));
}

public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
Expand All @@ -29,7 +32,7 @@ public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
}
}

private static void drawBatch(Map<MaterialProperties, Set<RenderCall>> batches, ShaderManager shaderManager) {
private static void drawBatch(Map<MaterialProperties, List<RenderCall>> batches, ShaderManager shaderManager) {
batches.forEach((materialProperties, renderCalls) -> {
shaderManager.setupShaderBatchState(materialProperties);
renderCalls.forEach(RenderCall::draw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import org.mtr.mapping.render.shader.ShaderManager;
import org.mtr.mapping.render.vertex.VertexAttributeState;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BatchManager {

private final Map<MaterialProperties, Set<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> translucentBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> translucentBatches = new HashMap<>();

public void queue(List<VertexArray> vertexArrays, VertexAttributeState vertexAttributeState) {
vertexArrays.forEach(vertexArray -> queue(vertexArray, vertexAttributeState));
}

public void queue(VertexArray vertexArray, VertexAttributeState vertexAttributeState) {
final MaterialProperties materialProperties = vertexArray.materialProperties;
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new HashSet<>()).add(new RenderCall(vertexArray, vertexAttributeState));
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new ArrayList<>()).add(new RenderCall(vertexArray, vertexAttributeState));
}

public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
Expand All @@ -29,7 +32,7 @@ public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
}
}

private static void drawBatch(Map<MaterialProperties, Set<RenderCall>> batches, ShaderManager shaderManager) {
private static void drawBatch(Map<MaterialProperties, List<RenderCall>> batches, ShaderManager shaderManager) {
batches.forEach((materialProperties, renderCalls) -> {
shaderManager.setupShaderBatchState(materialProperties);
renderCalls.forEach(RenderCall::draw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import org.mtr.mapping.render.shader.ShaderManager;
import org.mtr.mapping.render.vertex.VertexAttributeState;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BatchManager {

private final Map<MaterialProperties, Set<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> translucentBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> translucentBatches = new HashMap<>();

public void queue(List<VertexArray> vertexArrays, VertexAttributeState vertexAttributeState) {
vertexArrays.forEach(vertexArray -> queue(vertexArray, vertexAttributeState));
}

public void queue(VertexArray vertexArray, VertexAttributeState vertexAttributeState) {
final MaterialProperties materialProperties = vertexArray.materialProperties;
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new HashSet<>()).add(new RenderCall(vertexArray, vertexAttributeState));
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new ArrayList<>()).add(new RenderCall(vertexArray, vertexAttributeState));
}

public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
Expand All @@ -29,7 +32,7 @@ public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
}
}

private static void drawBatch(Map<MaterialProperties, Set<RenderCall>> batches, ShaderManager shaderManager) {
private static void drawBatch(Map<MaterialProperties, List<RenderCall>> batches, ShaderManager shaderManager) {
batches.forEach((materialProperties, renderCalls) -> {
shaderManager.setupShaderBatchState(materialProperties);
renderCalls.forEach(RenderCall::draw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import org.mtr.mapping.render.shader.ShaderManager;
import org.mtr.mapping.render.vertex.VertexAttributeState;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BatchManager {

private final Map<MaterialProperties, Set<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> translucentBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> translucentBatches = new HashMap<>();

public void queue(List<VertexArray> vertexArrays, VertexAttributeState vertexAttributeState) {
vertexArrays.forEach(vertexArray -> queue(vertexArray, vertexAttributeState));
}

public void queue(VertexArray vertexArray, VertexAttributeState vertexAttributeState) {
final MaterialProperties materialProperties = vertexArray.materialProperties;
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new HashSet<>()).add(new RenderCall(vertexArray, vertexAttributeState));
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new ArrayList<>()).add(new RenderCall(vertexArray, vertexAttributeState));
}

public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
Expand All @@ -29,7 +32,7 @@ public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
}
}

private static void drawBatch(Map<MaterialProperties, Set<RenderCall>> batches, ShaderManager shaderManager) {
private static void drawBatch(Map<MaterialProperties, List<RenderCall>> batches, ShaderManager shaderManager) {
batches.forEach((materialProperties, renderCalls) -> {
shaderManager.setupShaderBatchState(materialProperties);
renderCalls.forEach(RenderCall::draw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import org.mtr.mapping.render.shader.ShaderManager;
import org.mtr.mapping.render.vertex.VertexAttributeState;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BatchManager {

private final Map<MaterialProperties, Set<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, Set<RenderCall>> translucentBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> opaqueBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> cutoutBatches = new HashMap<>();
private final Map<MaterialProperties, List<RenderCall>> translucentBatches = new HashMap<>();

public void queue(List<VertexArray> vertexArrays, VertexAttributeState vertexAttributeState) {
vertexArrays.forEach(vertexArray -> queue(vertexArray, vertexAttributeState));
}

public void queue(VertexArray vertexArray, VertexAttributeState vertexAttributeState) {
final MaterialProperties materialProperties = vertexArray.materialProperties;
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new HashSet<>()).add(new RenderCall(vertexArray, vertexAttributeState));
(materialProperties.translucent ? translucentBatches : materialProperties.cutoutHack ? cutoutBatches : opaqueBatches).computeIfAbsent(materialProperties, key -> new ArrayList<>()).add(new RenderCall(vertexArray, vertexAttributeState));
}

public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
Expand All @@ -29,7 +32,7 @@ public void drawAll(ShaderManager shaderManager, boolean renderTranslucent) {
}
}

private static void drawBatch(Map<MaterialProperties, Set<RenderCall>> batches, ShaderManager shaderManager) {
private static void drawBatch(Map<MaterialProperties, List<RenderCall>> batches, ShaderManager shaderManager) {
batches.forEach((materialProperties, renderCalls) -> {
shaderManager.setupShaderBatchState(materialProperties);
renderCalls.forEach(RenderCall::draw);
Expand Down
Loading

0 comments on commit 16f5293

Please sign in to comment.