mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-01 06:33:38 +01:00
Merge pull request #235 from mikeprimm/master
Add file hashing to reduce zoom-out tile recalc, fix bigworld support
This commit is contained in:
commit
ec948f980e
@ -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<String, ProcessTileRec> toprocess = new HashMap<String, ProcessTileRec>();
|
||||
@ -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,6 +267,12 @@ public class DynmapWorld {
|
||||
}
|
||||
}
|
||||
FileLockManager.getWriteLock(zf);
|
||||
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();
|
||||
@ -274,8 +283,33 @@ public class DynmapWorld {
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
Debug.error("Failed to save zoom-out tile (NullPointerException): " + zf.getName(), e);
|
||||
}
|
||||
FileLockManager.releaseWriteLock(zf);
|
||||
KzedMap.freeBufferedImage(kzIm);
|
||||
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);
|
||||
}
|
||||
private HashMap<String, Long> ignore_upd = new HashMap<String, Long>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user