Add support for cleanup of stale tiles (off edge of map)

This commit is contained in:
Mike Primm 2011-12-15 13:24:16 +08:00 committed by mikeprimm
parent 8f66d34752
commit ba2c3eac1c
11 changed files with 132 additions and 36 deletions

View file

@ -7,17 +7,23 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.dynmap.Client;
import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapChunk;
import org.dynmap.DynmapPlugin;
import org.dynmap.DynmapWorld;
import org.dynmap.Log;
import org.dynmap.MapManager;
import org.dynmap.MapTile;
import org.dynmap.MapType;
import org.dynmap.debug.Debug;
import org.dynmap.kzedmap.MapTileRenderer;
import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.TileFlags;
import org.json.simple.JSONObject;
import com.avaje.ebean.text.StringParser;
public class HDMap extends MapType {
private String name;
@ -270,4 +276,61 @@ public class HDMap extends MapType {
public int getBackgroundARGBNight() {
return bgcolornight;
}
private HDMapTile fileToTile(DynmapWorld world, File f) {
String n = f.getName();
n = n.substring(0, n.lastIndexOf('.'));
if(n == null) return null;
String[] nt = n.split("_");
if(nt.length != 2) return null;
int xx, zz;
try {
xx = Integer.parseInt(nt[0]);
zz = Integer.parseInt(nt[1]);
} catch (NumberFormatException nfx) {
return null;
}
return new HDMapTile(world, perspective, xx, zz);
}
public void purgeOldTiles(final DynmapWorld world, final TileFlags rendered) {
File basedir = new File(world.worldtilepath, prefix); /* Get base directory for map */
FileCallback cb = new FileCallback() {
public void fileFound(File f, File parent, boolean day) {
String n = f.getName();
if(n.startsWith("z")) { /* If zoom file */
if(n.startsWith("z_")) { /* First tier of zoom? */
File ff = new File(parent, n.substring(2)); /* Make file for render tier, and drive update */
HDMapTile tile = fileToTile(world, ff); /* Parse it */
if(tile == null) return;
if(rendered.getFlag(tile.tx, tile.ty) || rendered.getFlag(tile.tx+1, tile.ty) ||
rendered.getFlag(tile.tx, tile.ty-1) || rendered.getFlag(tile.tx+1, tile.ty-1))
return;
world.enqueueZoomOutUpdate(ff);
}
return;
}
HDMapTile tile = fileToTile(world, f);
if(tile == null) return;
if(rendered.getFlag(tile.tx, tile.ty)) { /* If we rendered this tile, its good */
return;
}
Debug.debug("clean up " + f.getPath());
/* Otherwise, delete tile */
f.delete();
/* Push updates, clear hash code, and signal zoom tile update */
MapManager.mapman.pushUpdate(world.world,
new Client.Tile(day?tile.getDayFilename(prefix, getImageFormat()):tile.getFilename(prefix, getImageFormat())));
MapManager.mapman.hashman.updateHashCode(tile.getKey(prefix), day?"day":null, tile.tx, tile.ty, -1);
world.enqueueZoomOutUpdate(f);
}
};
walkMapTree(basedir, cb, false);
if(lighting.isNightAndDayEnabled()) {
basedir = new File(world.worldtilepath, prefix+"_day");
walkMapTree(basedir, cb, true);
}
}
}

View file

@ -73,8 +73,8 @@ public class HDMapTile extends MapTile {
return o.tx == tx && o.ty == ty && (perspective == o.perspective) && (o.getWorld() == getWorld());
}
public String getKey() {
return getWorld().getName() + "." + perspective.getName();
public String getKey(String prefix) {
return getWorld().getName() + "." + prefix;
}
@Override

View file

@ -1186,7 +1186,7 @@ public class IsoHDPerspective implements HDPerspective {
try {
if(rendered[i])
renderone = true;
if((!f.exists()) || (crc != hashman.getImageHashCode(tile.getKey(), prefix, tile.tx, tile.ty))) {
if((!f.exists()) || (crc != hashman.getImageHashCode(tile.getKey(prefix), null, tile.tx, tile.ty))) {
/* Wrap buffer as buffered image */
Debug.debug("saving image " + f.getPath());
if(!f.getParentFile().exists())
@ -1199,7 +1199,7 @@ public class IsoHDPerspective implements HDPerspective {
Debug.error("Failed to save image (NullPointerException): " + f.getPath(), e);
}
MapManager.mapman.pushUpdate(tile.getWorld(), new Client.Tile(fname));
hashman.updateHashCode(tile.getKey(), prefix, tile.tx, tile.ty, crc);
hashman.updateHashCode(tile.getKey(prefix), null, tile.tx, tile.ty, crc);
tile.getDynmapWorld().enqueueZoomOutUpdate(f);
tile_update = true;
}
@ -1216,10 +1216,9 @@ public class IsoHDPerspective implements HDPerspective {
fname = tile.getDayFilename(prefix, fmt);
f = new File(tile.getDynmapWorld().worldtilepath, fname);
FileLockManager.getWriteLock(f);
prefix = prefix+"_day";
tile_update = false;
try {
if((!f.exists()) || (crc != hashman.getImageHashCode(tile.getKey(), prefix, tile.tx, tile.ty))) {
if((!f.exists()) || (crc != hashman.getImageHashCode(tile.getKey(prefix), "day", tile.tx, tile.ty))) {
/* Wrap buffer as buffered image */
Debug.debug("saving image " + f.getPath());
if(!f.getParentFile().exists())
@ -1232,7 +1231,7 @@ public class IsoHDPerspective implements HDPerspective {
Debug.error("Failed to save image (NullPointerException): " + f.getPath(), e);
}
MapManager.mapman.pushUpdate(tile.getWorld(), new Client.Tile(fname));
hashman.updateHashCode(tile.getKey(), prefix, tile.tx, tile.ty, crc);
hashman.updateHashCode(tile.getKey(prefix), "day", tile.tx, tile.ty, crc);
tile.getDynmapWorld().enqueueZoomOutUpdate(f);
tile_update = true;
}
@ -1243,7 +1242,7 @@ public class IsoHDPerspective implements HDPerspective {
FileLockManager.releaseWriteLock(f);
DynmapBufferedImage.freeBufferedImage(dayim[i]);
}
MapManager.mapman.updateStatistics(tile, prefix, true, tile_update, !rendered[i]);
MapManager.mapman.updateStatistics(tile, prefix+"_day", true, tile_update, !rendered[i]);
}
}
return renderone;

View file

@ -1048,7 +1048,7 @@ public class TexturePack {
rslt.setTransparent();
return;
}
/* If warer block, to watercolor tone op */
/* If water block, to watercolor tone op */
if((blkid == 8) || (blkid == 9)) {
textop = COLORMOD_WATERTONED;
}