mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 08:40:03 +00:00
Queue npcs before unregistering, increase maximum messages
This commit is contained in:
@@ -10,7 +10,7 @@ public final class GameConstants {
|
|||||||
/**
|
/**
|
||||||
* The maximum amount of messages to process per pulse (per session).
|
* 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.
|
* The delay between consecutive pulses, in milliseconds.
|
||||||
|
|||||||
@@ -101,6 +101,11 @@ public final class World {
|
|||||||
*/
|
*/
|
||||||
private final Queue<Npc> queuedNpcs = new ConcurrentLinkedQueue<>();
|
private final Queue<Npc> queuedNpcs = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Queue of Npcs that have yet to be removed from the repository.
|
||||||
|
*/
|
||||||
|
private final Queue<Npc> oldNpcs = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This world's {@link RegionRepository}.
|
* This world's {@link RegionRepository}.
|
||||||
*/
|
*/
|
||||||
@@ -242,6 +247,7 @@ public final class World {
|
|||||||
* Pulses this World.
|
* Pulses this World.
|
||||||
*/
|
*/
|
||||||
public void pulse() {
|
public void pulse() {
|
||||||
|
unregisterNpcs();
|
||||||
registerNpcs();
|
registerNpcs();
|
||||||
scheduler.pulse();
|
scheduler.pulse();
|
||||||
}
|
}
|
||||||
@@ -311,10 +317,7 @@ public final class World {
|
|||||||
public void unregister(final Npc npc) {
|
public void unregister(final Npc npc) {
|
||||||
Preconditions.checkNotNull(npc, "Npc may not be null.");
|
Preconditions.checkNotNull(npc, "Npc may not be null.");
|
||||||
|
|
||||||
Region region = regions.fromPosition(npc.getPosition());
|
oldNpcs.add(npc);
|
||||||
region.removeEntity(npc);
|
|
||||||
|
|
||||||
npcRepository.remove(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user