rendering: only start preparing faces once connected

This commit is contained in:
Bixilon 2020-09-29 17:03:18 +02:00
parent 6998160853
commit 7321dceefc
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 12 additions and 20 deletions

View File

@ -21,10 +21,10 @@ import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
public class GameWindow { public class GameWindow {
private static float FOVY = 45f; private static final float FOVY = 45f;
private static int WIDTH = 800; private static final int WIDTH = 800;
private static int HEIGHT = 800; private static final int HEIGHT = 800;
private static boolean FULLSCREEN = false; private static final boolean FULLSCREEN = false;
private static OpenGLWindow openGLWindow; private static OpenGLWindow openGLWindow;
private static WorldRenderer renderer; private static WorldRenderer renderer;
private static Connection connection; private static Connection connection;
@ -97,6 +97,7 @@ public class GameWindow {
GameWindow.connection = connection; GameWindow.connection = connection;
running = true; running = true;
playerController = new PlayerController(openGLWindow.getWindow()); playerController = new PlayerController(openGLWindow.getWindow());
renderer.startChunkPreparation(connection);
} }
public static void pause() { public static void pause() {

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.render;
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block; import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
import de.bixilon.minosoft.game.datatypes.world.*; 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.Face;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation; import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
import javafx.util.Pair; import javafx.util.Pair;
@ -35,14 +36,11 @@ public class WorldRenderer {
public void init() { public void init() {
queuedChunks = new LinkedBlockingQueue<>(); queuedChunks = new LinkedBlockingQueue<>();
assetsLoader = new AssetsLoader();
}
public void startChunkPreparation(Connection connection) {
Thread chunkLoadThread = new Thread(() -> { Thread chunkLoadThread = new Thread(() -> {
while (GameWindow.getConnection() == null) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
while (true) { while (true) {
try { try {
Pair<ChunkLocation, Chunk> current = queuedChunks.take(); Pair<ChunkLocation, Chunk> 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(); chunkLoadThread.start();
assetsLoader = new AssetsLoader();
} }
public void queueChunkBulk(HashMap<ChunkLocation, Chunk> chunks) { public void queueChunkBulk(HashMap<ChunkLocation, Chunk> chunks) {
@ -68,19 +65,13 @@ public class WorldRenderer {
public void prepareChunk(ChunkLocation location, Chunk chunk) { public void prepareChunk(ChunkLocation location, Chunk chunk) {
// clear or create current chunk // clear or create current chunk
faces.put(location, new ConcurrentHashMap<>()); faces.put(location, new ConcurrentHashMap<>());
int xOffset = location.getX() * 16; chunk.getNibbles().forEach(((height, chunkNibble) -> prepareChunkNibble(location, height, chunkNibble)));
int zOffset = location.getZ() * 16;
chunk.getNibbles().forEach(((height, chunkNibble) -> {
prepareChunkNibble(location, height, chunkNibble);
}));
} }
public void prepareChunkNibble(ChunkLocation chunkLocation, byte height, ChunkNibble nibble) { public void prepareChunkNibble(ChunkLocation chunkLocation, byte height, ChunkNibble nibble) {
// clear or create current chunk nibble // clear or create current chunk nibble
ConcurrentHashMap<ChunkNibbleLocation, HashSet<Face>> nibbleMap = new ConcurrentHashMap<>(); ConcurrentHashMap<ChunkNibbleLocation, HashSet<Face>> nibbleMap = new ConcurrentHashMap<>();
faces.get(chunkLocation).put(height, nibbleMap); faces.get(chunkLocation).put(height, nibbleMap);
int xOffset = chunkLocation.getX() * 16;
int zOffset = chunkLocation.getZ() * 16;
HashMap<ChunkNibbleLocation, Block> nibbleBlocks = nibble.getBlocks(); HashMap<ChunkNibbleLocation, Block> nibbleBlocks = nibble.getBlocks();
nibbleBlocks.forEach((location, block) -> { nibbleBlocks.forEach((location, block) -> {
HashSet<FaceOrientation> facesToDraw = new HashSet<>(); HashSet<FaceOrientation> facesToDraw = new HashSet<>();