use of games.strategy.engine.framework.startup.launcher.IServerReady in project triplea by triplea-game.
the class ClientModel method startGameInNewThread.
private void startGameInNewThread(final byte[] gameData, final Map<String, INode> players, final boolean gameRunning) {
final GameData data;
try {
// this normally takes a couple seconds, but can take
// up to 60 seconds for a freaking huge game
data = IoUtils.readFromMemory(gameData, GameDataManager::loadGame);
} catch (final IOException ex) {
ClientLogger.logQuietly("Failed to load game", ex);
return;
}
objectStreamFactory.setData(data);
final Map<String, String> playerMapping = playersToNodes.entrySet().stream().filter(e -> e.getValue().equals(messenger.getLocalNode().getName())).collect(Collectors.toMap(Map.Entry::getKey, e -> IGameLoader.CLIENT_PLAYER_TYPE));
final Set<IGamePlayer> playerSet = data.getGameLoader().createPlayers(playerMapping);
final Messengers messengers = new Messengers(messenger, remoteMessenger, channelMessenger);
game = new ClientGame(data, playerSet, players, messengers);
new Thread(() -> {
SwingUtilities.invokeLater(() -> JOptionPane.getFrameForComponent(ui).setVisible(false));
try {
// game will be null if we loose the connection
if (game != null) {
try {
data.getGameLoader().startGame(game, playerSet, false);
data.testLocksOnRead();
} catch (final Exception e) {
ClientLogger.logError("Failed to start Game", e);
game.shutDown();
messenger.shutDown();
gameLoadingWindow.doneWait();
// an ugly hack, we need a better
// way to get the main frame
GameRunner.clientLeftGame();
}
}
if (!gameRunning) {
((IServerReady) remoteMessenger.getRemote(CLIENT_READY_CHANNEL)).clientReady();
}
} finally {
gameLoadingWindow.doneWait();
}
}, "Client Game Launcher").start();
}
Aggregations