mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
add: own branch
This commit is contained in:
@@ -1,54 +1,55 @@
|
||||
package org.toop;
|
||||
|
||||
import org.toop.eventbus.Events;
|
||||
import org.toop.eventbus.GlobalEventBus;
|
||||
import org.toop.server.Server;
|
||||
import org.toop.server.backend.Testsss;
|
||||
import org.toop.server.backend.TcpServer;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.toop.core.*;
|
||||
import org.toop.eventbus.*;
|
||||
import org.toop.graphics.*;
|
||||
|
||||
public class Main {
|
||||
private static final Logger logger = LogManager.getLogger(Main.class);
|
||||
private static boolean running = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) {
|
||||
registerEvents();
|
||||
|
||||
if (!initEvents()) {
|
||||
throw new RuntimeException("A event could not be initialized");
|
||||
}
|
||||
Window window = Window.setup(Window.API.GLFW, "Test", new Window.Size(1280, 720));
|
||||
Renderer renderer = Renderer.setup(Renderer.API.OPENGL);
|
||||
|
||||
TcpServer server = new TcpServer(5001);
|
||||
Thread serverThread = new Thread(server);
|
||||
serverThread.start();
|
||||
Server.start("127.0.0.1", "5001");
|
||||
// Testsss.start(""); // Used for testing server.
|
||||
Window.start("");
|
||||
Shader shader = Shader.create(
|
||||
"src/main/resources/shaders/gui_vertex.glsl",
|
||||
"src/main/resources/shaders/gui_fragment.glsl");
|
||||
|
||||
}
|
||||
running = window != null && renderer != null && shader != null;
|
||||
|
||||
/**
|
||||
* Returns false if any event could not be initialized.
|
||||
*/
|
||||
private static boolean initEvents() {
|
||||
try {
|
||||
while (running) {
|
||||
window.update();
|
||||
renderer.clear();
|
||||
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerIp.class,
|
||||
event ->
|
||||
logger.info("Changing server ip to {}", event.ip())
|
||||
);
|
||||
shader.start();
|
||||
renderer.render();
|
||||
}
|
||||
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerPort.class,
|
||||
event ->
|
||||
logger.info("Changing server port to {}", event.port())
|
||||
);
|
||||
if (shader != null) shader.cleanup();
|
||||
if (renderer != null) renderer.cleanup();
|
||||
if (window != null) window.cleanup();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception err) {
|
||||
logger.info("{}", err.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static void registerEvents() {
|
||||
GlobalEventBus.subscribeAndRegister(Events.WindowEvents.OnQuitRequested.class, event -> {
|
||||
quit();
|
||||
});
|
||||
|
||||
}
|
||||
GlobalEventBus.subscribeAndRegister(Events.WindowEvents.OnMouseMove.class, event -> {
|
||||
});
|
||||
}
|
||||
|
||||
private static void quit() {
|
||||
running = false;
|
||||
}
|
||||
|
||||
public static boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
public static void setRunning(boolean running) {
|
||||
Main.running = running;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user