From 7321dceefc158c12a41ca34c0833b90768dc2092 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Tue, 29 Sep 2020 17:03:18 +0200 Subject: [PATCH] rendering: only start preparing faces once connected --- .../bixilon/minosoft/render/GameWindow.java | 9 ++++---- .../minosoft/render/WorldRenderer.java | 23 ++++++------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/render/GameWindow.java b/src/main/java/de/bixilon/minosoft/render/GameWindow.java index 5e4391447..e3eeabd6f 100644 --- a/src/main/java/de/bixilon/minosoft/render/GameWindow.java +++ b/src/main/java/de/bixilon/minosoft/render/GameWindow.java @@ -21,10 +21,10 @@ import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.opengl.GL11.*; public class GameWindow { - private static float FOVY = 45f; - private static int WIDTH = 800; - private static int HEIGHT = 800; - private static boolean FULLSCREEN = false; + private static final float FOVY = 45f; + private static final int WIDTH = 800; + private static final int HEIGHT = 800; + private static final boolean FULLSCREEN = false; private static OpenGLWindow openGLWindow; private static WorldRenderer renderer; private static Connection connection; @@ -97,6 +97,7 @@ public class GameWindow { GameWindow.connection = connection; running = true; playerController = new PlayerController(openGLWindow.getWindow()); + renderer.startChunkPreparation(connection); } public static void pause() { diff --git a/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java b/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java index de0d6f566..4af617faa 100644 --- a/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java +++ b/src/main/java/de/bixilon/minosoft/render/WorldRenderer.java @@ -15,6 +15,7 @@ package de.bixilon.minosoft.render; import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block; import de.bixilon.minosoft.game.datatypes.world.*; +import de.bixilon.minosoft.protocol.network.Connection; import de.bixilon.minosoft.render.blockModels.Face.Face; import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; import javafx.util.Pair; @@ -35,14 +36,11 @@ public class WorldRenderer { public void init() { queuedChunks = new LinkedBlockingQueue<>(); + assetsLoader = new AssetsLoader(); + } + + public void startChunkPreparation(Connection connection) { Thread chunkLoadThread = new Thread(() -> { - while (GameWindow.getConnection() == null) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } while (true) { try { Pair current = queuedChunks.take(); @@ -52,9 +50,8 @@ public class WorldRenderer { } } }); - chunkLoadThread.setName(String.format("%d/ChunkLoading", 0)); // TODO: connection ID + chunkLoadThread.setName(String.format("%d/ChunkLoading", connection.getConnectionId())); chunkLoadThread.start(); - assetsLoader = new AssetsLoader(); } public void queueChunkBulk(HashMap chunks) { @@ -68,19 +65,13 @@ public class WorldRenderer { public void prepareChunk(ChunkLocation location, Chunk chunk) { // clear or create current chunk faces.put(location, new ConcurrentHashMap<>()); - int xOffset = location.getX() * 16; - int zOffset = location.getZ() * 16; - chunk.getNibbles().forEach(((height, chunkNibble) -> { - prepareChunkNibble(location, height, chunkNibble); - })); + chunk.getNibbles().forEach(((height, chunkNibble) -> prepareChunkNibble(location, height, chunkNibble))); } public void prepareChunkNibble(ChunkLocation chunkLocation, byte height, ChunkNibble nibble) { // clear or create current chunk nibble ConcurrentHashMap> nibbleMap = new ConcurrentHashMap<>(); faces.get(chunkLocation).put(height, nibbleMap); - int xOffset = chunkLocation.getX() * 16; - int zOffset = chunkLocation.getZ() * 16; HashMap nibbleBlocks = nibble.getBlocks(); nibbleBlocks.forEach((location, block) -> { HashSet facesToDraw = new HashSet<>();