From 137b6af6d500cc3ada3ccc0690f7379dd0329f2f Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 8 Jul 2011 00:40:52 -0500 Subject: [PATCH] Fix tile render timmes, split out utility class --- src/main/java/org/dynmap/Event.java | 22 ++++++++++++++----- src/main/java/org/dynmap/MapManager.java | 1 + src/main/java/org/dynmap/TileHashManager.java | 15 ++----------- .../org/dynmap/utils/LRULinkedHashMap.java | 15 +++++++++++++ 4 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 src/main/java/org/dynmap/utils/LRULinkedHashMap.java diff --git a/src/main/java/org/dynmap/Event.java b/src/main/java/org/dynmap/Event.java index f387d978..5d3acd81 100644 --- a/src/main/java/org/dynmap/Event.java +++ b/src/main/java/org/dynmap/Event.java @@ -1,21 +1,31 @@ package org.dynmap; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class Event { private List> listeners = new LinkedList>(); + private Object lock = new Object(); - public synchronized void addListener(Listener l) { - listeners.add(l); + public void addListener(Listener l) { + synchronized(lock) { + listeners.add(l); + } } - public synchronized void removeListener(Listener l) { - listeners.remove(l); + public void removeListener(Listener l) { + synchronized(lock) { + listeners.remove(l); + } } - public synchronized void trigger(T t) { - for (Listener l : listeners) { + public void trigger(T t) { + ArrayList> iterlist; + synchronized(lock) { + iterlist = new ArrayList>(listeners); + } + for (Listener l : iterlist) { l.triggered(t); } } diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index 41626997..7eadbed3 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -188,6 +188,7 @@ public class MapManager { found.clear(); rendered.clear(); rendercnt = 0; + timeaccum = 0; map_index++; /* Next map */ if(map_index >= world.maps.size()) { /* Last one done? */ sender.sendMessage("Full render of '" + world.world.getName() + "' finished."); diff --git a/src/main/java/org/dynmap/TileHashManager.java b/src/main/java/org/dynmap/TileHashManager.java index 1c6f3e24..1191bfdb 100644 --- a/src/main/java/org/dynmap/TileHashManager.java +++ b/src/main/java/org/dynmap/TileHashManager.java @@ -2,11 +2,11 @@ package org.dynmap; import java.io.File; import java.io.RandomAccessFile; import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.Map; import java.io.IOException; import java.util.zip.CRC32; +import org.dynmap.utils.LRULinkedHashMap; + /** * Image hash code manager - used to reduce compression and notification of updated tiles that do not actually yield new content * @@ -97,17 +97,6 @@ public class TileHashManager { } } - public static class LRULinkedHashMap extends LinkedHashMap { - private int limit; - public LRULinkedHashMap(int lim) { - super(16, (float)0.75, true); - limit = lim; - } - protected boolean removeEldestEntry(Map.Entry last) { - return(size() >= limit); - } - } - private static final int MAX_CACHED_TILEHASHFILES = 25; private Object lock = new Object(); private LRULinkedHashMap tilehash = new LRULinkedHashMap(MAX_CACHED_TILEHASHFILES); diff --git a/src/main/java/org/dynmap/utils/LRULinkedHashMap.java b/src/main/java/org/dynmap/utils/LRULinkedHashMap.java new file mode 100644 index 00000000..62fbd88b --- /dev/null +++ b/src/main/java/org/dynmap/utils/LRULinkedHashMap.java @@ -0,0 +1,15 @@ +package org.dynmap.utils; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class LRULinkedHashMap extends LinkedHashMap { + private int limit; + public LRULinkedHashMap(int lim) { + super(16, (float)0.75, true); + limit = lim; + } + protected boolean removeEldestEntry(Map.Entry last) { + return(size() >= limit); + } +}