wip: massive performance improvements (rendering)

This commit is contained in:
Bixilon 2020-09-28 23:33:11 +02:00
parent 6ae472a36d
commit 1fd57b8f52
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 17 additions and 30 deletions

View File

@ -20,20 +20,23 @@ import de.bixilon.minosoft.render.blockModels.Face.Face;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
import javafx.util.Pair;
import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import static de.bixilon.minosoft.render.blockModels.Face.RenderConstants.faceDir;
import static org.lwjgl.opengl.GL11.*;
public class WorldRenderer {
private final HashMap<BlockPosition, HashSet<Face>> faces;
private final ConcurrentHashMap<BlockPosition, HashSet<Face>> faces;
private AssetsLoader assetsLoader;
private LinkedBlockingQueue<Pair<ChunkLocation, Chunk>> queuedChunks;
public WorldRenderer() {
faces = new HashMap<>();
faces = new ConcurrentHashMap<>();
}
public void init() {
@ -85,12 +88,12 @@ public class WorldRenderer {
public void prepareBlock(BlockPosition position, Block block) {
if (block.equals(Blocks.nullBlock)) {
faces.put(position, null);
return;
}
HashMap<FaceOrientation, Boolean> adjacentBlocks = new HashMap<>();
for (FaceOrientation orientation : FaceOrientation.values()) {
BlockPosition neighbourPos = position.add(faceDir[orientation.getId()]);
BlockPosition neighbourPos = position.add(faceDir[orientation.ordinal()]);
if (neighbourPos.getY() >= 0 && neighbourPos.getY() <= 255) {
Block neighbourBlock = GameWindow.getConnection().getPlayer().getWorld().getBlock(neighbourPos);
@ -100,22 +103,14 @@ public class WorldRenderer {
adjacentBlocks.put(orientation, false);
}
}
synchronized (faces) {
faces.put(position, assetsLoader.getBlockModelLoader().prepare(block, adjacentBlocks));
}
}
public void draw() {
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, assetsLoader.getTextureLoader().getTextureID());
glBegin(GL_QUADS);
synchronized (faces) {
for (Map.Entry<BlockPosition, HashSet<Face>> entry : faces.entrySet()) {
for (Face face : entry.getValue()) {
face.draw(entry.getKey());
}
}
}
faces.forEach(((position, faces) -> faces.forEach((face) -> face.draw(position))));
glEnd();
}

View File

@ -23,7 +23,6 @@ import de.bixilon.minosoft.render.blockModels.specialModels.*;
import de.bixilon.minosoft.render.texture.TextureLoader;
import org.apache.commons.collections.primitives.ArrayFloatList;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
@ -123,14 +122,11 @@ public class BlockModelLoader {
public BlockModelInterface getBlockDescription(Block block) {
HashMap<String, BlockModelInterface> modList = blockDescriptionMap.get(block.getMod());
if (modList == null || !modList.containsKey(block.getIdentifier())) {
throw new IllegalArgumentException(String.format("No block %s:%s found", block.getMod(), block.getIdentifier()));
}
return modList.get(block.getIdentifier());
}
public boolean isFull(Block block) {
if (block == Blocks.nullBlock || block == null) {
if (block == null || block.equals(Blocks.nullBlock)) {
return false;
}
BlockModelInterface description = getBlockDescription(block);

View File

@ -14,14 +14,10 @@
package de.bixilon.minosoft.render.blockModels.Face;
public enum FaceOrientation {
EAST(0), WEST(1), UP(2), DOWN(3), SOUTH(4), NORTH(5);
private final int id;
FaceOrientation(int id) {
this.id = id;
}
public int getId() {
return this.id;
}
EAST,
WEST,
UP,
DOWN,
SOUTH,
NORTH
}