use of de.gg.engine.misc.TickCounter in project ProjektGG by eskalon.
the class GameSession method init.
/**
* Sets the game up by initializing the world, the game entities and the
* processing systems.
* <p>
* After the initialization the session can be updated via calling
* {@link #update()}. To resume the game after a round ended
* {@link #startNextRound()} has to get called.
*
* @param players
* A hashmap of all players in this session.
* @param savedGame
* <i>Not</i> <code>null</code> if this is a loaded game state.
*/
public synchronized void init(HashMap<Short, LobbyPlayer> players, @Nullable SavedGame savedGame) {
if (savedGame == null) {
this.world = new World();
this.world.generate(sessionSetup, players);
} else {
this.world = savedGame.world;
this.currentRound = savedGame.currentRound;
// Switch player IDs when loading game
if (savedGame != null) {
for (Entry<Short, LobbyPlayer> newE : players.entrySet()) {
for (Entry<Short, String> oldE : savedGame.clientIdentifiers.entrySet()) {
if (newE.getValue().getHostname().equals(oldE.getValue())) {
// Change all mentions of the saved player id to the
// new one
// Use negative numbers so there are no collisions
Player p = world.getPlayers().remove(oldE.getKey());
world.getPlayers().put((short) -newE.getKey(), p);
}
}
}
// Revert the IDs back to positive numbers
for (short s : savedGame.world.getPlayers().keySet()) {
Player p = world.getPlayers().remove(s);
world.getPlayers().put((short) -s, p);
}
}
// TODO in den Konstruktoren die Setups setzen
// TODO in der Lobby das Setup disablen
}
// Add and initialize the smp system(s)
this.roundEndSystem = new RoundEndSystem(localNetworkId);
this.roundEndSystem.init(world);
// Init the tick counter
this.tickCounter = new TickCounter(new TickHandler() {
@Override
public void onTick() {
fixedUpdate();
}
@Override
public int getDeltaMultiplier() {
return gameSpeed.getDeltaTimeMultiplied();
}
}, TICKS_PER_ROUND, TICK_DURATION, savedGame == null ? 0 : savedGame.lastProcessedTick);
this.initialized = true;
}
Aggregations