Improve handling of /reload, clean up dead code
This commit is contained in:
parent
3ddce85f89
commit
737bcb98d9
23 changed files with 279 additions and 338 deletions
|
|
@ -20,7 +20,7 @@ import org.dynmap.DynmapWorld;
|
|||
import org.dynmap.MapManager;
|
||||
import org.dynmap.TileHashManager;
|
||||
import org.dynmap.debug.Debug;
|
||||
import org.dynmap.kzedmap.KzedMap.KzedBufferedImage;
|
||||
import org.dynmap.utils.DynmapBufferedImage;
|
||||
import org.dynmap.utils.FileLockManager;
|
||||
import org.dynmap.utils.MapChunkCache;
|
||||
import org.dynmap.utils.MapIterator;
|
||||
|
|
@ -119,15 +119,15 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
public boolean render(MapChunkCache cache, KzedMapTile tile, File outputFile) {
|
||||
World world = tile.getWorld();
|
||||
boolean isnether = (world.getEnvironment() == Environment.NETHER);
|
||||
KzedBufferedImage im = KzedMap.allocateBufferedImage(KzedMap.tileWidth, KzedMap.tileHeight);
|
||||
KzedBufferedImage zim = KzedMap.allocateBufferedImage(KzedMap.tileWidth/2, KzedMap.tileHeight/2);
|
||||
DynmapBufferedImage im = DynmapBufferedImage.allocateBufferedImage(KzedMap.tileWidth, KzedMap.tileHeight);
|
||||
DynmapBufferedImage zim = DynmapBufferedImage.allocateBufferedImage(KzedMap.tileWidth/2, KzedMap.tileHeight/2);
|
||||
boolean isempty = true;
|
||||
|
||||
KzedBufferedImage im_day = null;
|
||||
KzedBufferedImage zim_day = null;
|
||||
DynmapBufferedImage im_day = null;
|
||||
DynmapBufferedImage zim_day = null;
|
||||
if(night_and_day) {
|
||||
im_day = KzedMap.allocateBufferedImage(KzedMap.tileWidth, KzedMap.tileHeight);
|
||||
zim_day = KzedMap.allocateBufferedImage(KzedMap.tileWidth/2, KzedMap.tileHeight/2);
|
||||
im_day = DynmapBufferedImage.allocateBufferedImage(KzedMap.tileWidth, KzedMap.tileHeight);
|
||||
zim_day = DynmapBufferedImage.allocateBufferedImage(KzedMap.tileWidth/2, KzedMap.tileHeight/2);
|
||||
}
|
||||
|
||||
int ix = KzedMap.anchorx + tile.px / 2 + tile.py / 2 - ((127-maximumHeight)/2);
|
||||
|
|
@ -255,9 +255,9 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
}
|
||||
|
||||
private void doFileWrites(final File fname, final KzedMapTile mtile,
|
||||
final KzedBufferedImage img, final KzedBufferedImage img_day,
|
||||
final DynmapBufferedImage img, final DynmapBufferedImage img_day,
|
||||
final KzedZoomedMapTile zmtile, final File zoomFile,
|
||||
final KzedBufferedImage zimg, final KzedBufferedImage zimg_day, boolean rendered) {
|
||||
final DynmapBufferedImage zimg, final DynmapBufferedImage zimg_day, boolean rendered) {
|
||||
|
||||
/* Get coordinates of zoomed tile */
|
||||
int ox = (mtile.px == zmtile.getTileX())?0:KzedMap.tileWidth/2;
|
||||
|
|
@ -288,7 +288,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
}
|
||||
} finally {
|
||||
FileLockManager.releaseWriteLock(fname);
|
||||
KzedMap.freeBufferedImage(img);
|
||||
DynmapBufferedImage.freeBufferedImage(img);
|
||||
}
|
||||
MapManager.mapman.updateStatistics(mtile, null, true, updated_fname, !rendered);
|
||||
|
||||
|
|
@ -318,7 +318,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
}
|
||||
} finally {
|
||||
FileLockManager.releaseWriteLock(dfname);
|
||||
KzedMap.freeBufferedImage(img_day);
|
||||
DynmapBufferedImage.freeBufferedImage(img_day);
|
||||
}
|
||||
MapManager.mapman.updateStatistics(mtile, "day", true, updated_dfname, !rendered);
|
||||
}
|
||||
|
|
@ -337,7 +337,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
}
|
||||
} finally {
|
||||
FileLockManager.releaseWriteLock(zoomFile);
|
||||
KzedMap.freeBufferedImage(zimg);
|
||||
DynmapBufferedImage.freeBufferedImage(zimg);
|
||||
}
|
||||
MapManager.mapman.updateStatistics(zmtile, null, true, ztile_updated, !rendered);
|
||||
|
||||
|
|
@ -355,16 +355,16 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
}
|
||||
} finally {
|
||||
FileLockManager.releaseWriteLock(zoomFile_day);
|
||||
KzedMap.freeBufferedImage(zimg_day);
|
||||
DynmapBufferedImage.freeBufferedImage(zimg_day);
|
||||
}
|
||||
MapManager.mapman.updateStatistics(zmtile, "day", true, ztile_updated, !rendered);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveZoomedTile(final KzedZoomedMapTile zmtile, final File zoomFile,
|
||||
final KzedBufferedImage zimg, int ox, int oy, String subkey) {
|
||||
final DynmapBufferedImage zimg, int ox, int oy, String subkey) {
|
||||
BufferedImage zIm = null;
|
||||
KzedBufferedImage kzIm = null;
|
||||
DynmapBufferedImage kzIm = null;
|
||||
try {
|
||||
zIm = ImageIO.read(zoomFile);
|
||||
} catch (IOException e) {
|
||||
|
|
@ -374,7 +374,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
boolean zIm_allocated = false;
|
||||
if (zIm == null) {
|
||||
/* create new one */
|
||||
kzIm = KzedMap.allocateBufferedImage(KzedMap.tileWidth, KzedMap.tileHeight);
|
||||
kzIm = DynmapBufferedImage.allocateBufferedImage(KzedMap.tileWidth, KzedMap.tileHeight);
|
||||
zIm = kzIm.buf_img;
|
||||
zIm_allocated = true;
|
||||
Debug.debug("New zoom-out tile created " + zmtile.getFilename());
|
||||
|
|
@ -399,7 +399,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
}
|
||||
|
||||
if(zIm_allocated)
|
||||
KzedMap.freeBufferedImage(kzIm);
|
||||
DynmapBufferedImage.freeBufferedImage(kzIm);
|
||||
else
|
||||
zIm.flush();
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import org.dynmap.MapManager;
|
|||
import org.dynmap.MapTile;
|
||||
import org.dynmap.MapType;
|
||||
import org.dynmap.MapType.MapStep;
|
||||
import org.dynmap.utils.DynmapBufferedImage;
|
||||
import org.dynmap.utils.MapChunkCache;
|
||||
import org.json.simple.JSONObject;
|
||||
import java.awt.image.DataBufferInt;
|
||||
|
|
@ -50,20 +51,6 @@ public class KzedMap extends MapType {
|
|||
MapTileRenderer[] renderers;
|
||||
private boolean isbigmap;
|
||||
|
||||
/* BufferedImage with direct access to its ARGB-formatted data buffer */
|
||||
public static class KzedBufferedImage {
|
||||
public BufferedImage buf_img;
|
||||
public int[] argb_buf;
|
||||
public int width;
|
||||
public int height;
|
||||
}
|
||||
|
||||
/* BufferedImage cache - we use the same things a lot... */
|
||||
private static Object lock = new Object();
|
||||
private static HashMap<Long, LinkedList<KzedBufferedImage>> imgcache =
|
||||
new HashMap<Long, LinkedList<KzedBufferedImage>>(); /* Indexed by resolution - X<<32+Y */
|
||||
private static final int CACHE_LIMIT = 10;
|
||||
|
||||
public KzedMap(ConfigurationNode configuration) {
|
||||
Log.verboseinfo("Loading renderers for map '" + getClass().toString() + "'...");
|
||||
List<MapTileRenderer> renderers = configuration.<MapTileRenderer>createInstances("renderers", new Class<?>[0], new Object[0]);
|
||||
|
|
@ -267,52 +254,6 @@ public class KzedMap extends MapType {
|
|||
return y - (y % zTileHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate buffered image from pool, if possible
|
||||
* @param x - x dimension
|
||||
* @param y - y dimension
|
||||
*/
|
||||
public static KzedBufferedImage allocateBufferedImage(int x, int y) {
|
||||
KzedBufferedImage img = null;
|
||||
synchronized(lock) {
|
||||
long k = (x<<16) + y;
|
||||
LinkedList<KzedBufferedImage> ll = imgcache.get(k);
|
||||
if(ll != null) {
|
||||
img = ll.poll();
|
||||
}
|
||||
}
|
||||
if(img != null) { /* Got it - reset it for use */
|
||||
Arrays.fill(img.argb_buf, 0);
|
||||
}
|
||||
else {
|
||||
img = new KzedBufferedImage();
|
||||
img.width = x;
|
||||
img.height = y;
|
||||
img.argb_buf = new int[x*y];
|
||||
}
|
||||
img.buf_img = createBufferedImage(img.argb_buf, img.width, img.height);
|
||||
return img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffered image to pool
|
||||
*/
|
||||
public static void freeBufferedImage(KzedBufferedImage img) {
|
||||
img.buf_img.flush();
|
||||
img.buf_img = null; /* Toss bufferedimage - seems to hold on to other memory */
|
||||
synchronized(lock) {
|
||||
long k = (img.width<<16) + img.height;
|
||||
LinkedList<KzedBufferedImage> ll = imgcache.get(k);
|
||||
if(ll == null) {
|
||||
ll = new LinkedList<KzedBufferedImage>();
|
||||
imgcache.put(k, ll);
|
||||
}
|
||||
if(ll.size() < CACHE_LIMIT) {
|
||||
ll.add(img);
|
||||
img = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBiomeDataNeeded() {
|
||||
for(MapTileRenderer r : renderers) {
|
||||
|
|
@ -382,21 +323,4 @@ public class KzedMap extends MapType {
|
|||
renderer.buildClientConfiguration(worldObject, world, this);
|
||||
}
|
||||
}
|
||||
|
||||
/* ARGB band masks */
|
||||
private static final int [] band_masks = {0xFF0000, 0xFF00, 0xff, 0xff000000};
|
||||
|
||||
/**
|
||||
* Build BufferedImage from provided ARGB array and dimensions
|
||||
*/
|
||||
public static BufferedImage createBufferedImage(int[] argb_buf, int w, int h) {
|
||||
/* Create integer-base data buffer */
|
||||
DataBuffer db = new DataBufferInt (argb_buf, w*h);
|
||||
/* Create writable raster */
|
||||
WritableRaster raster = Raster.createPackedRaster(db, w, h, w, band_masks, null);
|
||||
/* RGB color model */
|
||||
ColorModel color_model = ColorModel.getRGBdefault ();
|
||||
/* Return buffered image */
|
||||
return new BufferedImage (color_model, raster, false, null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue