Update biomecolored to support biome-type-based,

biome-temperature-based and biome-rainfail-based shading
This commit is contained in:
Mike Primm 2011-06-20 16:00:28 -05:00
parent edf7d4f5c8
commit 6efbf3a3df
9 changed files with 288 additions and 71 deletions

View file

@ -18,12 +18,16 @@ public class ColorScheme {
public final Color[][] colors; /* [blk-type][step] */
public final Color[][][] datacolors; /* [bkt-type][blk-dat][step] */
public final Color[][] biomecolors; /* [Biome.ordinal][step] */
public final Color[][] raincolors; /* [rain * 63][step] */
public final Color[][] tempcolors; /* [temp * 63][step] */
public ColorScheme(String name, Color[][] colors, Color[][][] datacolors, Color[][] biomecolors) {
public ColorScheme(String name, Color[][] colors, Color[][][] datacolors, Color[][] biomecolors, Color[][] raincolors, Color[][] tempcolors) {
this.name = name;
this.colors = colors;
this.datacolors = datacolors;
this.biomecolors = biomecolors;
this.raincolors = raincolors;
this.tempcolors = tempcolors;
}
private static File getColorSchemeDirectory() {
@ -46,6 +50,9 @@ public class ColorScheme {
Color[][] colors = new Color[256][];
Color[][][] datacolors = new Color[256][][];
Color[][] biomecolors = new Color[Biome.values().length][];
Color[][] raincolors = new Color[64][];
Color[][] tempcolors = new Color[64][];
InputStream stream;
try {
Debug.debug("Loading colors from '" + colorSchemeFile + "'...");
@ -72,6 +79,8 @@ public class ColorScheme {
Integer id;
Integer dat = null;
boolean isbiome = false;
boolean istemp = false;
boolean israin = false;
int idx = split[0].indexOf(':');
if(idx > 0) { /* ID:data - data color */
id = new Integer(split[0].substring(0, idx));
@ -89,6 +98,28 @@ public class ColorScheme {
break;
}
}
if(id < 0) { /* Not biome - check for rain or temp */
if(bio.startsWith("RAINFALL-")) {
try {
double v = Double.parseDouble(bio.substring(9));
if((v >= 0) && (v <= 1.00)) {
id = (int)(v * 63.0);
israin = true;
}
} catch (NumberFormatException nfx) {
}
}
else if(bio.startsWith("TEMPERATURE-")) {
try {
double v = Double.parseDouble(bio.substring(12));
if((v >= 0) && (v <= 1.00)) {
id = (int)(v * 63.0);
istemp = true;
}
} catch (NumberFormatException nfx) {
}
}
}
}
else {
id = new Integer(split[0]);
@ -104,7 +135,13 @@ public class ColorScheme {
c[4] = new Color((c[0].getRed()+c[2].getRed())/2, (c[0].getGreen()+c[2].getGreen())/2, (c[0].getBlue()+c[2].getBlue())/2, (c[0].getAlpha()+c[2].getAlpha())/2);
if(isbiome) {
if((id >= 0) && (id < biomecolors.length))
if(istemp) {
tempcolors[id] = c;
}
else if(israin) {
raincolors[id] = c;
}
else if((id >= 0) && (id < biomecolors.length))
biomecolors[id] = c;
}
else if(dat != null) {
@ -137,12 +174,65 @@ public class ColorScheme {
}
}
}
/* And interpolate any missing rain and temperature colors */
interpolateColorTable(tempcolors);
interpolateColorTable(raincolors);
} catch (RuntimeException e) {
Log.severe("Could not load colors '" + name + "' ('" + colorSchemeFile + "').", e);
return null;
} catch (FileNotFoundException e) {
Log.severe("Could not load colors '" + name + "' ('" + colorSchemeFile + "'): File not found.", e);
}
return new ColorScheme(name, colors, datacolors, biomecolors);
return new ColorScheme(name, colors, datacolors, biomecolors, raincolors, tempcolors);
}
public static void interpolateColorTable(Color[][] c) {
int idx = -1;
for(int k = 0; k < c.length; k++) {
if(c[k] == null) { /* Missing? */
if((idx >= 0) && (k == (c.length-1))) { /* We're last - so fill forward from last color */
for(int kk = idx+1; kk <= k; kk++) {
c[kk] = c[idx];
}
}
/* Skip - will backfill when we find next color */
}
else if(idx == -1) { /* No previous color, just backfill this color */
for(int kk = 0; kk < k; kk++) {
c[kk] = c[k];
}
idx = k; /* This is now last defined color */
}
else { /* Else, interpolate between last idx and this one */
int cnt = c[k].length;
for(int kk = idx+1; kk < k; kk++) {
double interp = (double)(kk-idx)/(double)(k-idx);
Color[] cc = new Color[cnt];
for(int jj = 0; jj < cnt; jj++) {
cc[jj] = new Color(
(int)((1.0-interp)*c[idx][jj].getRed() + interp*c[k][jj].getRed()),
(int)((1.0-interp)*c[idx][jj].getGreen() + interp*c[k][jj].getGreen()),
(int)((1.0-interp)*c[idx][jj].getBlue() + interp*c[k][jj].getBlue()),
(int)((1.0-interp)*c[idx][jj].getAlpha() + interp*c[k][jj].getAlpha()));
}
c[kk] = cc;
}
idx = k;
}
}
}
public Color[] getRainColor(double rain) {
int idx = (int)(rain * 63.0);
if((idx >= 0) && (idx < raincolors.length))
return raincolors[idx];
else
return null;
}
public Color[] getTempColor(double temp) {
int idx = (int)(temp * 63.0);
if((idx >= 0) && (idx < tempcolors.length))
return tempcolors[idx];
else
return null;
}
}

View file

@ -39,7 +39,10 @@ public class DefaultTileRenderer implements MapTileRenderer {
protected int lightscale[]; /* scale skylight level (light = lightscale[skylight] */
protected boolean night_and_day; /* If true, render both day (prefix+'-day') and night (prefix) tiles */
protected boolean transparency; /* Is transparency support active? */
protected boolean biomecolored; /* Use biome for coloring */
public enum BiomeColorOption {
NONE, BIOME, TEMPERATURE, RAINFALL
}
protected BiomeColorOption biomecolored = BiomeColorOption.NONE; /* Use biome for coloring */
@Override
public String getName() {
return name;
@ -83,9 +86,24 @@ public class DefaultTileRenderer implements MapTileRenderer {
colorScheme = ColorScheme.getScheme((String)configuration.get("colorscheme"));
night_and_day = configuration.getBoolean("night-and-day", false);
transparency = configuration.getBoolean("transparency", true); /* Default on */
biomecolored = configuration.getBoolean("biomecolored", false);
String biomeopt = configuration.getString("biomecolored", "none");
if(biomeopt.equals("biome")) {
biomecolored = BiomeColorOption.BIOME;
}
else if(biomeopt.equals("temperature")) {
biomecolored = BiomeColorOption.TEMPERATURE;
}
else if(biomeopt.equals("rainfall")) {
biomecolored = BiomeColorOption.RAINFALL;
}
else {
biomecolored = BiomeColorOption.NONE;
}
}
public boolean isBiomeDataNeeded() { return biomecolored.equals(BiomeColorOption.BIOME); }
public boolean isRawBiomeDataNeeded() {
return biomecolored.equals(BiomeColorOption.RAINFALL) || biomecolored.equals(BiomeColorOption.TEMPERATURE);
}
public boolean isBiomeDataNeeded() { return biomecolored; }
public boolean render(MapChunkCache cache, KzedMapTile tile, File outputFile) {
World world = tile.getWorld();
@ -365,6 +383,8 @@ public class DefaultTileRenderer implements MapTileRenderer {
int lightlevel = 15;
int lightlevel_day = 15;
Biome bio = null;
double rain = 0.0;
double temp = 0.0;
result.setTransparent();
if(result_day != null)
result_day.setTransparent();
@ -386,11 +406,22 @@ public class DefaultTileRenderer implements MapTileRenderer {
isnether = false;
}
if(id != 0) { /* No update needed for air */
if(colorScheme.datacolors[id] != null) { /* If data colored */
data = mapiter.getBlockData();
switch(biomecolored) {
case NONE:
if(colorScheme.datacolors[id] != null) { /* If data colored */
data = mapiter.getBlockData();
}
break;
case BIOME:
bio = mapiter.getBiome();
break;
case RAINFALL:
rain = mapiter.getRawBiomeRainfall();
break;
case TEMPERATURE:
temp = mapiter.getRawBiomeTemperature();
break;
}
if(biomecolored)
bio = mapiter.getBiome();
if((shadowscale != null) && (mapiter.getY() < 127)) {
/* Find light level of previous chunk */
switch(seq) {
@ -448,17 +479,25 @@ public class DefaultTileRenderer implements MapTileRenderer {
result.setColor(highlightColor);
return;
}
Color[] colors;
if(biomecolored) {
if(bio != null)
colors = colorScheme.biomecolors[bio.ordinal()];
else
colors = null;
Color[] colors = null;
switch(biomecolored) {
case NONE:
if(data != 0)
colors = colorScheme.datacolors[id][data];
else
colors = colorScheme.colors[id];
break;
case BIOME:
if(bio != null)
colors = colorScheme.biomecolors[bio.ordinal()];
break;
case RAINFALL:
colors = colorScheme.getRainColor(rain);
break;
case TEMPERATURE:
colors = colorScheme.getTempColor(temp);
break;
}
else if(data != 0)
colors = colorScheme.datacolors[id][data];
else
colors = colorScheme.colors[id];
if (colors != null) {
Color c = colors[seq];
if (c.getAlpha() > 0) {

View file

@ -318,6 +318,14 @@ public class KzedMap extends MapType {
return false;
}
public boolean isRawBiomeDataNeeded() {
for(MapTileRenderer r : renderers) {
if(r.isRawBiomeDataNeeded())
return true;
}
return false;
}
public String getName() {
return "KzedMap";
}

View file

@ -14,4 +14,5 @@ public interface MapTileRenderer {
void buildClientConfiguration(JSONObject worldObject);
boolean isBiomeDataNeeded();
boolean isRawBiomeDataNeeded();
}