From 4cb5b9a95615dc234be80c4c8aaf047135674597 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Mon, 15 Aug 2011 06:43:08 +0800 Subject: [PATCH] Fix initial zoomout processing (unnecessary updates), extra tile invalidates --- src/main/java/org/dynmap/DynmapPlugin.java | 27 ++++++++++++------- src/main/java/org/dynmap/DynmapWorld.java | 13 +++++++-- src/main/java/org/dynmap/MapManager.java | 4 +-- src/main/java/org/dynmap/flat/FlatMap.java | 16 +++++++++++ src/main/java/org/dynmap/hdmap/HDMapTile.java | 6 ++--- .../java/org/dynmap/kzedmap/KzedMapTile.java | 6 ++--- 6 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index f6768724..dfa9ccc5 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -352,8 +352,9 @@ public class DynmapPlugin extends JavaPlugin { return; Location loc = event.getBlock().getLocation(); mm.sscache.invalidateSnapshot(loc); - if(onplace) + if(onplace) { mm.touch(loc); + } } @Override @@ -362,8 +363,9 @@ public class DynmapPlugin extends JavaPlugin { return; Location loc = event.getBlock().getLocation(); mm.sscache.invalidateSnapshot(loc); - if(onbreak) + if(onbreak) { mm.touch(loc); + } } @Override @@ -372,8 +374,9 @@ public class DynmapPlugin extends JavaPlugin { return; Location loc = event.getBlock().getLocation(); mm.sscache.invalidateSnapshot(loc); - if(onleaves) + if(onleaves) { mm.touch(loc); + } } @Override @@ -382,8 +385,9 @@ public class DynmapPlugin extends JavaPlugin { return; Location loc = event.getBlock().getLocation(); mm.sscache.invalidateSnapshot(loc); - if(onburn) + if(onburn) { mm.touch(loc); + } } @Override @@ -392,8 +396,9 @@ public class DynmapPlugin extends JavaPlugin { return; Location loc = event.getBlock().getLocation(); mm.sscache.invalidateSnapshot(loc); - if(onblockform) + if(onblockform) { mm.touch(loc); + } } @Override public void onBlockFade(BlockFadeEvent event) { @@ -401,8 +406,9 @@ public class DynmapPlugin extends JavaPlugin { return; Location loc = event.getBlock().getLocation(); mm.sscache.invalidateSnapshot(loc); - if(onblockfade) + if(onblockfade) { mm.touch(loc); + } } @Override public void onBlockSpread(BlockSpreadEvent event) { @@ -410,8 +416,9 @@ public class DynmapPlugin extends JavaPlugin { return; Location loc = event.getBlock().getLocation(); mm.sscache.invalidateSnapshot(loc); - if(onblockspread) + if(onblockspread) { mm.touch(loc); + } } @Override public void onBlockPistonRetract(BlockPistonRetractEvent event) { @@ -421,8 +428,9 @@ public class DynmapPlugin extends JavaPlugin { Location loc = b.getLocation(); mm.sscache.invalidateSnapshot(loc); BlockFace dir = event.getDirection(); - if(onpiston) + if(onpiston) { mm.touchVolume(loc, b.getRelative(dir, 2).getLocation()); + } for(int i = 0; i < 2; i++) { b = b.getRelative(dir, 1); mm.sscache.invalidateSnapshot(b.getLocation()); @@ -436,8 +444,9 @@ public class DynmapPlugin extends JavaPlugin { Location loc = b.getLocation(); mm.sscache.invalidateSnapshot(loc); BlockFace dir = event.getDirection(); - if(onpiston) + if(onpiston) { mm.touchVolume(loc, b.getRelative(dir, 1+event.getLength()).getLocation()); + } for(int i = 0; i < 1+event.getLength(); i++) { b = b.getRelative(dir, 1); mm.sscache.invalidateSnapshot(b.getLocation()); diff --git a/src/main/java/org/dynmap/DynmapWorld.java b/src/main/java/org/dynmap/DynmapWorld.java index 72b9f37b..73238eb2 100644 --- a/src/main/java/org/dynmap/DynmapWorld.java +++ b/src/main/java/org/dynmap/DynmapWorld.java @@ -105,12 +105,21 @@ public class DynmapWorld { } } + private static final String COORDSTART = "-0123456789"; private static class PNGFileFilter implements FilenameFilter { String prefix; String suffix; - public PNGFileFilter(String pre, MapType.ImageFormat fmt) { prefix = pre; suffix = "." + fmt.getFileExt(); } + public PNGFileFilter(String pre, MapType.ImageFormat fmt) { + if((pre != null) && (pre.length() > 0)) + prefix = pre; + suffix = "." + fmt.getFileExt(); + } public boolean accept(File f, String n) { - if(n.endsWith(suffix) && n.startsWith(prefix)) { + if(n.endsWith(suffix)) { + if((prefix != null) && (!n.startsWith(prefix))) + return false; + if((prefix == null) && (COORDSTART.indexOf(n.charAt(0)) < 0)) + return false; File fn = new File(f, n); return fn.isFile(); } diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index 2bedb159..651e0a3f 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -658,8 +658,8 @@ public class MapManager { } public void invalidateTile(MapTile tile) { - Debug.debug("Invalidating tile " + tile.getFilename()); - tileQueue.push(tile); + if(tileQueue.push(tile)) + Debug.debug("Invalidating tile " + tile.getFilename()); } public static void scheduleDelayedJob(Runnable job, long delay_in_msec) { diff --git a/src/main/java/org/dynmap/flat/FlatMap.java b/src/main/java/org/dynmap/flat/FlatMap.java index 136e87e9..8d9a61af 100644 --- a/src/main/java/org/dynmap/flat/FlatMap.java +++ b/src/main/java/org/dynmap/flat/FlatMap.java @@ -538,6 +538,22 @@ public class FlatMap extends MapType { return map.getAdjecentTiles(this); } + @Override + public int hashCode() { + return x ^ y ^ size ^ map.getName().hashCode(); + } + + @Override + public boolean equals(Object x) { + if(x instanceof FlatMapTile) { + return equals((FlatMapTile)x); + } + return false; + } + public boolean equals(FlatMapTile o) { + return (o.x == x) && (o.y == y) && (o.map == map); + } + @Override public String getKey() { return world.world.getName() + "." + map.getPrefix(); diff --git a/src/main/java/org/dynmap/hdmap/HDMapTile.java b/src/main/java/org/dynmap/hdmap/HDMapTile.java index 6d6fc42f..bbb87a18 100644 --- a/src/main/java/org/dynmap/hdmap/HDMapTile.java +++ b/src/main/java/org/dynmap/hdmap/HDMapTile.java @@ -40,7 +40,7 @@ public class HDMapTile extends MapTile { @Override public int hashCode() { - return perspective.getName().hashCode() ^ getWorld().hashCode(); + return tx ^ ty ^ perspective.getName().hashCode() ^ getWorld().getName().hashCode(); } @Override @@ -48,11 +48,11 @@ public class HDMapTile extends MapTile { if (obj instanceof HDMapTile) { return equals((HDMapTile) obj); } - return super.equals(obj); + return false; } public boolean equals(HDMapTile o) { - return o.tx == tx && o.ty == ty && o.getWorld().equals(getWorld()) && (perspective.equals(o.perspective)); + return o.tx == tx && o.ty == ty && (perspective == o.perspective) && (o.getWorld() == getWorld()); } public String getKey() { diff --git a/src/main/java/org/dynmap/kzedmap/KzedMapTile.java b/src/main/java/org/dynmap/kzedmap/KzedMapTile.java index 7ea2e01d..dba01203 100644 --- a/src/main/java/org/dynmap/kzedmap/KzedMapTile.java +++ b/src/main/java/org/dynmap/kzedmap/KzedMapTile.java @@ -52,7 +52,7 @@ public class KzedMapTile extends MapTile { @Override public int hashCode() { - return getFilename().hashCode() ^ getWorld().hashCode(); + return px ^ py ^ map.getName().hashCode() ^ getWorld().getName().hashCode(); } @Override @@ -60,11 +60,11 @@ public class KzedMapTile extends MapTile { if (obj instanceof KzedMapTile) { return equals((KzedMapTile) obj); } - return super.equals(obj); + return false; } public boolean equals(KzedMapTile o) { - return o.px == px && o.py == py && o.getWorld().equals(getWorld()); + return o.px == px && o.py == py && (o.map == map) && (o.getWorld() == getWorld()); } public String getKey() {