Moved window to second thread.

This commit is contained in:
lieght
2025-09-13 13:51:13 +02:00
parent 1df97f990c
commit c6bdbae46c
2 changed files with 25 additions and 13 deletions

View File

@@ -16,8 +16,8 @@ public class Main {
throw new RuntimeException("A event could not be initialized");
}
Server.start("local", "127.0.0.1", "5001");
Window.start();
Server.start("remote", "127.0.0.1", "5001");
Window.start("");
}
@@ -26,22 +26,25 @@ public class Main {
*/
private static boolean initEvents() {
try {
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerBackend.class, e ->
logger.info("Changing server backend state to {}", e.backend())
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerBackend.class,
event ->
logger.info("Changing server backend state to {}", event.backend())
);
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerIp.class, e ->
logger.info("Changing server ip to {}", e.ip())
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerIp.class,
event ->
logger.info("Changing server ip to {}", event.ip())
);
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerPort.class, e ->
logger.info("Changing server port to {}", e.port())
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerPort.class,
event ->
logger.info("Changing server port to {}", event.port())
);
return true;
}
catch (Exception e) {
logger.info("{}", e.getMessage());
catch (Exception err) {
logger.info("{}", err.getMessage());
return false;
}
}

View File

@@ -1,5 +1,7 @@
package org.toop;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
@@ -14,8 +16,9 @@ import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.stb.STBImage.*;
public class Window {
public class Window extends Thread {
private static final Logger logger = LogManager.getLogger(Main.class);
// The window handle
private long window;
@@ -148,8 +151,14 @@ public class Window {
//public static void main(String[] args) {
//new Window().run();
//}
public static void start(){
new Window().run();
/**
* TODO: Is putting the window on a second thread, safe?
* Can't overwrite start(), so a overload is needed.
*
* @param ignoredKeepEmpty Just input "" an empty string.
*/
public static void start(String ignoredKeepEmpty){
new Window().start();
}
}