Readded zoom-tiles. Still needs some work.
This commit is contained in:
parent
e1a3ac60e2
commit
2b2891bd0a
7 changed files with 933 additions and 772 deletions
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) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,275 +1,279 @@
|
||||||
package org.dynmap.kzedmap;
|
package org.dynmap.kzedmap;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.WritableRaster;
|
import java.awt.image.WritableRaster;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.dynmap.MapManager;
|
import org.dynmap.MapManager;
|
||||||
import org.dynmap.MapTile;
|
import org.dynmap.MapTile;
|
||||||
import org.dynmap.debug.Debugger;
|
import org.dynmap.debug.Debugger;
|
||||||
|
|
||||||
public class DefaultTileRenderer implements MapTileRenderer {
|
public class DefaultTileRenderer implements MapTileRenderer {
|
||||||
private String name;
|
private String name;
|
||||||
protected Debugger debugger;
|
protected Debugger debugger;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultTileRenderer(String name, Debugger debugger) {
|
public DefaultTileRenderer(String name, Debugger debugger) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.debugger = debugger;
|
this.debugger = debugger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(KzedMapTile tile, String path) {
|
public void render(KzedMapTile tile, String path) {
|
||||||
World world = tile.getMap().getWorld();
|
World world = tile.getMap().getWorld();
|
||||||
BufferedImage im = new BufferedImage(KzedMap.tileWidth, KzedMap.tileHeight, BufferedImage.TYPE_INT_RGB);
|
BufferedImage im = new BufferedImage(KzedMap.tileWidth, KzedMap.tileHeight, BufferedImage.TYPE_INT_RGB);
|
||||||
|
|
||||||
WritableRaster r = im.getRaster();
|
WritableRaster r = im.getRaster();
|
||||||
|
|
||||||
int ix = tile.mx;
|
int ix = tile.mx;
|
||||||
int iy = tile.my;
|
int iy = tile.my;
|
||||||
int iz = tile.mz;
|
int iz = tile.mz;
|
||||||
int jx, jz;
|
int jx, jz;
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
/* draw the map */
|
/* draw the map */
|
||||||
for(y=0; y<KzedMap.tileHeight;) {
|
for(y=0; y<KzedMap.tileHeight;) {
|
||||||
jx = ix;
|
jx = ix;
|
||||||
jz = iz;
|
jz = iz;
|
||||||
|
|
||||||
for(x=KzedMap.tileWidth-1; x>=0; x-=2) {
|
for(x=KzedMap.tileWidth-1; x>=0; x-=2) {
|
||||||
Color c1 = scan(world, jx, iy, jz, 0);
|
Color c1 = scan(world, jx, iy, jz, 0);
|
||||||
Color c2 = scan(world, jx, iy, jz, 2);
|
Color c2 = scan(world, jx, iy, jz, 2);
|
||||||
|
|
||||||
r.setPixel(x, y, new int[] { c1.getRed(), c1.getGreen(), c1.getBlue() });
|
r.setPixel(x, y, new int[] { c1.getRed(), c1.getGreen(), c1.getBlue() });
|
||||||
r.setPixel(x-1, y, new int[] { c2.getRed(), c2.getGreen(), c2.getBlue() });
|
r.setPixel(x-1, y, new int[] { c2.getRed(), c2.getGreen(), c2.getBlue() });
|
||||||
|
|
||||||
jx++;
|
jx++;
|
||||||
jz++;
|
jz++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
y ++;
|
y ++;
|
||||||
|
|
||||||
jx = ix;
|
jx = ix;
|
||||||
jz = iz - 1;
|
jz = iz - 1;
|
||||||
|
|
||||||
for(x=KzedMap.tileWidth-1; x>=0; x-=2) {
|
for(x=KzedMap.tileWidth-1; x>=0; x-=2) {
|
||||||
Color c1 = scan(world, jx, iy, jz, 2);
|
Color c1 = scan(world, jx, iy, jz, 2);
|
||||||
jx++;
|
jx++;
|
||||||
jz++;
|
jz++;
|
||||||
Color c2 = scan(world, jx, iy, jz, 0);
|
Color c2 = scan(world, jx, iy, jz, 0);
|
||||||
|
|
||||||
r.setPixel(x, y, new int[] { c1.getRed(), c1.getGreen(), c1.getBlue() });
|
r.setPixel(x, y, new int[] { c1.getRed(), c1.getGreen(), c1.getBlue() });
|
||||||
r.setPixel(x-1, y, new int[] { c2.getRed(), c2.getGreen(), c2.getBlue() });
|
r.setPixel(x-1, y, new int[] { c2.getRed(), c2.getGreen(), c2.getBlue() });
|
||||||
}
|
}
|
||||||
|
|
||||||
y ++;
|
y ++;
|
||||||
|
|
||||||
ix ++;
|
ix ++;
|
||||||
iz --;
|
iz --;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save the generated tile */
|
/* save the generated tile */
|
||||||
saveTile(tile, im, path);
|
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)
|
}
|
||||||
{
|
|
||||||
for(;;) {
|
protected Color scan(World world, int x, int y, int z, int seq)
|
||||||
if(y < 0)
|
{
|
||||||
return Color.BLUE;
|
for(;;) {
|
||||||
|
if(y < 0)
|
||||||
int id = world.getBlockAt(x, y, z).getTypeID();
|
return Color.BLUE;
|
||||||
|
|
||||||
switch(seq) {
|
int id = world.getBlockAt(x, y, z).getTypeID();
|
||||||
case 0:
|
|
||||||
x--;
|
switch(seq) {
|
||||||
break;
|
case 0:
|
||||||
case 1:
|
x--;
|
||||||
y--;
|
break;
|
||||||
break;
|
case 1:
|
||||||
case 2:
|
y--;
|
||||||
z++;
|
break;
|
||||||
break;
|
case 2:
|
||||||
case 3:
|
z++;
|
||||||
y--;
|
break;
|
||||||
break;
|
case 3:
|
||||||
}
|
y--;
|
||||||
|
break;
|
||||||
seq = (seq + 1) & 3;
|
}
|
||||||
|
|
||||||
if(id != 0) {
|
seq = (seq + 1) & 3;
|
||||||
Color[] colors = KzedMap.colors.get(id);
|
|
||||||
if(colors != null) {
|
if(id != 0) {
|
||||||
Color c = colors[seq];
|
Color[] colors = KzedMap.colors.get(id);
|
||||||
if(c.getAlpha() > 0) {
|
if(colors != null) {
|
||||||
/* we found something that isn't transparent! */
|
Color c = colors[seq];
|
||||||
if(c.getAlpha() == 255) {
|
if(c.getAlpha() > 0) {
|
||||||
/* it's opaque - the ray ends here */
|
/* we found something that isn't transparent! */
|
||||||
return c;
|
if(c.getAlpha() == 255) {
|
||||||
}
|
/* it's opaque - the ray ends here */
|
||||||
|
return c;
|
||||||
/* this block is transparent, so recurse */
|
}
|
||||||
Color bg = scan(world, x, y, z, seq);
|
|
||||||
|
/* this block is transparent, so recurse */
|
||||||
int cr = c.getRed();
|
Color bg = scan(world, x, y, z, seq);
|
||||||
int cg = c.getGreen();
|
|
||||||
int cb = c.getBlue();
|
int cr = c.getRed();
|
||||||
int ca = c.getAlpha();
|
int cg = c.getGreen();
|
||||||
cr *= ca;
|
int cb = c.getBlue();
|
||||||
cg *= ca;
|
int ca = c.getAlpha();
|
||||||
cb *= ca;
|
cr *= ca;
|
||||||
int na = 255 - ca;
|
cg *= ca;
|
||||||
|
cb *= ca;
|
||||||
return new Color((bg.getRed() * na + cr) >> 8, (bg.getGreen() * na + cg) >> 8, (bg.getBlue() * na + cb) >> 8);
|
int na = 255 - ca;
|
||||||
}
|
|
||||||
}
|
return new Color((bg.getRed() * na + cr) >> 8, (bg.getGreen() * na + cg) >> 8, (bg.getBlue() * na + cb) >> 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* save rendered tile, update zoom-out tile */
|
}
|
||||||
public void saveTile(KzedMapTile tile, BufferedImage im, String path)
|
|
||||||
{
|
/* save rendered tile, update zoom-out tile */
|
||||||
String tilePath = getPath(tile, path);
|
public void saveTile(KzedMapTile tile, BufferedImage im, String path)
|
||||||
|
{
|
||||||
debugger.debug("saving tile " + tilePath);
|
String tilePath = getPath(tile, path);
|
||||||
|
|
||||||
/* save image */
|
debugger.debug("saving tile " + tilePath);
|
||||||
try {
|
|
||||||
File file = new File(tilePath);
|
/* save image */
|
||||||
ImageIO.write(im, "png", file);
|
try {
|
||||||
} catch(IOException e) {
|
File file = new File(tilePath);
|
||||||
debugger.error("Failed to save tile: " + tilePath, e);
|
ImageIO.write(im, "png", file);
|
||||||
} catch(java.lang.NullPointerException e) {
|
} catch(IOException e) {
|
||||||
debugger.error("Failed to save tile (NullPointerException): " + tilePath, e);
|
debugger.error("Failed to save tile: " + tilePath, e);
|
||||||
}
|
} catch(java.lang.NullPointerException e) {
|
||||||
|
debugger.error("Failed to save tile (NullPointerException): " + tilePath, e);
|
||||||
/* now update zoom-out tile */
|
}
|
||||||
/*BufferedImage zIm = mgr.zoomCache.get(zoomPath);
|
|
||||||
|
|
||||||
|
|
||||||
if(zIm == null) {
|
/* now update zoom-out tile */
|
||||||
// zoom-out tile doesn't exist - try to load it from disk
|
/*BufferedImage zIm = mgr.zoomCache.get(zoomPath);
|
||||||
|
|
||||||
mgr.debug("Trying to load zoom-out tile: " + zoomPath);
|
|
||||||
|
if(zIm == null) {
|
||||||
try {
|
// zoom-out tile doesn't exist - try to load it from disk
|
||||||
File file = new File(zoomPath);
|
|
||||||
zIm = ImageIO.read(file);
|
mgr.debug("Trying to load zoom-out tile: " + zoomPath);
|
||||||
} catch(IOException e) {
|
|
||||||
}
|
try {
|
||||||
|
File file = new File(zoomPath);
|
||||||
if(zIm == null) {
|
zIm = ImageIO.read(file);
|
||||||
mgr.debug("Failed to load zoom-out tile: " + zoomPath);
|
} catch(IOException e) {
|
||||||
// create new one
|
}
|
||||||
// TODO: we might use existing tiles that we could load
|
|
||||||
// to fill the zoomed out tile in...
|
if(zIm == null) {
|
||||||
zIm = new BufferedImage(MapManager.tileWidth, MapManager.tileHeight, BufferedImage.TYPE_INT_RGB);
|
mgr.debug("Failed to load zoom-out tile: " + zoomPath);
|
||||||
} else {
|
// create new one
|
||||||
mgr.debug("Loaded zoom-out tile from " + zoomPath);
|
// TODO: we might use existing tiles that we could load
|
||||||
}
|
// to fill the zoomed out tile in...
|
||||||
} else {
|
zIm = new BufferedImage(MapManager.tileWidth, MapManager.tileHeight, BufferedImage.TYPE_INT_RGB);
|
||||||
mgr.debug("Using zoom-out tile from cache: " + zoomPath);
|
} else {
|
||||||
}
|
mgr.debug("Loaded zoom-out tile from " + zoomPath);
|
||||||
|
}
|
||||||
// update zoom-out tile
|
} else {
|
||||||
|
mgr.debug("Using zoom-out tile from cache: " + zoomPath);
|
||||||
// scaled size
|
}
|
||||||
int scw = mgr.tileWidth / 2;
|
|
||||||
int sch = mgr.tileHeight / 2;
|
// update zoom-out tile
|
||||||
|
|
||||||
// origin in zoomed-out tile
|
// scaled size
|
||||||
int ox = scw;
|
int scw = mgr.tileWidth / 2;
|
||||||
int oy = 0;
|
int sch = mgr.tileHeight / 2;
|
||||||
|
|
||||||
if(zpx != px) ox = 0;
|
// origin in zoomed-out tile
|
||||||
if(zpy != py) oy = sch;
|
int ox = scw;
|
||||||
|
int oy = 0;
|
||||||
// blit scaled rendered tile onto zoom-out tile
|
|
||||||
WritableRaster zr = zIm.getRaster();
|
if(zpx != px) ox = 0;
|
||||||
Graphics2D g2 = zIm.createGraphics();
|
if(zpy != py) oy = sch;
|
||||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
|
||||||
g2.drawImage(im, ox, oy, scw, sch, null);
|
// blit scaled rendered tile onto zoom-out tile
|
||||||
|
WritableRaster zr = zIm.getRaster();
|
||||||
// update zoom-out tile cache
|
Graphics2D g2 = zIm.createGraphics();
|
||||||
BufferedImage oldIm = mgr.zoomCache.put(zoomPath, zIm);
|
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||||
if(oldIm != null && oldIm != zIm) {
|
g2.drawImage(im, ox, oy, scw, sch, null);
|
||||||
oldIm.flush();
|
|
||||||
}
|
// update zoom-out tile cache
|
||||||
|
BufferedImage oldIm = mgr.zoomCache.put(zoomPath, zIm);
|
||||||
// save zoom-out tile
|
if(oldIm != null && oldIm != zIm) {
|
||||||
try {
|
oldIm.flush();
|
||||||
File file = new File(zoomPath);
|
}
|
||||||
ImageIO.write(zIm, "png", file);
|
|
||||||
mgr.debug("saved zoom-out tile at " + zoomPath);
|
// save zoom-out tile
|
||||||
|
try {
|
||||||
//log.info("Saved tile: " + path);
|
File file = new File(zoomPath);
|
||||||
} catch(IOException e) {
|
ImageIO.write(zIm, "png", file);
|
||||||
log.log(Level.SEVERE, "Failed to save zoom-out tile: " + zoomPath, e);
|
mgr.debug("saved zoom-out tile at " + zoomPath);
|
||||||
} catch(java.lang.NullPointerException e) {
|
|
||||||
log.log(Level.SEVERE, "Failed to save zoom-out tile (NullPointerException): " + zoomPath, e);
|
//log.info("Saved tile: " + path);
|
||||||
}*/
|
} catch(IOException e) {
|
||||||
}
|
log.log(Level.SEVERE, "Failed to save zoom-out tile: " + zoomPath, e);
|
||||||
|
} catch(java.lang.NullPointerException e) {
|
||||||
public String getPath(KzedMapTile tile, String outputPath)
|
log.log(Level.SEVERE, "Failed to save zoom-out tile (NullPointerException): " + zoomPath, e);
|
||||||
{
|
}*/
|
||||||
return new File(new File(outputPath), tile.getName() + ".png").getPath();
|
}
|
||||||
}
|
|
||||||
|
public String getPath(KzedMapTile tile, String outputPath)
|
||||||
/* try to load already generated image */
|
{
|
||||||
/*public BufferedImage loadTile(KzedMapTile tile)
|
return new File(new File(outputPath), tile.getName() + ".png").getPath();
|
||||||
{
|
}
|
||||||
try {
|
|
||||||
String path = getPath(tile);
|
/* try to load already generated image */
|
||||||
//log.info("Loading tile from " + path);
|
/*public BufferedImage loadTile(KzedMapTile tile)
|
||||||
File file = new File(path);
|
{
|
||||||
BufferedImage im = ImageIO.read(file);
|
try {
|
||||||
//log.info("OK");
|
String path = getPath(tile);
|
||||||
return im;
|
//log.info("Loading tile from " + path);
|
||||||
} catch(IOException e) {
|
File file = new File(path);
|
||||||
//log.info("failed: " + e.toString());
|
BufferedImage im = ImageIO.read(file);
|
||||||
}
|
//log.info("OK");
|
||||||
|
return im;
|
||||||
return null;
|
} catch(IOException e) {
|
||||||
}*/
|
//log.info("failed: " + e.toString());
|
||||||
|
}
|
||||||
/*
|
|
||||||
// generate a path name for this map tile
|
return null;
|
||||||
public String getPath(MapManager mgr)
|
}*/
|
||||||
{
|
|
||||||
return mgr.tilepath + "t_" + px + "_" + py + ".png";
|
/*
|
||||||
}
|
// generate a path name for this map tile
|
||||||
|
public String getPath(MapManager mgr)
|
||||||
// generate a path name for the zoomed-out tile
|
{
|
||||||
public String getZoomPath(MapManager mgr)
|
return mgr.tilepath + "t_" + px + "_" + py + ".png";
|
||||||
{
|
}
|
||||||
return mgr.tilepath + "zt_" + zpx + "_" + zpy + ".png";
|
|
||||||
}
|
// generate a path name for the zoomed-out tile
|
||||||
|
public String getZoomPath(MapManager mgr)
|
||||||
// generate a path name for this cave map tile
|
{
|
||||||
public String getCavePath(MapManager mgr)
|
return mgr.tilepath + "zt_" + zpx + "_" + zpy + ".png";
|
||||||
{
|
}
|
||||||
return mgr.tilepath + "ct_" + px + "_" + py + ".png";
|
|
||||||
}
|
// generate a path name for this cave map tile
|
||||||
|
public String getCavePath(MapManager mgr)
|
||||||
// generate a path name for the zoomed-out cave tile
|
{
|
||||||
public String getZoomCavePath(MapManager mgr)
|
return mgr.tilepath + "ct_" + px + "_" + py + ".png";
|
||||||
{
|
}
|
||||||
return mgr.tilepath + "czt_" + zpx + "_" + zpy + ".png";
|
|
||||||
}
|
// generate a path name for the zoomed-out cave tile
|
||||||
*/
|
public String getZoomCavePath(MapManager mgr)
|
||||||
}
|
{
|
||||||
|
return mgr.tilepath + "czt_" + zpx + "_" + zpy + ".png";
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,349 +1,354 @@
|
||||||
package org.dynmap.kzedmap;
|
package org.dynmap.kzedmap;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.dynmap.Map;
|
import org.dynmap.Map;
|
||||||
import org.dynmap.MapManager;
|
import org.dynmap.MapManager;
|
||||||
import org.dynmap.MapTile;
|
import org.dynmap.MapTile;
|
||||||
import org.dynmap.StaleQueue;
|
import org.dynmap.StaleQueue;
|
||||||
import org.dynmap.debug.Debugger;
|
import org.dynmap.debug.Debugger;
|
||||||
|
|
||||||
public class KzedMap extends Map {
|
public class KzedMap extends Map {
|
||||||
/* dimensions of a map tile */
|
/* dimensions of a map tile */
|
||||||
public static final int tileWidth = 128;
|
public static final int tileWidth = 128;
|
||||||
public static final int tileHeight = 128;
|
public static final int tileHeight = 128;
|
||||||
|
|
||||||
/* (logical!) dimensions of a zoomed out map tile
|
/* (logical!) dimensions of a zoomed out map tile
|
||||||
* must be twice the size of the normal tile */
|
* must be twice the size of the normal tile */
|
||||||
public static final int zTileWidth = 256;
|
public static final int zTileWidth = 256;
|
||||||
public static final int zTileHeight = 256;
|
public static final int zTileHeight = 256;
|
||||||
|
|
||||||
/* map x, y, z for projection origin */
|
/* map x, y, z for projection origin */
|
||||||
public static final int anchorx = 0;
|
public static final int anchorx = 0;
|
||||||
public static final int anchory = 127;
|
public static final int anchory = 127;
|
||||||
public static final int anchorz = 0;
|
public static final int anchorz = 0;
|
||||||
|
|
||||||
public static java.util.Map<Integer, Color[]> colors;
|
public static java.util.Map<Integer, Color[]> colors;
|
||||||
MapTileRenderer[] renderers;
|
MapTileRenderer[] renderers;
|
||||||
|
ZoomedTileRenderer zoomrenderer;
|
||||||
public KzedMap(MapManager manager, World world, Debugger debugger) {
|
|
||||||
super(manager, world, debugger);
|
public KzedMap(MapManager manager, World world, Debugger debugger) {
|
||||||
if (colors == null)
|
super(manager, world, debugger);
|
||||||
colors = loadColorSet("colors.txt");
|
if (colors == null)
|
||||||
renderers = new MapTileRenderer[] {
|
colors = loadColorSet("colors.txt");
|
||||||
new DefaultTileRenderer("t", debugger),
|
renderers = new MapTileRenderer[] {
|
||||||
new CaveTileRenderer("ct", debugger)
|
new DefaultTileRenderer("t", debugger),
|
||||||
};
|
new CaveTileRenderer("ct", debugger),
|
||||||
}
|
};
|
||||||
|
zoomrenderer = new ZoomedTileRenderer(debugger);
|
||||||
@Override
|
}
|
||||||
public void touch(Location l) {
|
|
||||||
int x = l.getBlockX();
|
@Override
|
||||||
int y = l.getBlockY();
|
public void touch(Location l) {
|
||||||
int z = l.getBlockZ();
|
int x = l.getBlockX();
|
||||||
|
int y = l.getBlockY();
|
||||||
int dx = x - anchorx;
|
int z = l.getBlockZ();
|
||||||
int dy = y - anchory;
|
|
||||||
int dz = z - anchorz;
|
int dx = x - anchorx;
|
||||||
int px = dx + dz;
|
int dy = y - anchory;
|
||||||
int py = dx - dz - dy;
|
int dz = z - anchorz;
|
||||||
|
int px = dx + dz;
|
||||||
int tx = tilex(px);
|
int py = dx - dz - dy;
|
||||||
int ty = tiley(py);
|
|
||||||
|
int tx = tilex(px);
|
||||||
invalidateTile(tx, ty);
|
int ty = tiley(py);
|
||||||
|
|
||||||
boolean ledge = tilex(px - 4) != tx;
|
invalidateTile(tx, ty);
|
||||||
boolean tedge = tiley(py - 4) != ty;
|
|
||||||
boolean redge = tilex(px + 4) != tx;
|
boolean ledge = tilex(px - 4) != tx;
|
||||||
boolean bedge = tiley(py + 4) != ty;
|
boolean tedge = tiley(py - 4) != ty;
|
||||||
|
boolean redge = tilex(px + 4) != tx;
|
||||||
if(ledge) invalidateTile(tx - tileWidth, ty);
|
boolean bedge = tiley(py + 4) != ty;
|
||||||
if(redge) invalidateTile(tx + tileWidth, ty);
|
|
||||||
if(tedge) invalidateTile(tx, ty - tileHeight);
|
if(ledge) invalidateTile(tx - tileWidth, ty);
|
||||||
if(bedge) invalidateTile(tx, ty + tileHeight);
|
if(redge) invalidateTile(tx + tileWidth, ty);
|
||||||
|
if(tedge) invalidateTile(tx, ty - tileHeight);
|
||||||
if(ledge && tedge) invalidateTile(tx - tileWidth, ty - tileHeight);
|
if(bedge) invalidateTile(tx, ty + tileHeight);
|
||||||
if(ledge && bedge) invalidateTile(tx - tileWidth, ty + tileHeight);
|
|
||||||
if(redge && tedge) invalidateTile(tx + tileWidth, ty - tileHeight);
|
if(ledge && tedge) invalidateTile(tx - tileWidth, ty - tileHeight);
|
||||||
if(redge && bedge) invalidateTile(tx + tileWidth, ty + tileHeight);
|
if(ledge && bedge) invalidateTile(tx - tileWidth, ty + tileHeight);
|
||||||
}
|
if(redge && tedge) invalidateTile(tx + tileWidth, ty - tileHeight);
|
||||||
|
if(redge && bedge) invalidateTile(tx + tileWidth, ty + tileHeight);
|
||||||
public void invalidateTile(int px, int py) {
|
}
|
||||||
for(MapTileRenderer renderer : renderers) {
|
|
||||||
invalidateTile(new KzedMapTile(this, renderer, px, py));
|
public void invalidateTile(int px, int py) {
|
||||||
}
|
for(MapTileRenderer renderer : renderers) {
|
||||||
}
|
invalidateTile(new KzedMapTile(this, renderer, px, py));
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public void render(MapTile tile) {
|
|
||||||
KzedMapTile t = (KzedMapTile)tile;
|
@Override
|
||||||
t.renderer.render(t, getMapManager().tilepath);
|
public void render(MapTile tile) {
|
||||||
}
|
if (tile instanceof KzedZoomedMapTile) {
|
||||||
|
zoomrenderer.render((KzedZoomedMapTile)tile, getMapManager().tilepath);
|
||||||
/* tile X for position x */
|
} else if (tile instanceof KzedMapTile) {
|
||||||
static int tilex(int x)
|
((KzedMapTile)tile).renderer.render((KzedMapTile)tile, getMapManager().tilepath);
|
||||||
{
|
}
|
||||||
if(x < 0)
|
}
|
||||||
return x - (tileWidth + (x % tileWidth));
|
|
||||||
else
|
/* tile X for position x */
|
||||||
return x - (x % tileWidth);
|
static int tilex(int x)
|
||||||
}
|
{
|
||||||
|
if(x < 0)
|
||||||
/* tile Y for position y */
|
return x - (tileWidth + (x % tileWidth));
|
||||||
static int tiley(int y)
|
else
|
||||||
{
|
return x - (x % tileWidth);
|
||||||
if(y < 0)
|
}
|
||||||
return y - (tileHeight + (y % tileHeight));
|
|
||||||
else
|
/* tile Y for position y */
|
||||||
return y - (y % tileHeight);
|
static int tiley(int y)
|
||||||
}
|
{
|
||||||
|
if(y < 0)
|
||||||
/* zoomed-out tile X for tile position x */
|
return y - (tileHeight + (y % tileHeight));
|
||||||
static int ztilex(int x)
|
else
|
||||||
{
|
return y - (y % tileHeight);
|
||||||
if(x < 0)
|
}
|
||||||
return x + x % zTileWidth;
|
|
||||||
else
|
/* zoomed-out tile X for tile position x */
|
||||||
return x - (x % zTileWidth);
|
static int ztilex(int x)
|
||||||
}
|
{
|
||||||
|
if(x < 0)
|
||||||
/* zoomed-out tile Y for tile position y */
|
return x + x % zTileWidth;
|
||||||
static int ztiley(int y)
|
else
|
||||||
{
|
return x - (x % zTileWidth);
|
||||||
if(y < 0)
|
}
|
||||||
return y + y % zTileHeight;
|
|
||||||
//return y - (zTileHeight + (y % zTileHeight));
|
/* zoomed-out tile Y for tile position y */
|
||||||
else
|
static int ztiley(int y)
|
||||||
return y - (y % zTileHeight);
|
{
|
||||||
}
|
if(y < 0)
|
||||||
|
return y + y % zTileHeight;
|
||||||
/*
|
//return y - (zTileHeight + (y % zTileHeight));
|
||||||
// regenerate the entire map, starting at position
|
else
|
||||||
public void regenerate(int x, int y, int z)
|
return y - (y % zTileHeight);
|
||||||
{
|
}
|
||||||
int dx = x - anchorx;
|
|
||||||
int dy = y - anchory;
|
/*
|
||||||
int dz = z - anchorz;
|
// regenerate the entire map, starting at position
|
||||||
int px = dx + dz;
|
public void regenerate(int x, int y, int z)
|
||||||
int py = dx - dz - dy;
|
{
|
||||||
|
int dx = x - anchorx;
|
||||||
int tx = tilex(px);
|
int dy = y - anchory;
|
||||||
int ty = tiley(py);
|
int dz = z - anchorz;
|
||||||
|
int px = dx + dz;
|
||||||
MapTile first = getTileByPosition(tx, ty);
|
int py = dx - dz - dy;
|
||||||
|
|
||||||
Vector<MapTile> open = new Vector<MapTile>();
|
int tx = tilex(px);
|
||||||
open.add(first);
|
int ty = tiley(py);
|
||||||
|
|
||||||
while(open.size() > 0) {
|
MapTile first = getTileByPosition(tx, ty);
|
||||||
MapTile t = open.remove(open.size() - 1);
|
|
||||||
if(t.stale) continue;
|
Vector<MapTile> open = new Vector<MapTile>();
|
||||||
int h = world.getHighestBlockYAt(t.mx, t.mz);
|
open.add(first);
|
||||||
|
|
||||||
log.info("walking: " + t.mx + ", " + t.mz + ", h = " + h);
|
while(open.size() > 0) {
|
||||||
if(h < 1)
|
MapTile t = open.remove(open.size() - 1);
|
||||||
continue;
|
if(t.stale) continue;
|
||||||
|
int h = world.getHighestBlockYAt(t.mx, t.mz);
|
||||||
pushStaleTile(t);
|
|
||||||
|
log.info("walking: " + t.mx + ", " + t.mz + ", h = " + h);
|
||||||
open.add(getTileByPosition(t.px + tileWidth, t.py));
|
if(h < 1)
|
||||||
open.add(getTileByPosition(t.px - tileWidth, t.py));
|
continue;
|
||||||
open.add(getTileByPosition(t.px, t.py + tileHeight));
|
|
||||||
open.add(getTileByPosition(t.px, t.py - tileHeight));
|
pushStaleTile(t);
|
||||||
}
|
|
||||||
}
|
open.add(getTileByPosition(t.px + tileWidth, t.py));
|
||||||
|
open.add(getTileByPosition(t.px - tileWidth, t.py));
|
||||||
// regenerate all zoom tiles, starting at position
|
open.add(getTileByPosition(t.px, t.py + tileHeight));
|
||||||
public void regenerateZoom(int x, int y, int z)
|
open.add(getTileByPosition(t.px, t.py - tileHeight));
|
||||||
{
|
}
|
||||||
int dx = x - anchorx;
|
}
|
||||||
int dy = y - anchory;
|
|
||||||
int dz = z - anchorz;
|
// regenerate all zoom tiles, starting at position
|
||||||
int px = dx + dz;
|
public void regenerateZoom(int x, int y, int z)
|
||||||
int py = dx - dz - dy;
|
{
|
||||||
|
int dx = x - anchorx;
|
||||||
int fzpx = ztilex(tilex(px));
|
int dy = y - anchory;
|
||||||
int fzpy = ztiley(tiley(py));
|
int dz = z - anchorz;
|
||||||
|
int px = dx + dz;
|
||||||
class Pair implements Comparator {
|
int py = dx - dz - dy;
|
||||||
public int x;
|
|
||||||
public int y;
|
int fzpx = ztilex(tilex(px));
|
||||||
public Pair(int x, int y)
|
int fzpy = ztiley(tiley(py));
|
||||||
{
|
|
||||||
this.x = x;
|
class Pair implements Comparator {
|
||||||
this.y = y;
|
public int x;
|
||||||
}
|
public int y;
|
||||||
|
public Pair(int x, int y)
|
||||||
public int hashCode()
|
{
|
||||||
{
|
this.x = x;
|
||||||
return (x << 16) ^ y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o)
|
public int hashCode()
|
||||||
{
|
{
|
||||||
Pair p = (Pair) o;
|
return (x << 16) ^ y;
|
||||||
return x == p.x && y == p.y;
|
}
|
||||||
}
|
|
||||||
|
public boolean equals(Object o)
|
||||||
public int compare(Object o1, Object o2)
|
{
|
||||||
{
|
Pair p = (Pair) o;
|
||||||
Pair p1 = (Pair) o1;
|
return x == p.x && y == p.y;
|
||||||
Pair p2 = (Pair) o2;
|
}
|
||||||
if(p1.x < p1.x) return -1;
|
|
||||||
if(p1.x > p1.x) return 1;
|
public int compare(Object o1, Object o2)
|
||||||
if(p1.y < p1.y) return -1;
|
{
|
||||||
if(p1.y > p1.y) return 1;
|
Pair p1 = (Pair) o1;
|
||||||
return 0;
|
Pair p2 = (Pair) o2;
|
||||||
}
|
if(p1.x < p1.x) return -1;
|
||||||
}
|
if(p1.x > p1.x) return 1;
|
||||||
|
if(p1.y < p1.y) return -1;
|
||||||
HashSet<Pair> visited = new HashSet<Pair>();
|
if(p1.y > p1.y) return 1;
|
||||||
Vector<Pair> open = new Vector<Pair>();
|
return 0;
|
||||||
|
}
|
||||||
Pair fp = new Pair(fzpx, fzpy);
|
}
|
||||||
open.add(fp);
|
|
||||||
visited.add(fp);
|
HashSet<Pair> visited = new HashSet<Pair>();
|
||||||
|
Vector<Pair> open = new Vector<Pair>();
|
||||||
while(open.size() > 0) {
|
|
||||||
Pair p = open.remove(open.size() - 1);
|
Pair fp = new Pair(fzpx, fzpy);
|
||||||
|
open.add(fp);
|
||||||
int zpx = p.x;
|
visited.add(fp);
|
||||||
int zpy = p.y;
|
|
||||||
|
while(open.size() > 0) {
|
||||||
log.info("Regenerating zoom tile " + zpx + "," + zpy);
|
Pair p = open.remove(open.size() - 1);
|
||||||
|
|
||||||
int g = regenZoomTile(zpx, zpy);
|
int zpx = p.x;
|
||||||
|
int zpy = p.y;
|
||||||
if(g > 0) {
|
|
||||||
Pair[] np = new Pair[4];
|
log.info("Regenerating zoom tile " + zpx + "," + zpy);
|
||||||
np[0] = new Pair(zpx-zTileWidth, zpy);
|
|
||||||
np[1] = new Pair(zpx+zTileWidth, zpy);
|
int g = regenZoomTile(zpx, zpy);
|
||||||
np[2] = new Pair(zpx, zpy-zTileHeight);
|
|
||||||
np[3] = new Pair(zpx, zpy+zTileHeight);
|
if(g > 0) {
|
||||||
|
Pair[] np = new Pair[4];
|
||||||
for(int i=0; i<4; i++) {
|
np[0] = new Pair(zpx-zTileWidth, zpy);
|
||||||
if(!visited.contains(np[i])) {
|
np[1] = new Pair(zpx+zTileWidth, zpy);
|
||||||
visited.add(np[i]);
|
np[2] = new Pair(zpx, zpy-zTileHeight);
|
||||||
open.add(np[i]);
|
np[3] = new Pair(zpx, zpy+zTileHeight);
|
||||||
}
|
|
||||||
}
|
for(int i=0; i<4; i++) {
|
||||||
}
|
if(!visited.contains(np[i])) {
|
||||||
}
|
visited.add(np[i]);
|
||||||
}
|
open.add(np[i]);
|
||||||
|
}
|
||||||
// regenerate zoom-out tile
|
}
|
||||||
// returns number of valid subtiles
|
}
|
||||||
public int regenZoomTile(int zpx, int zpy)
|
}
|
||||||
{
|
}
|
||||||
int px1 = zpx + tileWidth;
|
|
||||||
int py1 = zpy;
|
// regenerate zoom-out tile
|
||||||
int px2 = zpx;
|
// returns number of valid subtiles
|
||||||
int py2 = py1 + tileHeight;
|
public int regenZoomTile(int zpx, int zpy)
|
||||||
|
{
|
||||||
MapTile t1 = getTileByPosition(px1, py1);
|
int px1 = zpx + tileWidth;
|
||||||
MapTile t2 = getTileByPosition(px2, py1);
|
int py1 = zpy;
|
||||||
MapTile t3 = getTileByPosition(px1, py2);
|
int px2 = zpx;
|
||||||
MapTile t4 = getTileByPosition(px2, py2);
|
int py2 = py1 + tileHeight;
|
||||||
|
|
||||||
BufferedImage im1 = t1.loadTile(this);
|
MapTile t1 = getTileByPosition(px1, py1);
|
||||||
BufferedImage im2 = t2.loadTile(this);
|
MapTile t2 = getTileByPosition(px2, py1);
|
||||||
BufferedImage im3 = t3.loadTile(this);
|
MapTile t3 = getTileByPosition(px1, py2);
|
||||||
BufferedImage im4 = t4.loadTile(this);
|
MapTile t4 = getTileByPosition(px2, py2);
|
||||||
|
|
||||||
BufferedImage zIm = new BufferedImage(MapManager.tileWidth, MapManager.tileHeight, BufferedImage.TYPE_INT_RGB);
|
BufferedImage im1 = t1.loadTile(this);
|
||||||
WritableRaster zr = zIm.getRaster();
|
BufferedImage im2 = t2.loadTile(this);
|
||||||
Graphics2D g2 = zIm.createGraphics();
|
BufferedImage im3 = t3.loadTile(this);
|
||||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
BufferedImage im4 = t4.loadTile(this);
|
||||||
|
|
||||||
int scw = tileWidth / 2;
|
BufferedImage zIm = new BufferedImage(MapManager.tileWidth, MapManager.tileHeight, BufferedImage.TYPE_INT_RGB);
|
||||||
int sch = tileHeight / 2;
|
WritableRaster zr = zIm.getRaster();
|
||||||
|
Graphics2D g2 = zIm.createGraphics();
|
||||||
int good = 0;
|
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||||
|
|
||||||
if(im1 != null) {
|
int scw = tileWidth / 2;
|
||||||
g2.drawImage(im1, 0, 0, scw, sch, null);
|
int sch = tileHeight / 2;
|
||||||
good ++;
|
|
||||||
}
|
int good = 0;
|
||||||
|
|
||||||
if(im2 != null) {
|
if(im1 != null) {
|
||||||
g2.drawImage(im2, scw, 0, scw, sch, null);
|
g2.drawImage(im1, 0, 0, scw, sch, null);
|
||||||
good ++;
|
good ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(im3 != null) {
|
if(im2 != null) {
|
||||||
g2.drawImage(im3, 0, sch, scw, sch, null);
|
g2.drawImage(im2, scw, 0, scw, sch, null);
|
||||||
good ++;
|
good ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(im4 != null) {
|
if(im3 != null) {
|
||||||
g2.drawImage(im4, scw, sch, scw, sch, null);
|
g2.drawImage(im3, 0, sch, scw, sch, null);
|
||||||
good ++;
|
good ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(good == 0) {
|
if(im4 != null) {
|
||||||
return 0;
|
g2.drawImage(im4, scw, sch, scw, sch, null);
|
||||||
}
|
good ++;
|
||||||
|
}
|
||||||
String zPath = t1.getZoomPath(this);
|
|
||||||
// save zoom-out tile
|
if(good == 0) {
|
||||||
try {
|
return 0;
|
||||||
File file = new File(zPath);
|
}
|
||||||
ImageIO.write(zIm, "png", file);
|
|
||||||
log.info("regenZoomTile saved zoom-out tile at " + zPath);
|
String zPath = t1.getZoomPath(this);
|
||||||
} catch(IOException e) {
|
// save zoom-out tile
|
||||||
log.log(Level.SEVERE, "Failed to save zoom-out tile: " + zPath, e);
|
try {
|
||||||
} catch(java.lang.NullPointerException e) {
|
File file = new File(zPath);
|
||||||
log.log(Level.SEVERE, "Failed to save zoom-out tile (NullPointerException): " + zPath, e);
|
ImageIO.write(zIm, "png", file);
|
||||||
}
|
log.info("regenZoomTile saved zoom-out tile at " + zPath);
|
||||||
|
} catch(IOException e) {
|
||||||
return good;
|
log.log(Level.SEVERE, "Failed to save zoom-out tile: " + zPath, e);
|
||||||
}
|
} catch(java.lang.NullPointerException e) {
|
||||||
*/
|
log.log(Level.SEVERE, "Failed to save zoom-out tile (NullPointerException): " + zPath, e);
|
||||||
|
}
|
||||||
public static java.util.Map<Integer, Color[]> loadColorSet(String colorsetpath) {
|
|
||||||
java.util.Map<Integer, Color[]> colors = new HashMap<Integer, Color[]>();
|
return good;
|
||||||
|
}
|
||||||
/* load colorset */
|
*/
|
||||||
File cfile = new File(colorsetpath);
|
|
||||||
|
public static java.util.Map<Integer, Color[]> loadColorSet(String colorsetpath) {
|
||||||
try {
|
java.util.Map<Integer, Color[]> colors = new HashMap<Integer, Color[]>();
|
||||||
Scanner scanner = new Scanner(cfile);
|
|
||||||
int nc = 0;
|
/* load colorset */
|
||||||
while(scanner.hasNextLine()) {
|
File cfile = new File(colorsetpath);
|
||||||
String line = scanner.nextLine();
|
|
||||||
if (line.startsWith("#") || line.equals("")) {
|
try {
|
||||||
continue;
|
Scanner scanner = new Scanner(cfile);
|
||||||
}
|
int nc = 0;
|
||||||
|
while(scanner.hasNextLine()) {
|
||||||
String[] split = line.split("\t");
|
String line = scanner.nextLine();
|
||||||
if (split.length < 17) {
|
if (line.startsWith("#") || line.equals("")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer id = new Integer(split[0]);
|
String[] split = line.split("\t");
|
||||||
|
if (split.length < 17) {
|
||||||
Color[] c = new Color[4];
|
continue;
|
||||||
|
}
|
||||||
/* store colors by raycast sequence number */
|
|
||||||
c[0] = new Color(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]), Integer.parseInt(split[4]));
|
Integer id = new Integer(split[0]);
|
||||||
c[3] = new Color(Integer.parseInt(split[5]), Integer.parseInt(split[6]), Integer.parseInt(split[7]), Integer.parseInt(split[8]));
|
|
||||||
c[1] = new Color(Integer.parseInt(split[9]), Integer.parseInt(split[10]), Integer.parseInt(split[11]), Integer.parseInt(split[12]));
|
Color[] c = new Color[4];
|
||||||
c[2] = new Color(Integer.parseInt(split[13]), Integer.parseInt(split[14]), Integer.parseInt(split[15]), Integer.parseInt(split[16]));
|
|
||||||
|
/* store colors by raycast sequence number */
|
||||||
colors.put(id, c);
|
c[0] = new Color(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]), Integer.parseInt(split[4]));
|
||||||
nc += 1;
|
c[3] = new Color(Integer.parseInt(split[5]), Integer.parseInt(split[6]), Integer.parseInt(split[7]), Integer.parseInt(split[8]));
|
||||||
}
|
c[1] = new Color(Integer.parseInt(split[9]), Integer.parseInt(split[10]), Integer.parseInt(split[11]), Integer.parseInt(split[12]));
|
||||||
scanner.close();
|
c[2] = new Color(Integer.parseInt(split[13]), Integer.parseInt(split[14]), Integer.parseInt(split[15]), Integer.parseInt(split[16]));
|
||||||
} catch(Exception e) {
|
|
||||||
return null;
|
colors.put(id, c);
|
||||||
}
|
nc += 1;
|
||||||
return colors;
|
}
|
||||||
}
|
scanner.close();
|
||||||
}
|
} catch(Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,146 +1,146 @@
|
||||||
package org.dynmap.kzedmap;
|
package org.dynmap.kzedmap;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import org.bukkit.Player;
|
import org.bukkit.Player;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.dynmap.MapTile;
|
import org.dynmap.MapTile;
|
||||||
|
|
||||||
public class KzedMapTile extends MapTile {
|
public class KzedMapTile extends MapTile {
|
||||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
public KzedMap map;
|
public KzedMap map;
|
||||||
|
|
||||||
public MapTileRenderer renderer;
|
public MapTileRenderer renderer;
|
||||||
|
|
||||||
/* projection position */
|
/* projection position */
|
||||||
public int px, py;
|
public int px, py;
|
||||||
|
|
||||||
/* minecraft space origin */
|
/* minecraft space origin */
|
||||||
public int mx, my, mz;
|
public int mx, my, mz;
|
||||||
|
|
||||||
/* create new MapTile */
|
/* create new MapTile */
|
||||||
public KzedMapTile(KzedMap map, MapTileRenderer renderer, int px, int py) {
|
public KzedMapTile(KzedMap map, MapTileRenderer renderer, int px, int py) {
|
||||||
super(map);
|
super(map);
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
this.px = px;
|
this.px = px;
|
||||||
this.py = py;
|
this.py = py;
|
||||||
|
|
||||||
mx = KzedMap.anchorx + px / 2 + py / 2;
|
mx = KzedMap.anchorx + px / 2 + py / 2;
|
||||||
my = KzedMap.anchory;
|
my = KzedMap.anchory;
|
||||||
mz = KzedMap.anchorz + px / 2 - py / 2;
|
mz = KzedMap.anchorz + px / 2 - py / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return renderer.getName() + "_" + px + "_" + py;
|
return renderer.getName() + "_" + px + "_" + py;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* try to get the server to load the relevant chunks */
|
/* try to get the server to load the relevant chunks */
|
||||||
public void loadChunks()
|
public void loadChunks()
|
||||||
{
|
{
|
||||||
int x1 = mx - 64;
|
int x1 = mx - 64;
|
||||||
int x2 = mx + KzedMap.tileWidth / 2 + KzedMap.tileHeight / 2;
|
int x2 = mx + KzedMap.tileWidth / 2 + KzedMap.tileHeight / 2;
|
||||||
|
|
||||||
int z1 = mz - KzedMap.tileHeight / 2;
|
int z1 = mz - KzedMap.tileHeight / 2;
|
||||||
int z2 = mz + KzedMap.tileWidth / 2 + 64;
|
int z2 = mz + KzedMap.tileWidth / 2 + 64;
|
||||||
|
|
||||||
int x, z;
|
int x, z;
|
||||||
|
|
||||||
for(x=x1; x<x2; x+=16) {
|
for(x=x1; x<x2; x+=16) {
|
||||||
for(z=z1; z<z2; z+=16) {
|
for(z=z1; z<z2; z+=16) {
|
||||||
if(!map.getWorld().isChunkLoaded(map.getWorld().getChunkAt(x, z))) {
|
if(!map.getWorld().isChunkLoaded(map.getWorld().getChunkAt(x, z))) {
|
||||||
log.info("chunk not loaded: " + x + ", 0, " + z);
|
log.info("chunk not loaded: " + x + ", 0, " + z);
|
||||||
/*
|
/*
|
||||||
|
|
||||||
try {
|
try {
|
||||||
s.loadChunk(x, 0, z);
|
s.loadChunk(x, 0, z);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
log.log(Level.SEVERE, "Caught exception from loadChunk!", e);
|
log.log(Level.SEVERE, "Caught exception from loadChunk!", e);
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if all relevant chunks are loaded */
|
/* check if all relevant chunks are loaded */
|
||||||
public boolean isMapLoaded()
|
public boolean isMapLoaded()
|
||||||
{
|
{
|
||||||
int x1 = mx - KzedMap.tileHeight / 2;
|
int x1 = mx - KzedMap.tileHeight / 2;
|
||||||
int x2 = mx + KzedMap.tileWidth / 2 + KzedMap.tileHeight / 2;
|
int x2 = mx + KzedMap.tileWidth / 2 + KzedMap.tileHeight / 2;
|
||||||
|
|
||||||
int z1 = mz - KzedMap.tileHeight / 2;
|
int z1 = mz - KzedMap.tileHeight / 2;
|
||||||
int z2 = mz + KzedMap.tileWidth / 2 + 64;
|
int z2 = mz + KzedMap.tileWidth / 2 + 64;
|
||||||
|
|
||||||
int x, z;
|
int x, z;
|
||||||
|
|
||||||
for(x=x1; x<x2; x+=16) {
|
for(x=x1; x<x2; x+=16) {
|
||||||
for(z=z1; z<z2; z+=16) {
|
for(z=z1; z<z2; z+=16) {
|
||||||
if(!map.getWorld().isChunkLoaded(map.getWorld().getChunkAt(x, z))) {
|
if(!map.getWorld().isChunkLoaded(map.getWorld().getChunkAt(x, z))) {
|
||||||
// Will try to load chunk.
|
// Will try to load chunk.
|
||||||
//log.info("chunk not loaded: " + x + ", " + z + " for tile " + this.toString());
|
//log.info("chunk not loaded: " + x + ", " + z + " for tile " + this.toString());
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Sometimes give very heavy serverload:
|
// Sometimes give very heavy serverload:
|
||||||
/*try {
|
/*try {
|
||||||
s.loadChunk(x, 0, z);
|
s.loadChunk(x, 0, z);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
log.log(Level.SEVERE, "Caught exception from loadChunk!", e);
|
log.log(Level.SEVERE, "Caught exception from loadChunk!", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!s.isChunkLoaded(x, 0, z)) {
|
if(!s.isChunkLoaded(x, 0, z)) {
|
||||||
log.info("Could not load chunk: " + x + ", " + z + " for tile " + this.toString());
|
log.info("Could not load chunk: " + x + ", " + z + " for tile " + this.toString());
|
||||||
return false;
|
return false;
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get key by projection position */
|
/* get key by projection position */
|
||||||
public static long key(int px, int py)
|
public static long key(int px, int py)
|
||||||
{
|
{
|
||||||
long lpx = (long) px;
|
long lpx = (long) px;
|
||||||
long lpy = (long) py;
|
long lpy = (long) py;
|
||||||
|
|
||||||
return ((lpx & (long) 0xffffffffL) << 32) | (lpy & (long) 0xffffffffL);
|
return ((lpx & (long) 0xffffffffL) << 32) | (lpy & (long) 0xffffffffL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hash value, based on projection position */
|
/* hash value, based on projection position */
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return ((px << 16) ^ py) ^ getName().hashCode();
|
return ((px << 16) ^ py) ^ getName().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj instanceof KzedMapTile) {
|
if (obj instanceof KzedMapTile) {
|
||||||
return equals((KzedMapTile)obj);
|
return equals((KzedMapTile)obj);
|
||||||
}
|
}
|
||||||
return super.equals(obj);
|
return super.equals(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* equality comparison - based on projection position */
|
/* equality comparison - based on projection position */
|
||||||
public boolean equals(KzedMapTile o)
|
public boolean equals(KzedMapTile o)
|
||||||
{
|
{
|
||||||
return o.getName().equals(getName()) && o.px == px && o.py == py;
|
return o.getName().equals(getName()) && o.px == px && o.py == py;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return a simple string representation... */
|
/* return a simple string representation... */
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return getName() + "_" + px + "_" + py;
|
return getName() + "_" + px + "_" + py;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
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.width = config.zoomSize[zoom] + 'px';
|
||||||
img.style.height = 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" : "";
|
var pfx = caveMode ? "c" : "";
|
||||||
|
|
||||||
if(zoom > 0) {
|
if(zoom > 0) {
|
||||||
var tilename = pfx + "t_" + (- coord.x * config.tileWidth) + '_' + coord.y * config.tileHeight;
|
var tilename = pfx + "t_" + (- coord.x * config.tileWidth) + '_' + coord.y * config.tileHeight;
|
||||||
} else {
|
} 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;
|
tileDict[tilename] = img;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue