Search in sources :

Example 1 with PhasedSynchronizationTask

use of org.apollo.game.sync.task.PhasedSynchronizationTask in project apollo by apollo-rsps.

the class ParallelClientSynchronizer method synchronize.

@Override
public void synchronize(MobRepository<Player> players, MobRepository<Npc> npcs) {
    int playerCount = players.size();
    int npcCount = npcs.size();
    Map<RegionCoordinates, Set<RegionUpdateMessage>> encodes = new ConcurrentHashMap<>();
    Map<RegionCoordinates, Set<RegionUpdateMessage>> updates = new ConcurrentHashMap<>();
    phaser.bulkRegister(playerCount);
    for (Player player : players) {
        SynchronizationTask task = new PrePlayerSynchronizationTask(player, encodes, updates);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
    phaser.bulkRegister(npcCount);
    for (Npc npc : npcs) {
        SynchronizationTask task = new PreNpcSynchronizationTask(npc);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
    phaser.bulkRegister(playerCount);
    for (Player player : players) {
        SynchronizationTask task = new PlayerSynchronizationTask(player);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
    phaser.bulkRegister(playerCount);
    for (Player player : players) {
        SynchronizationTask task = new NpcSynchronizationTask(player);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
    phaser.bulkRegister(playerCount);
    for (Player player : players) {
        SynchronizationTask task = new PostPlayerSynchronizationTask(player);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
    phaser.bulkRegister(npcCount);
    for (Npc npc : npcs) {
        SynchronizationTask task = new PostNpcSynchronizationTask(npc);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
}
Also used : Npc(org.apollo.game.model.entity.Npc) PhasedSynchronizationTask(org.apollo.game.sync.task.PhasedSynchronizationTask) Player(org.apollo.game.model.entity.Player) Set(java.util.Set) PlayerSynchronizationTask(org.apollo.game.sync.task.PlayerSynchronizationTask) PrePlayerSynchronizationTask(org.apollo.game.sync.task.PrePlayerSynchronizationTask) PostPlayerSynchronizationTask(org.apollo.game.sync.task.PostPlayerSynchronizationTask) PrePlayerSynchronizationTask(org.apollo.game.sync.task.PrePlayerSynchronizationTask) NpcSynchronizationTask(org.apollo.game.sync.task.NpcSynchronizationTask) PlayerSynchronizationTask(org.apollo.game.sync.task.PlayerSynchronizationTask) PrePlayerSynchronizationTask(org.apollo.game.sync.task.PrePlayerSynchronizationTask) SynchronizationTask(org.apollo.game.sync.task.SynchronizationTask) PostNpcSynchronizationTask(org.apollo.game.sync.task.PostNpcSynchronizationTask) PostPlayerSynchronizationTask(org.apollo.game.sync.task.PostPlayerSynchronizationTask) PreNpcSynchronizationTask(org.apollo.game.sync.task.PreNpcSynchronizationTask) PhasedSynchronizationTask(org.apollo.game.sync.task.PhasedSynchronizationTask) RegionCoordinates(org.apollo.game.model.area.RegionCoordinates) NpcSynchronizationTask(org.apollo.game.sync.task.NpcSynchronizationTask) PostNpcSynchronizationTask(org.apollo.game.sync.task.PostNpcSynchronizationTask) PreNpcSynchronizationTask(org.apollo.game.sync.task.PreNpcSynchronizationTask) PreNpcSynchronizationTask(org.apollo.game.sync.task.PreNpcSynchronizationTask) PostPlayerSynchronizationTask(org.apollo.game.sync.task.PostPlayerSynchronizationTask) PostNpcSynchronizationTask(org.apollo.game.sync.task.PostNpcSynchronizationTask) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 RegionCoordinates (org.apollo.game.model.area.RegionCoordinates)1 Npc (org.apollo.game.model.entity.Npc)1 Player (org.apollo.game.model.entity.Player)1 NpcSynchronizationTask (org.apollo.game.sync.task.NpcSynchronizationTask)1 PhasedSynchronizationTask (org.apollo.game.sync.task.PhasedSynchronizationTask)1 PlayerSynchronizationTask (org.apollo.game.sync.task.PlayerSynchronizationTask)1 PostNpcSynchronizationTask (org.apollo.game.sync.task.PostNpcSynchronizationTask)1 PostPlayerSynchronizationTask (org.apollo.game.sync.task.PostPlayerSynchronizationTask)1 PreNpcSynchronizationTask (org.apollo.game.sync.task.PreNpcSynchronizationTask)1 PrePlayerSynchronizationTask (org.apollo.game.sync.task.PrePlayerSynchronizationTask)1 SynchronizationTask (org.apollo.game.sync.task.SynchronizationTask)1