mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Safety
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user