From d63db655d8a8391e7fb9976610060aa5781999f1 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 24 Jun 2011 02:46:16 -0500 Subject: [PATCH] More tuning on zoom-out, fix zoomout on bigworld on iso-maps --- src/main/java/org/dynmap/DynmapWorld.java | 58 ++++++++++++++++++----- web/js/kzedmaps.js | 9 ++-- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/dynmap/DynmapWorld.java b/src/main/java/org/dynmap/DynmapWorld.java index ffa3bea6..5cf28eb1 100644 --- a/src/main/java/org/dynmap/DynmapWorld.java +++ b/src/main/java/org/dynmap/DynmapWorld.java @@ -137,18 +137,19 @@ public class DynmapWorld { Debug.debug("freshenZoomOutFiles(" + world.getName() + "," + zoomlevel + ") - done (" + cnt + " updated files)"); } - private static class ProcessTileRec { File zf; String zfname; int x, y; } + private String makeFilePath(PrefixData pd, int x, int y, boolean zoomed) { if(bigworld) return pd.baseprefix + "/" + ((x/pd.stepsize) >> 5) + "_" + ((y/pd.stepsize) >> 5) + "/" + (zoomed?pd.zfnprefix:pd.fnprefix) + x + "_" + y + ".png"; else return (zoomed?pd.zfnprefix:pd.fnprefix) + "_" + x + "_" + y + ".png"; } + private int processZoomDirectory(File dir, PrefixData pd) { Debug.debug("processZoomDirectory(" + dir.getPath() + "," + pd.baseprefix + ")"); HashMap toprocess = new HashMap(); @@ -188,8 +189,9 @@ public class DynmapWorld { /* Make name of corresponding zoomed tile */ String zfname = makeFilePath(pd, x, y, true); File zf = new File(worldtilepath, zfname); + long fts = f.lastModified(); /* If zoom file exists and is older than our file, nothing to do */ - if(zf.exists() && (zf.lastModified() >= f.lastModified())) { + if(zf.exists() && ((zf.lastModified() >= f.lastModified()) || checkIgnoreUpdate(f, fts))) { continue; } String zfpath = zf.getPath(); @@ -211,6 +213,7 @@ public class DynmapWorld { Debug.debug("processZoomDirectory(" + dir.getPath() + "," + pd.baseprefix + ") - done (" + cnt + " files)"); return cnt; } + private void processZoomTile(PrefixData pd, File dir, File zf, String zfname, int tx, int ty) { Debug.debug("processZoomFile(" + pd.baseprefix + "," + dir.getPath() + "," + zf.getPath() + "," + tx + "," + ty + ")"); int width = 128, height = 128; @@ -264,18 +267,49 @@ public class DynmapWorld { } } FileLockManager.getWriteLock(zf); - try { - if(!zf.getParentFile().exists()) - zf.getParentFile().mkdirs(); - FileLockManager.imageIOWrite(zIm, "png", zf); - Debug.debug("Saved zoom-out tile at " + zf.getPath()); - } catch (IOException e) { - Debug.error("Failed to save zoom-out tile: " + zf.getName(), e); - } catch (java.lang.NullPointerException e) { - Debug.error("Failed to save zoom-out tile (NullPointerException): " + zf.getName(), e); + TileHashManager hashman = MapManager.mapman.hashman; + long crc = hashman.calculateTileHash(argb); /* Get hash of tile */ + int tilex = tx/step/2; + int tiley = ty/step/2; + String key = world.getName()+"."+pd.zoomprefix+pd.baseprefix; + if((!zf.exists()) || (crc != MapManager.mapman.hashman.getImageHashCode(key, null, tilex, tiley))) { + try { + if(!zf.getParentFile().exists()) + zf.getParentFile().mkdirs(); + FileLockManager.imageIOWrite(zIm, "png", zf); + Debug.debug("Saved zoom-out tile at " + zf.getPath()); + } catch (IOException e) { + Debug.error("Failed to save zoom-out tile: " + zf.getName(), e); + } catch (java.lang.NullPointerException e) { + Debug.error("Failed to save zoom-out tile (NullPointerException): " + zf.getName(), e); + } + hashman.updateHashCode(key, null, tilex, tiley, crc); + MapManager.mapman.pushUpdate(this.world, new Client.Tile(zfname)); + } + else { + zf.setLastModified(System.currentTimeMillis()); /* Touch the existing file */ +// ignoreUpdate(zf); /* Remember to ignore this update */ } FileLockManager.releaseWriteLock(zf); KzedMap.freeBufferedImage(kzIm); - MapManager.mapman.pushUpdate(this.world, new Client.Tile(zfname)); } + private HashMap ignore_upd = new HashMap(); + + private void ignoreUpdate(File f) { + long ts = f.lastModified(); + ignore_upd.put(f.getPath(), ts); + } + /** + * Check if ignore for file at current timestamp - return true if so + */ + private boolean checkIgnoreUpdate(File f, long ts) { + String fn = f.getPath(); + Long its = ignore_upd.get(fn); + if((its != null) && (ts <= its.longValue())) { + return true; + } + ignore_upd.remove(fn); /* If newer, stop ignoring */ + return false; + } + } diff --git a/web/js/kzedmaps.js b/web/js/kzedmaps.js index 971af58e..d5312715 100644 --- a/web/js/kzedmaps.js +++ b/web/js/kzedmaps.js @@ -50,18 +50,19 @@ KzedMapType.prototype = $.extend(new DynMapType(), { dnprefix = '_day'; var extrazoom = this.dynmap.world.extrazoomout; if (zoom <= extrazoom) { - var zpre = 'zzzzzzzzzzzzzzzz'.substring(0, extrazoom-zoom+1); + var zpre = 'zzzzzzzzzzzzzzzz'.substring(0, extrazoom-zoom); // Most zoomed out tiles. tileSize = 128; imgSize = tileSize; var tilescale = 2 << (extrazoom-zoom); if (this.dynmap.world.bigworld) { - tileName = zpre + this.prefix + dnprefix + '/' + ((-coord.x * tileSize*tilescale)>>12) + - '_' + ((coord.y * tileSize*tilescale) >> 12) + '/' + + if(zoom < extrazoom) zpre = zpre + '_'; + tileName = 'z' + this.prefix + dnprefix + '/' + ((-coord.x * tileSize*tilescale)>>12) + + '_' + ((coord.y * tileSize*tilescale) >> 12) + '/' + zpre + (-coord.x * tileSize*tilescale) + '_' + (coord.y * tileSize*tilescale) + '.png'; } else { - tileName = zpre + this.prefix + dnprefix + '_' + (-coord.x * tileSize*tilescale) + '_' + (coord.y * tileSize*tilescale) + '.png'; + tileName = zpre + 'z' + this.prefix + dnprefix + '_' + (-coord.x * tileSize*tilescale) + '_' + (coord.y * tileSize*tilescale) + '.png'; } } else { // Other zoom levels.