mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-25 18:17:37 +01:00
Readded zoom-tiles. Still needs some work.
This commit is contained in:
parent
e1a3ac60e2
commit
2b2891bd0a
16
src/main/java/org/dynmap/debug/NullDebugger.java
Normal file
16
src/main/java/org/dynmap/debug/NullDebugger.java
Normal file
@ -0,0 +1,16 @@
|
||||
package org.dynmap.debug;
|
||||
|
||||
public class NullDebugger implements Debugger {
|
||||
@Override
|
||||
public void debug(String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String message, Throwable thrown) {
|
||||
}
|
||||
|
||||
}
|
@ -84,6 +84,8 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
||||
|
||||
/* save the generated tile */
|
||||
saveTile(tile, im, path);
|
||||
|
||||
((KzedMap)tile.getMap()).invalidateTile(new KzedZoomedMapTile((KzedMap)tile.getMap(), im, tile));
|
||||
}
|
||||
|
||||
protected Color scan(World world, int x, int y, int z, int seq)
|
||||
@ -158,6 +160,8 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
||||
debugger.error("Failed to save tile (NullPointerException): " + tilePath, e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* now update zoom-out tile */
|
||||
/*BufferedImage zIm = mgr.zoomCache.get(zoomPath);
|
||||
|
||||
|
@ -31,6 +31,7 @@ public class KzedMap extends Map {
|
||||
|
||||
public static java.util.Map<Integer, Color[]> colors;
|
||||
MapTileRenderer[] renderers;
|
||||
ZoomedTileRenderer zoomrenderer;
|
||||
|
||||
public KzedMap(MapManager manager, World world, Debugger debugger) {
|
||||
super(manager, world, debugger);
|
||||
@ -38,8 +39,9 @@ public class KzedMap extends Map {
|
||||
colors = loadColorSet("colors.txt");
|
||||
renderers = new MapTileRenderer[] {
|
||||
new DefaultTileRenderer("t", debugger),
|
||||
new CaveTileRenderer("ct", debugger)
|
||||
new CaveTileRenderer("ct", debugger),
|
||||
};
|
||||
zoomrenderer = new ZoomedTileRenderer(debugger);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,8 +85,11 @@ public class KzedMap extends Map {
|
||||
|
||||
@Override
|
||||
public void render(MapTile tile) {
|
||||
KzedMapTile t = (KzedMapTile)tile;
|
||||
t.renderer.render(t, getMapManager().tilepath);
|
||||
if (tile instanceof KzedZoomedMapTile) {
|
||||
zoomrenderer.render((KzedZoomedMapTile)tile, getMapManager().tilepath);
|
||||
} else if (tile instanceof KzedMapTile) {
|
||||
((KzedMapTile)tile).renderer.render((KzedMapTile)tile, getMapManager().tilepath);
|
||||
}
|
||||
}
|
||||
|
||||
/* tile X for position x */
|
||||
|
57
src/main/java/org/dynmap/kzedmap/KzedZoomedMapTile.java
Normal file
57
src/main/java/org/dynmap/kzedmap/KzedZoomedMapTile.java
Normal file
@ -0,0 +1,57 @@
|
||||
package org.dynmap.kzedmap;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import org.dynmap.MapTile;
|
||||
|
||||
public class KzedZoomedMapTile extends MapTile {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "z" + originalTile.renderer.getName() + "_" + ztilex(originalTile.px) + "_" + ztiley(originalTile.py);
|
||||
}
|
||||
public BufferedImage unzoomedImage;
|
||||
public KzedMapTile originalTile;
|
||||
public KzedZoomedMapTile(KzedMap map, BufferedImage unzoomedImage, KzedMapTile original) {
|
||||
super(map);
|
||||
this.unzoomedImage = unzoomedImage;
|
||||
this.originalTile = original;
|
||||
}
|
||||
|
||||
public int getTileX() {
|
||||
return ztilex(originalTile.px);
|
||||
}
|
||||
|
||||
public int getTileY() {
|
||||
return ztiley(originalTile.py);
|
||||
}
|
||||
|
||||
static int ztilex(int x) {
|
||||
if(x < 0)
|
||||
return x + (x % (KzedMap.tileWidth*2));
|
||||
else
|
||||
return x - (x % (KzedMap.tileWidth*2));
|
||||
}
|
||||
|
||||
/* zoomed-out tile Y for tile position y */
|
||||
static int ztiley(int y)
|
||||
{
|
||||
if(y < 0)
|
||||
return y + (y % (KzedMap.tileHeight*2));
|
||||
//return y - (zTileHeight + (y % zTileHeight));
|
||||
else
|
||||
return y - (y % (KzedMap.tileHeight*2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof KzedZoomedMapTile) {
|
||||
return ((KzedZoomedMapTile)obj).originalTile.equals(originalTile);
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
77
src/main/java/org/dynmap/kzedmap/ZoomedTileRenderer.java
Normal file
77
src/main/java/org/dynmap/kzedmap/ZoomedTileRenderer.java
Normal file
@ -0,0 +1,77 @@
|
||||
package org.dynmap.kzedmap;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.dynmap.debug.Debugger;
|
||||
|
||||
public class ZoomedTileRenderer {
|
||||
protected Debugger debugger;
|
||||
|
||||
public ZoomedTileRenderer(Debugger debugger) {
|
||||
this.debugger = debugger;
|
||||
}
|
||||
|
||||
public void render(KzedZoomedMapTile zt, String outputPath) {
|
||||
KzedMapTile t = zt.originalTile;
|
||||
String zoomPath = new File(new File(outputPath), zt.getName() + ".png").getPath();
|
||||
render(t.px, t.py, zt.getTileX(), zt.getTileY(), zt.unzoomedImage, zoomPath);
|
||||
}
|
||||
|
||||
public void render(int px, int py, int zpx, int zpy, BufferedImage image, String zoomPath) {
|
||||
BufferedImage zIm = null;
|
||||
debugger.debug("Trying to load zoom-out tile: " + zoomPath);
|
||||
try {
|
||||
File file = new File(zoomPath);
|
||||
zIm = ImageIO.read(file);
|
||||
} catch(IOException e) {
|
||||
}
|
||||
|
||||
if(zIm == null) {
|
||||
/* create new one */
|
||||
zIm = new BufferedImage(KzedMap.tileWidth, KzedMap.tileHeight, BufferedImage.TYPE_INT_RGB);
|
||||
debugger.debug("New zoom-out tile created " + zoomPath);
|
||||
} else {
|
||||
debugger.debug("Loaded zoom-out tile from " + zoomPath);
|
||||
}
|
||||
|
||||
/* update zoom-out tile */
|
||||
|
||||
/* scaled size */
|
||||
int scw = KzedMap.tileWidth / 2;
|
||||
int sch = KzedMap.tileHeight / 2;
|
||||
|
||||
/* origin in zoomed-out tile */
|
||||
int ox = scw;
|
||||
int oy = 0;
|
||||
|
||||
if(zpx != px) ox = 0;
|
||||
if(zpy != py) oy = sch;
|
||||
|
||||
/* blit scaled rendered tile onto zoom-out tile */
|
||||
//WritableRaster zr = zIm.getRaster();
|
||||
Graphics2D g2 = zIm.createGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g2.drawImage(image, ox, oy, scw, sch, null);
|
||||
|
||||
image.flush();
|
||||
|
||||
/* save zoom-out tile */
|
||||
try {
|
||||
File file = new File(zoomPath);
|
||||
ImageIO.write(zIm, "png", file);
|
||||
debugger.debug("Saved zoom-out tile at " + zoomPath);
|
||||
} catch(IOException e) {
|
||||
debugger.error("Failed to save zoom-out tile: " + zoomPath, e);
|
||||
} catch(java.lang.NullPointerException e) {
|
||||
debugger.error("Failed to save zoom-out tile (NullPointerException): " + zoomPath, e);
|
||||
}
|
||||
zIm.flush();
|
||||
}
|
||||
}
|
@ -156,14 +156,16 @@ function makeRequest(url, func, type, fail, post, contenttype)
|
||||
|
||||
img.style.width = config.zoomSize[zoom] + 'px';
|
||||
img.style.height = config.zoomSize[zoom] + 'px';
|
||||
img.style.borderStyle = 'none';
|
||||
//img.style.borderStyle = 'none';
|
||||
img.style.border = '1px solid red';
|
||||
img.style.margin = '-1px -1px -1px -1px';
|
||||
|
||||
var pfx = caveMode ? "c" : "";
|
||||
|
||||
if(zoom > 0) {
|
||||
var tilename = pfx + "t_" + (- coord.x * config.tileWidth) + '_' + coord.y * config.tileHeight;
|
||||
} else {
|
||||
var tilename = pfx + "zt_" + (- coord.x * config.tileWidth * 2) + '_' + coord.y * config.tileHeight * 2;
|
||||
var tilename = pfx + "zt_" + (- coord.x * config.tileWidth * 2) + '_' + (coord.y * config.tileHeight * 2);
|
||||
}
|
||||
|
||||
tileDict[tilename] = img;
|
||||
|
Loading…
Reference in New Issue
Block a user