mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
rendering: only start preparing faces once connected
This commit is contained in:
parent
6998160853
commit
7321dceefc
@ -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() {
|
||||
|
@ -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<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();
|
||||
assetsLoader = new AssetsLoader();
|
||||
}
|
||||
|
||||
public void queueChunkBulk(HashMap<ChunkLocation, Chunk> 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<ChunkNibbleLocation, HashSet<Face>> nibbleMap = new ConcurrentHashMap<>();
|
||||
faces.get(chunkLocation).put(height, nibbleMap);
|
||||
int xOffset = chunkLocation.getX() * 16;
|
||||
int zOffset = chunkLocation.getZ() * 16;
|
||||
HashMap<ChunkNibbleLocation, Block> nibbleBlocks = nibble.getBlocks();
|
||||
nibbleBlocks.forEach((location, block) -> {
|
||||
HashSet<FaceOrientation> facesToDraw = new HashSet<>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user