Get day/night workding with HDMap

This commit is contained in:
Mike Primm 2011-07-05 23:24:25 -05:00
parent 1f2722b249
commit 225b348154
6 changed files with 77 additions and 17 deletions

View File

@ -90,9 +90,9 @@ public class DefaultHDShader implements HDShader {
private Color color = new Color();
private Color daycolor;
protected MapIterator mapiter;
private int seqy; /* For dither */
private Color tmpcolor = new Color();
private Color tmpdaycolor = new Color();
private int pixelodd;
private OurRendererState(MapIterator mapiter) {
this.mapiter = mapiter;
@ -107,10 +107,7 @@ public class DefaultHDShader implements HDShader {
color.setTransparent();
if(daycolor != null)
daycolor.setTransparent();
if(((x+y) & 0x01) == 0x01)
seqy = 0;
else
seqy = 2;
pixelodd = x ^ y;
}
protected Color[] getBlockColors(int blocktype, int blockdata) {
if((blockdata != 0) && (colorScheme.datacolors[blocktype] != null))
@ -139,8 +136,10 @@ public class DefaultHDShader implements HDShader {
seq = 1;
else if((laststep == BlockStep.Z_PLUS) || (laststep == BlockStep.Z_MINUS))
seq = 3;
else if(((mapiter.getX() ^ mapiter.getZ() ^ pixelodd) & 0x01) == 0)
seq = 0;
else
seq = seqy;
seq = 2;
Color c = colors[seq];
if (c.getAlpha() > 0) {
@ -190,14 +189,15 @@ public class DefaultHDShader implements HDShader {
else {
int alpha = color.getAlpha();
int alpha2 = tmpcolor.getAlpha() * (255-alpha) / 255;
color.setRGBA((tmpcolor.getRed()*alpha2 + color.getRed()*alpha) / 255,
(tmpcolor.getGreen()*alpha2 + color.getGreen()*alpha) / 255,
(tmpcolor.getBlue()*alpha2 + color.getBlue()*alpha) / 255, alpha+alpha2);
int talpha = alpha + alpha2;
color.setRGBA((tmpcolor.getRed()*alpha2 + color.getRed()*alpha) / talpha,
(tmpcolor.getGreen()*alpha2 + color.getGreen()*alpha) / talpha,
(tmpcolor.getBlue()*alpha2 + color.getBlue()*alpha) / talpha, talpha);
if(daycolor != null)
daycolor.setRGBA((tmpdaycolor.getRed()*alpha2 + daycolor.getRed()*alpha) / 255,
(tmpdaycolor.getGreen()*alpha2 + daycolor.getGreen()*alpha) / 255,
(tmpdaycolor.getBlue()*alpha2 + daycolor.getBlue()*alpha) / 255, alpha+alpha2);
return (alpha+alpha2) >= 254; /* If only one short, no meaningful contribution left */
daycolor.setRGBA((tmpdaycolor.getRed()*alpha2 + daycolor.getRed()*alpha) / talpha,
(tmpdaycolor.getGreen()*alpha2 + daycolor.getGreen()*alpha) / talpha,
(tmpdaycolor.getBlue()*alpha2 + daycolor.getBlue()*alpha) / talpha, talpha);
return (talpha >= 254); /* If only one short, no meaningful contribution left */
}
}
}
@ -292,6 +292,10 @@ public class DefaultHDShader implements HDShader {
s(o, "title", c.getString("title"));
s(o, "icon", c.getString("icon"));
s(o, "prefix", c.getString("prefix"));
s(o, "background", c.getString("background"));
s(o, "nightandday", c.getBoolean("night-and-day", false));
s(o, "backgroundday", c.getString("backgroundday"));
s(o, "backgroundnight", c.getString("backgroundnight"));
a(worldObject, "maps", o);
}
}

View File

@ -429,11 +429,43 @@ public class HDMap extends MapType {
FileLockManager.releaseWriteLock(f);
renderedone = true;
KzedMap.freeBufferedImage(im[i]);
if(dayim[i] != null)
}
MapManager.mapman.updateStatistics(tile, shadername, true, tile_update, !rendered[i]);
/* Handle day image, if needed */
if(dayim[i] != null) {
f = new File(t.getDynmapWorld().worldtilepath, t.getDayFilename(shadername));
FileLockManager.getWriteLock(f);
shadername = shadername+"_day";
tile_update = false;
try {
if((!f.exists()) || (crc != hashman.getImageHashCode(tile.getKey(), shadername, t.tx, t.ty))) {
/* Wrap buffer as buffered image */
Debug.debug("saving image " + f.getPath());
if(!f.getParentFile().exists())
f.getParentFile().mkdirs();
try {
FileLockManager.imageIOWrite(dayim[i].buf_img, "png", f);
} catch (IOException e) {
Debug.error("Failed to save image: " + f.getPath(), e);
} catch (java.lang.NullPointerException e) {
Debug.error("Failed to save image (NullPointerException): " + f.getPath(), e);
}
MapManager.mapman.pushUpdate(tile.getWorld(), new Client.Tile(f.getPath()));
hashman.updateHashCode(tile.getKey(), shadername, t.tx, t.ty, crc);
tile.getDynmapWorld().enqueueZoomOutUpdate(f);
tile_update = true;
}
else {
Debug.debug("skipping image " + f.getPath() + " - hash match");
}
} finally {
FileLockManager.releaseWriteLock(f);
renderedone = true;
KzedMap.freeBufferedImage(dayim[i]);
}
MapManager.mapman.updateStatistics(tile, shadername, true, tile_update, !rendered[i]);
}
}
MapManager.mapman.updateStatistics(tile, shadername, true, tile_update, !rendered[i]);
}
return renderedone;
}

