From c4874acd3caea7d44dbe06faf30f392293475c2e Mon Sep 17 00:00:00 2001 From: atomicint Date: Tue, 9 Feb 2016 13:32:07 -0500 Subject: [PATCH] Queue npcs before unregistering, increase maximum messages --- .../main/org/apollo/game/GameConstants.java | 2 +- .../src/main/org/apollo/game/model/World.java | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) 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..14bc40ae 100644 --- a/game/src/main/org/apollo/game/model/World.java +++ b/game/src/main/org/apollo/game/model/World.java @@ -100,6 +100,11 @@ public final class World { * The Queue of Npcs that have yet to be added to the repository. */ private final Queue queuedNpcs = new ConcurrentLinkedQueue<>(); + + /** + * The Queue of Npcs that have yet to be removed from the repository. + */ + private final Queue oldNpcs = new ConcurrentLinkedQueue<>(); /** * 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