This commit is contained in:
lieght
2025-12-07 20:33:27 +01:00
parent 80d3e47ad9
commit 12bccb8854

View File

@@ -127,9 +127,14 @@ public final class App extends Application {
}, false, "init_loading");
// Start loading assets
new Thread(() -> ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets")))
.start();
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
executor.submit(
() -> ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets")
));
} finally {
executor.shutdown();
}
stage.show();
@@ -164,7 +169,13 @@ public final class App extends Application {
private void setOnLoadingSuccess(LoadingWidget loading) {
loading.setOnSuccess(() -> {
try {
initSystems();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
AppSettings.applyMusicVolumeSettings();
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).postEvent();
loading.hide();
@@ -182,12 +193,16 @@ public final class App extends Application {
});
}
private void initSystems() { // TODO Move to better place
private void initSystems() throws InterruptedException { // TODO Move to better place
final int THREAD_COUNT = 2;
CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
@SuppressWarnings("resource")
ExecutorService threads = Executors.newFixedThreadPool(THREAD_COUNT);
try {
threads.submit(() -> {
new NetworkingClientEventListener(
GlobalEventBus.get(),
@@ -223,10 +238,9 @@ public final class App extends Application {
latch.countDown();
});
try {
} finally {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
threads.shutdown();
}
}