mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Safety
This commit is contained in:
@@ -127,9 +127,14 @@ public final class App extends Application {
|
|||||||
|
|
||||||
}, false, "init_loading");
|
}, false, "init_loading");
|
||||||
|
|
||||||
// Start loading assets
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
new Thread(() -> ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets")))
|
try {
|
||||||
.start();
|
executor.submit(
|
||||||
|
() -> ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets")
|
||||||
|
));
|
||||||
|
} finally {
|
||||||
|
executor.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
stage.show();
|
stage.show();
|
||||||
|
|
||||||
@@ -164,8 +169,14 @@ public final class App extends Application {
|
|||||||
|
|
||||||
private void setOnLoadingSuccess(LoadingWidget loading) {
|
private void setOnLoadingSuccess(LoadingWidget loading) {
|
||||||
loading.setOnSuccess(() -> {
|
loading.setOnSuccess(() -> {
|
||||||
initSystems();
|
|
||||||
AppSettings.applyMusicVolumeSettings();
|
try {
|
||||||
|
initSystems();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
AppSettings.applyMusicVolumeSettings();
|
||||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).postEvent();
|
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).postEvent();
|
||||||
loading.hide();
|
loading.hide();
|
||||||
WidgetContainer.add(Pos.CENTER, new MainView());
|
WidgetContainer.add(Pos.CENTER, new MainView());
|
||||||
@@ -182,52 +193,55 @@ 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;
|
final int THREAD_COUNT = 2;
|
||||||
CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
|
CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
|
||||||
|
|
||||||
|
@SuppressWarnings("resource")
|
||||||
ExecutorService threads = Executors.newFixedThreadPool(THREAD_COUNT);
|
ExecutorService threads = Executors.newFixedThreadPool(THREAD_COUNT);
|
||||||
|
|
||||||
threads.submit(() -> {
|
try {
|
||||||
new NetworkingClientEventListener(
|
|
||||||
GlobalEventBus.get(),
|
|
||||||
new NetworkingClientManager(GlobalEventBus.get()));
|
|
||||||
|
|
||||||
latch.countDown();
|
threads.submit(() -> {
|
||||||
});
|
new NetworkingClientEventListener(
|
||||||
|
GlobalEventBus.get(),
|
||||||
|
new NetworkingClientManager(GlobalEventBus.get()));
|
||||||
|
|
||||||
threads.submit(() -> {
|
latch.countDown();
|
||||||
MusicManager<MusicAsset> musicManager =
|
});
|
||||||
new MusicManager<>(
|
|
||||||
GlobalEventBus.get(),
|
|
||||||
ResourceManager.getAllOfTypeAndRemoveWrapper(MusicAsset.class),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
SoundEffectManager<SoundEffectAsset> soundEffectManager =
|
threads.submit(() -> {
|
||||||
new SoundEffectManager<>(ResourceManager.getAllOfType(SoundEffectAsset.class));
|
MusicManager<MusicAsset> musicManager =
|
||||||
|
new MusicManager<>(
|
||||||
|
GlobalEventBus.get(),
|
||||||
|
ResourceManager.getAllOfTypeAndRemoveWrapper(MusicAsset.class),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
AudioVolumeManager audioVolumeManager = new AudioVolumeManager()
|
SoundEffectManager<SoundEffectAsset> soundEffectManager =
|
||||||
.registerManager(VolumeControl.MASTERVOLUME, musicManager)
|
new SoundEffectManager<>(ResourceManager.getAllOfType(SoundEffectAsset.class));
|
||||||
.registerManager(VolumeControl.MASTERVOLUME, soundEffectManager)
|
|
||||||
.registerManager(VolumeControl.FX, soundEffectManager)
|
|
||||||
.registerManager(VolumeControl.MUSIC, musicManager);
|
|
||||||
|
|
||||||
new AudioEventListener<>(
|
AudioVolumeManager audioVolumeManager = new AudioVolumeManager()
|
||||||
GlobalEventBus.get(),
|
.registerManager(VolumeControl.MASTERVOLUME, musicManager)
|
||||||
musicManager,
|
.registerManager(VolumeControl.MASTERVOLUME, soundEffectManager)
|
||||||
soundEffectManager,
|
.registerManager(VolumeControl.FX, soundEffectManager)
|
||||||
audioVolumeManager
|
.registerManager(VolumeControl.MUSIC, musicManager);
|
||||||
).initListeners("medium-button-click.wav");
|
|
||||||
|
|
||||||
latch.countDown();
|
new AudioEventListener<>(
|
||||||
});
|
GlobalEventBus.get(),
|
||||||
|
musicManager,
|
||||||
|
soundEffectManager,
|
||||||
|
audioVolumeManager
|
||||||
|
).initListeners("medium-button-click.wav");
|
||||||
|
|
||||||
try {
|
latch.countDown();
|
||||||
latch.await();
|
});
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
} finally {
|
||||||
}
|
latch.await();
|
||||||
|
threads.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void quit() {
|
public static void quit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user