mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 09:26:11 -04:00
render: wip: improve code style
This commit is contained in:
parent
f080432749
commit
f7c76b382d
@ -85,6 +85,9 @@ public class MainWindow implements Initializable {
|
||||
}
|
||||
|
||||
public static void selectAccount() {
|
||||
if (menuAccount2 == null) {
|
||||
return;
|
||||
}
|
||||
if (Minosoft.getSelectedAccount() != null) {
|
||||
menuAccount2.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_ACCOUNTS_SELECTED, Minosoft.getSelectedAccount().getPlayerName()));
|
||||
} else {
|
||||
|
@ -21,7 +21,7 @@ import static org.lwjgl.glfw.GLFW.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class GameWindow {
|
||||
private static final float FOVY = 45f;
|
||||
private static final float FOV_Y = 45f;
|
||||
private static final int WIDTH = 800;
|
||||
private static final int HEIGHT = 800;
|
||||
private static final boolean FULLSCREEN = false;
|
||||
@ -30,21 +30,21 @@ public class GameWindow {
|
||||
private static WorldRenderer renderer;
|
||||
private static Connection connection;
|
||||
private static PlayerController playerController;
|
||||
private static boolean running = false;
|
||||
|
||||
public static void prepare() {
|
||||
new Thread(() -> {
|
||||
Log.debug("Starting render preparations...");
|
||||
openGLWindow = new OpenGLWindow(WIDTH, HEIGHT, FULLSCREEN);
|
||||
playerController = new PlayerController(openGLWindow.getWindow());
|
||||
playerController = new PlayerController(openGLWindow.getWindowId());
|
||||
openGLWindow.init();
|
||||
renderer = new WorldRenderer();
|
||||
renderer.init();
|
||||
Log.info("Finished loading game Assets");
|
||||
Log.debug("Render preparations done.");
|
||||
try {
|
||||
while (!running) {
|
||||
while (connection == null) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
openGLWindow.start();
|
||||
Log.debug("Render window preparations done.");
|
||||
mainLoop();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
@ -53,7 +53,7 @@ public class GameWindow {
|
||||
}
|
||||
|
||||
private static void mainLoop() {
|
||||
while (!glfwWindowShouldClose(openGLWindow.getWindow())) {
|
||||
while (!glfwWindowShouldClose(openGLWindow.getWindowId())) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glLoadIdentity();
|
||||
glfwPollEvents();
|
||||
@ -65,13 +65,11 @@ public class GameWindow {
|
||||
glColor4f(1f, 1f, 1f, 1f);
|
||||
}
|
||||
|
||||
OpenGLWindow.gluPerspective(FOVY, (float) WIDTH / (float) HEIGHT, 0.1f, 500f);
|
||||
OpenGLWindow.gluPerspective(FOV_Y, WIDTH / (float) HEIGHT, 0.1f, 500f);
|
||||
playerController.loop(deltaTime);
|
||||
if (connection != null && connection.getPlayer().isSpawnConfirmed()) {
|
||||
renderer.draw();
|
||||
}
|
||||
renderer.draw();
|
||||
glPopMatrix();
|
||||
glfwSwapBuffers(openGLWindow.getWindow());
|
||||
glfwSwapBuffers(openGLWindow.getWindowId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,12 +86,11 @@ public class GameWindow {
|
||||
}
|
||||
|
||||
public static void start(Connection connection) {
|
||||
if (running) {
|
||||
if (GameWindow.connection != null) {
|
||||
return;
|
||||
}
|
||||
GameWindow.connection = connection;
|
||||
running = true;
|
||||
playerController = new PlayerController(openGLWindow.getWindow());
|
||||
playerController = new PlayerController(openGLWindow.getWindowId());
|
||||
renderer.startChunkPreparation(connection);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Lukas Eisenhauer
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -29,7 +29,7 @@ import static org.lwjgl.system.MemoryUtil.NULL;
|
||||
public class OpenGLWindow {
|
||||
private final boolean fullscreen;
|
||||
boolean escDown = false;
|
||||
private long window;
|
||||
private long windowId;
|
||||
private int width, height;
|
||||
private double mouseX;
|
||||
private double mouseY;
|
||||
@ -41,8 +41,8 @@ public class OpenGLWindow {
|
||||
this.fullscreen = fullscreen;
|
||||
}
|
||||
|
||||
public static void gluPerspective(float fovy, float aspect, float near, float far) {
|
||||
float bottom = -near * (float) Math.tan(fovy / 2);
|
||||
public static void gluPerspective(float fovY, float aspect, float near, float far) {
|
||||
float bottom = -near * (float) Math.tan(fovY / 2);
|
||||
float top = -bottom;
|
||||
float left = aspect * bottom;
|
||||
float right = -left;
|
||||
@ -67,8 +67,8 @@ public class OpenGLWindow {
|
||||
height = mode.height();
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(width, height, "RENDER", NULL, NULL);
|
||||
if (window == NULL) {
|
||||
windowId = glfwCreateWindow(width, height, "RENDER", NULL, NULL);
|
||||
if (windowId == NULL) {
|
||||
throw new RuntimeException("Failed to create the GLFW window");
|
||||
}
|
||||
|
||||
@ -76,19 +76,19 @@ public class OpenGLWindow {
|
||||
IntBuffer pWidth = stack.mallocInt(1); // int*
|
||||
IntBuffer pHeight = stack.mallocInt(1); // int*
|
||||
|
||||
glfwGetWindowSize(window, pWidth, pHeight);
|
||||
glfwGetWindowSize(windowId, pWidth, pHeight);
|
||||
|
||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
|
||||
glfwSetWindowPos(window, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2);
|
||||
glfwSetWindowPos(windowId, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2);
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwMakeContextCurrent(windowId);
|
||||
|
||||
glfwSetCursorPosCallback(window, new GLFWCursorPosCallback() {
|
||||
glfwSetCursorPosCallback(windowId, new GLFWCursorPosCallback() {
|
||||
@Override
|
||||
public void invoke(long window, double xpos, double ypos) {
|
||||
mouseX = xpos;
|
||||
mouseY = ypos;
|
||||
public void invoke(long windowId, double xPos, double yPos) {
|
||||
mouseX = xPos;
|
||||
mouseY = yPos;
|
||||
}
|
||||
});
|
||||
|
||||
@ -117,8 +117,8 @@ public class OpenGLWindow {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
public long getWindow() {
|
||||
return window;
|
||||
public long getWindowId() {
|
||||
return windowId;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
@ -138,7 +138,7 @@ public class OpenGLWindow {
|
||||
}
|
||||
|
||||
public float loop() {
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||
if (glfwGetKey(windowId, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||
if (!escDown) {
|
||||
GameWindow.pause();
|
||||
escDown = true;
|
||||
@ -154,15 +154,15 @@ public class OpenGLWindow {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
glfwSetCursorPosCallback(window, GameWindow.getPlayerController().getCameraMovement()::mouseCallback);
|
||||
glfwShowWindow(window);
|
||||
glfwSetCursorPosCallback(windowId, GameWindow.getPlayerController().getCameraMovement()::mouseCallback);
|
||||
glfwShowWindow(windowId);
|
||||
}
|
||||
|
||||
public void mouseEnable(boolean mouse) {
|
||||
if (mouse) {
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
} else {
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
glfwSetInputMode(windowId, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
return;
|
||||
}
|
||||
glfwSetInputMode(windowId, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
}
|
||||
|
@ -29,22 +29,13 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class WorldRenderer {
|
||||
private final ConcurrentHashMap<ChunkLocation, ConcurrentHashMap<Byte, ArrayFloatList>> faces;
|
||||
private BlockModelLoader modelLoader;
|
||||
private final ConcurrentHashMap<ChunkLocation, ConcurrentHashMap<Byte, ArrayFloatList>> faces = new ConcurrentHashMap<>();
|
||||
private final BlockModelLoader modelLoader = new BlockModelLoader();
|
||||
|
||||
private LinkedBlockingQueue<Runnable> queuedMapData;
|
||||
|
||||
public WorldRenderer() {
|
||||
faces = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
queuedMapData = new LinkedBlockingQueue<>();
|
||||
modelLoader = new BlockModelLoader();
|
||||
}
|
||||
private final LinkedBlockingQueue<Runnable> queuedMapData = new LinkedBlockingQueue<>();
|
||||
|
||||
public void startChunkPreparation(Connection connection) {
|
||||
Thread chunkLoadThread = new Thread(() -> {
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
queuedMapData.take().run();
|
||||
@ -53,9 +44,7 @@ public class WorldRenderer {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
chunkLoadThread.setName(String.format("%d/ChunkLoading", connection.getConnectionId()));
|
||||
chunkLoadThread.start();
|
||||
}, String.format("%d/ChunkLoading", connection.getConnectionId())).start();
|
||||
}
|
||||
|
||||
public void queueChunkBulk(HashMap<ChunkLocation, Chunk> chunks) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user