View File

@ -136,9 +136,15 @@ public class LegacyMapChunkCache implements MapChunkCache {
public final void setY(int y) {
this.y = y;
}
public final int getX() {
return x;
}
public final int getY() {
return y;
}
public final int getZ() {
return z;
}
}
/**

View File

@ -81,8 +81,16 @@ public interface MapIterator {
* @param y
*/
void setY(int y);
/**
* Get X coordinate
*/
int getX();
/**
* Get Y coordinate
*/
int getY();
/**
* Get Z coordinate
*/
int getZ();
}

View File

@ -136,9 +136,15 @@ public class NewMapChunkCache implements MapChunkCache {
public final void setY(int y) {
this.y = y;
}
public final int getX() {
return x;
}
public final int getY() {
return y;
}
public final int getZ() {
return z;
}
}
/**

View File

@ -26,16 +26,20 @@ HDMapType.prototype = $.extend(new DynMapType(), {
var imgSize;
var tileName;
var dnprefix = '';
if(this.dynmap.map.mapTypes[this.dynmap.map.mapTypeId].nightandday && this.dynmap.serverday)
dnprefix = '_day';
var extrazoom = this.dynmap.world.extrazoomout;
if(zoom < extrazoom) {
var scale = 1 << (extrazoom-zoom);
var zprefix = "zzzzzzzzzzzz".substring(0, extrazoom-zoom);
tileName = this.prefix + '/' + ((scale*coord.x) >> 5) + '_' + ((-scale*coord.y) >> 5) +
tileName = this.prefix + dnprefix + '/' + ((scale*coord.x) >> 5) + '_' + ((-scale*coord.y) >> 5) +
'/' + zprefix + "_" + (scale*coord.x) + '_' + (-scale*coord.y) + '.png';
imgSize = 128;
}
else {
tileName = this.prefix + '/' + (coord.x >> 5) + '_' + ((-coord.y) >> 5) +
tileName = this.prefix + dnprefix + '/' + (coord.x >> 5) + '_' + ((-coord.y) >> 5) +
'/' + coord.x + '_' + (-coord.y) + '.png';
imgSize = Math.pow(2, 7+zoom-extrazoom);
}