From 8d5b8a81fe8bc62f3526cdae0bf43618d4bd9bf6 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 14 Oct 2012 12:30:33 -0400 Subject: [PATCH] Reorganize the forced chunks a bit- offload the cost of immutable map building to the mods, rather than the chunk tick --- .../common/ForgeChunkManager.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/common/net/minecraftforge/common/ForgeChunkManager.java b/common/net/minecraftforge/common/ForgeChunkManager.java index c711c66f5..52d611fae 100644 --- a/common/net/minecraftforge/common/ForgeChunkManager.java +++ b/common/net/minecraftforge/common/ForgeChunkManager.java @@ -81,7 +81,7 @@ public class ForgeChunkManager private static Map callbacks = Maps.newHashMap(); - private static Map> forcedChunks = new MapMaker().weakKeys().makeMap(); + private static Map> forcedChunks = new MapMaker().weakKeys().makeMap(); private static BiMap pendingEntities = HashBiMap.create(); private static Map> dormantChunkCache = new MapMaker().weakKeys().makeMap(); @@ -209,17 +209,17 @@ public class ForgeChunkManager } /** - * Gets the current max depth for this ticket. - * Should be the same as getMaxChunkListDepth() + * Gets the current max depth for this ticket. + * Should be the same as getMaxChunkListDepth() * unless setChunkListDepth has been called. - * + * * @return Current max depth */ public int getChunkListDepth() { return maxDepth; } - + /** * Get the maximum chunk depth size * @@ -316,8 +316,7 @@ public class ForgeChunkManager ArrayListMultimap newTickets = ArrayListMultimap.create(); tickets.put(world, newTickets); - SetMultimap forcedChunkMap = LinkedHashMultimap.create(); - forcedChunks.put(world, forcedChunkMap); + forcedChunks.put(world, ImmutableSetMultimap.of()); if (!(world instanceof WorldServer)) { @@ -612,7 +611,8 @@ public class ForgeChunkManager return; } ticket.requestedChunks.add(chunk); - forcedChunks.get(ticket.world).put(chunk, ticket); + ImmutableSetMultimap newMap = ImmutableSetMultimap.builder().putAll(forcedChunks.get(ticket.world)).put(chunk, ticket).build(); + forcedChunks.put(ticket.world, newMap); if (ticket.maxDepth > 0 && ticket.requestedChunks.size() > ticket.maxDepth) { ChunkCoordIntPair removed = ticket.requestedChunks.iterator().next(); @@ -650,7 +650,10 @@ public class ForgeChunkManager return; } ticket.requestedChunks.remove(chunk); - forcedChunks.get(ticket.world).remove(chunk, ticket); + LinkedHashMultimap copy = LinkedHashMultimap.create(forcedChunks.get(ticket.world)); + copy.remove(chunk, ticket); + ImmutableSetMultimap newMap = ImmutableSetMultimap.copyOf(copy); + forcedChunks.put(ticket.world,newMap); } static void loadConfiguration() @@ -676,7 +679,7 @@ public class ForgeChunkManager */ public static SetMultimap getPersistentChunksFor(World world) { - return forcedChunks.containsKey(world) ? ImmutableSetMultimap.copyOf(forcedChunks.get(world)) : ImmutableSetMultimap.of(); + return forcedChunks.containsKey(world) ? forcedChunks.get(world) : ImmutableSetMultimap.of(); } static void saveWorld(World world)