diff --git a/game/src/main/org/apollo/game/GameConstants.java b/game/src/main/org/apollo/game/GameConstants.java index f44f7497..b765cba2 100644 --- a/game/src/main/org/apollo/game/GameConstants.java +++ b/game/src/main/org/apollo/game/GameConstants.java @@ -10,7 +10,7 @@ public final class GameConstants { /** * The maximum amount of messages to process per pulse (per session). */ - public static final int MESSAGES_PER_PULSE = 10; + public static final int MESSAGES_PER_PULSE = 25; /** * The delay between consecutive pulses, in milliseconds. diff --git a/game/src/main/org/apollo/game/model/World.java b/game/src/main/org/apollo/game/model/World.java index d2dbb584..27536ab8 100644 --- a/game/src/main/org/apollo/game/model/World.java +++ b/game/src/main/org/apollo/game/model/World.java @@ -1,10 +1,10 @@ package org.apollo.game.model; +import java.util.ArrayDeque; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; import java.util.logging.Logger; import org.apollo.Service; @@ -99,7 +99,12 @@ public final class World { /** * The Queue of Npcs that have yet to be added to the repository. */ - private final Queue queuedNpcs = new ConcurrentLinkedQueue<>(); + private final Queue queuedNpcs = new ArrayDeque<>(); + + /** + * The Queue of Npcs that have yet to be removed from the repository. + */ + private final Queue oldNpcs = new ArrayDeque<>(); /** * This world's {@link RegionRepository}. @@ -242,6 +247,7 @@ public final class World { * Pulses this World. */ public void pulse() { + unregisterNpcs(); registerNpcs(); scheduler.pulse(); } @@ -311,10 +317,7 @@ public final class World { public void unregister(final Npc npc) { Preconditions.checkNotNull(npc, "Npc may not be null."); - Region region = regions.fromPosition(npc.getPosition()); - region.removeEntity(npc); - - npcRepository.remove(npc); + oldNpcs.add(npc); } /** @@ -363,4 +366,19 @@ public final class World { } } } + + /** + * Unregisters all of the {@link Npc}s in the {@link #oldNpcs queue}. + */ + private void unregisterNpcs() { + while (!oldNpcs.isEmpty()) { + Npc npc = oldNpcs.poll(); + + Region region = regions.fromPosition(npc.getPosition()); + region.removeEntity(npc); + + npcRepository.remove(npc); + } + } + } \ No newline at end of file