mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 17:37:58 -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() {
|
public static void selectAccount() {
|
||||||
|
if (menuAccount2 == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Minosoft.getSelectedAccount() != null) {
|
if (Minosoft.getSelectedAccount() != null) {
|
||||||
menuAccount2.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_ACCOUNTS_SELECTED, Minosoft.getSelectedAccount().getPlayerName()));
|
menuAccount2.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_ACCOUNTS_SELECTED, Minosoft.getSelectedAccount().getPlayerName()));
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,7 +21,7 @@ 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 final float FOVY = 45f;
|
private static final float FOV_Y = 45f;
|
||||||
private static final int WIDTH = 800;
|
private static final int WIDTH = 800;
|
||||||
private static final int HEIGHT = 800;
|
private static final int HEIGHT = 800;
|
||||||
private static final boolean FULLSCREEN = false;
|
private static final boolean FULLSCREEN = false;
|
||||||
@ -30,21 +30,21 @@ public class GameWindow {
|
|||||||
private static WorldRenderer renderer;
|
private static WorldRenderer renderer;
|
||||||
private static Connection connection;
|
private static Connection connection;
|
||||||
private static PlayerController playerController;
|
private static PlayerController playerController;
|
||||||
private static boolean running = false;
|
|
||||||
|
|
||||||
public static void prepare() {
|
public static void prepare() {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
Log.debug("Starting render preparations...");
|
||||||
openGLWindow = new OpenGLWindow(WIDTH, HEIGHT, FULLSCREEN);
|
openGLWindow = new OpenGLWindow(WIDTH, HEIGHT, FULLSCREEN);
|
||||||
playerController = new PlayerController(openGLWindow.getWindow());
|
playerController = new PlayerController(openGLWindow.getWindowId());
|
||||||
openGLWindow.init();
|
openGLWindow.init();
|
||||||
renderer = new WorldRenderer();
|
renderer = new WorldRenderer();
|
||||||
renderer.init();
|
Log.debug("Render preparations done.");
|
||||||
Log.info("Finished loading game Assets");
|
|
||||||
try {
|
try {
|
||||||
while (!running) {
|
while (connection == null) {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
openGLWindow.start();
|
openGLWindow.start();
|
||||||
|
Log.debug("Render window preparations done.");
|
||||||
mainLoop();
|
mainLoop();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -53,7 +53,7 @@ public class GameWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void mainLoop() {
|
private static void mainLoop() {
|
||||||
while (!glfwWindowShouldClose(openGLWindow.getWindow())) {
|
while (!glfwWindowShouldClose(openGLWindow.getWindowId())) {
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
@ -65,13 +65,11 @@ public class GameWindow {
|
|||||||
glColor4f(1f, 1f, 1f, 1f);
|
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);
|
playerController.loop(deltaTime);
|
||||||
if (connection != null && connection.getPlayer().isSpawnConfirmed()) {
|
|
||||||
renderer.draw();
|
renderer.draw();
|
||||||
}
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glfwSwapBuffers(openGLWindow.getWindow());
|
glfwSwapBuffers(openGLWindow.getWindowId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +86,11 @@ public class GameWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void start(Connection connection) {
|
public static void start(Connection connection) {
|
||||||
if (running) {
|
if (GameWindow.connection != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GameWindow.connection = connection;
|
GameWindow.connection = connection;
|
||||||
running = true;
|
playerController = new PlayerController(openGLWindow.getWindowId());
|
||||||
playerController = new PlayerController(openGLWindow.getWindow());
|
|
||||||
renderer.startChunkPreparation(connection);
|
renderer.startChunkPreparation(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Codename Minosoft
|
* 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.
|
* 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 {
|
public class OpenGLWindow {
|
||||||
private final boolean fullscreen;
|
private final boolean fullscreen;
|
||||||
boolean escDown = false;
|
boolean escDown = false;
|
||||||
private long window;
|
private long windowId;
|
||||||
private int width, height;
|
private int width, height;
|
||||||
private double mouseX;
|
private double mouseX;
|
||||||
private double mouseY;
|
private double mouseY;
|
||||||
@ -41,8 +41,8 @@ public class OpenGLWindow {
|
|||||||
this.fullscreen = fullscreen;
|
this.fullscreen = fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void gluPerspective(float fovy, float aspect, float near, float far) {
|
public static void gluPerspective(float fovY, float aspect, float near, float far) {
|
||||||
float bottom = -near * (float) Math.tan(fovy / 2);
|
float bottom = -near * (float) Math.tan(fovY / 2);
|
||||||
float top = -bottom;
|
float top = -bottom;
|
||||||
float left = aspect * bottom;
|
float left = aspect * bottom;
|
||||||
float right = -left;
|
float right = -left;
|
||||||
@ -67,8 +67,8 @@ public class OpenGLWindow {
|
|||||||
height = mode.height();
|
height = mode.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwCreateWindow(width, height, "RENDER", NULL, NULL);
|
windowId = glfwCreateWindow(width, height, "RENDER", NULL, NULL);
|
||||||
if (window == NULL) {
|
if (windowId == NULL) {
|
||||||
throw new RuntimeException("Failed to create the GLFW window");
|
throw new RuntimeException("Failed to create the GLFW window");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,19 +76,19 @@ public class OpenGLWindow {
|
|||||||
IntBuffer pWidth = stack.mallocInt(1); // int*
|
IntBuffer pWidth = stack.mallocInt(1); // int*
|
||||||
IntBuffer pHeight = stack.mallocInt(1); // int*
|
IntBuffer pHeight = stack.mallocInt(1); // int*
|
||||||
|
|
||||||
glfwGetWindowSize(window, pWidth, pHeight);
|
glfwGetWindowSize(windowId, pWidth, pHeight);
|
||||||
|
|
||||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
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
|
@Override
|
||||||
public void invoke(long window, double xpos, double ypos) {
|
public void invoke(long windowId, double xPos, double yPos) {
|
||||||
mouseX = xpos;
|
mouseX = xPos;
|
||||||
mouseY = ypos;
|
mouseY = yPos;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -117,8 +117,8 @@ public class OpenGLWindow {
|
|||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getWindow() {
|
public long getWindowId() {
|
||||||
return window;
|
return windowId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
@ -138,7 +138,7 @@ public class OpenGLWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float loop() {
|
public float loop() {
|
||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
if (glfwGetKey(windowId, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||||
if (!escDown) {
|
if (!escDown) {
|
||||||
GameWindow.pause();
|
GameWindow.pause();
|
||||||
escDown = true;
|
escDown = true;
|
||||||
@ -154,15 +154,15 @@ public class OpenGLWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
glfwSetCursorPosCallback(window, GameWindow.getPlayerController().getCameraMovement()::mouseCallback);
|
glfwSetCursorPosCallback(windowId, GameWindow.getPlayerController().getCameraMovement()::mouseCallback);
|
||||||
glfwShowWindow(window);
|
glfwShowWindow(windowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mouseEnable(boolean mouse) {
|
public void mouseEnable(boolean mouse) {
|
||||||
if (mouse) {
|
if (mouse) {
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(windowId, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
} else {
|
return;
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
}
|
||||||
}
|
glfwSetInputMode(windowId, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,22 +29,13 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
public class WorldRenderer {
|
public class WorldRenderer {
|
||||||
private final ConcurrentHashMap<ChunkLocation, ConcurrentHashMap<Byte, ArrayFloatList>> faces;
|
private final ConcurrentHashMap<ChunkLocation, ConcurrentHashMap<Byte, ArrayFloatList>> faces = new ConcurrentHashMap<>();
|
||||||
private BlockModelLoader modelLoader;
|
private final BlockModelLoader modelLoader = new BlockModelLoader();
|
||||||
|
|
||||||
private LinkedBlockingQueue<Runnable> queuedMapData;
|
private final LinkedBlockingQueue<Runnable> queuedMapData = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
public WorldRenderer() {
|
|
||||||
faces = new ConcurrentHashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init() {
|
|
||||||
queuedMapData = new LinkedBlockingQueue<>();
|
|
||||||
modelLoader = new BlockModelLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startChunkPreparation(Connection connection) {
|
public void startChunkPreparation(Connection connection) {
|
||||||
Thread chunkLoadThread = new Thread(() -> {
|
new Thread(() -> {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
queuedMapData.take().run();
|
queuedMapData.take().run();
|
||||||
@ -53,9 +44,7 @@ public class WorldRenderer {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}, String.format("%d/ChunkLoading", connection.getConnectionId())).start();
|
||||||
chunkLoadThread.setName(String.format("%d/ChunkLoading", connection.getConnectionId()));
|
|
||||||
chunkLoadThread.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void queueChunkBulk(HashMap<ChunkLocation, Chunk> chunks) {
|
public void queueChunkBulk(HashMap<ChunkLocation, Chunk> chunks) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user