Update to 1.2 biome shading model (1.1 maps will be 1.2-style shaded - sorry)

This commit is contained in:
Mike Primm 2012-03-11 16:17:32 -05:00
parent 2628559b55
commit ef0ad40496

View File

@ -51,7 +51,7 @@ public class NewMapChunkCache implements MapChunkCache {
private boolean do_save = false; private boolean do_save = false;
private boolean isempty = true; private boolean isempty = true;
private ChunkSnapshot[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */ private ChunkSnapshot[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
private byte[][] swampcnt; private byte[][] sameneighborbiomecnt;
private BiomeMap[][] biomemap; private BiomeMap[][] biomemap;
private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */ private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */
@ -121,35 +121,47 @@ public class NewMapChunkCache implements MapChunkCache {
return snap.getBlockEmittedLight(bx, y, bz); return snap.getBlockEmittedLight(bx, y, bz);
} }
private void biomePrep() { private void biomePrep() {
if(swampcnt != null) if(sameneighborbiomecnt != null)
return; return;
int x_size = x_dim << 4; int x_size = x_dim << 4;
int z_size = (z_max - z_min + 1) << 4; int z_size = (z_max - z_min + 1) << 4;
swampcnt = new byte[x_size][]; sameneighborbiomecnt = new byte[x_size][];
biomemap = new BiomeMap[x_size][]; biomemap = new BiomeMap[x_size][];
for(int i = 0; i < x_size; i++) { for(int i = 0; i < x_size; i++) {
swampcnt[i] = new byte[z_size]; sameneighborbiomecnt[i] = new byte[z_size];
biomemap[i] = new BiomeMap[z_size]; biomemap[i] = new BiomeMap[z_size];
} }
for(int i = 0; i < x_size; i++) { for(int i = 0; i < x_size; i++) {
initialize(i + x_base, 64, z_base); initialize(i + x_base, 64, z_base);
for(int j = 0; j < z_size; j++) { for(int j = 0; j < z_size; j++) {
Biome bb = snap.getBiome(bx, bz); Biome bb = snap.getBiome(bx, bz);
BiomeMap bm;
if(bb == null) if(bb == null)
biomemap[i][j] = BiomeMap.NULL; bm = BiomeMap.NULL;
else else
biomemap[i][j] = biome_to_bmap[bb.ordinal()]; bm = biome_to_bmap[bb.ordinal()];
if(biomemap[i][j] == BiomeMap.SWAMPLAND) { biomemap[i][j] = bm;
for(int ii = i-1; ii < i+2; ii++) { int cnt = 0;
for(int jj = j-1; jj < j+2; jj++) { if(i > 0) {
if(ii < 0) continue; if(bm == biomemap[i-1][j]) { /* Same as one to left */
if(jj < 0) continue; cnt++;
if(ii >= x_size) continue; sameneighborbiomecnt[i-1][j]++;
if(jj >= z_size) continue; }
swampcnt[ii][jj]++; if((j > 0) && (bm == biomemap[i-1][j-1])) {
} cnt++;
sameneighborbiomecnt[i-1][j-1]++;
}
if((j < (z_size-1)) && (bm == biomemap[i-1][j+1])) {
cnt++;
sameneighborbiomecnt[i-1][j+1]++;
} }
} }
if((j > 0) && (biomemap[i][j] == biomemap[i][j-1])) { /* Same as one to above */
cnt++;
sameneighborbiomecnt[i][j-1]++;
}
sameneighborbiomecnt[i][j] = (byte)cnt;
stepPosition(BlockStep.Z_PLUS); stepPosition(BlockStep.Z_PLUS);
} }
} }
@ -163,48 +175,123 @@ public class NewMapChunkCache implements MapChunkCache {
} }
} }
public final int countSmoothedSwampBiomes() { private final int getSmoothColorMultiplier(int[] colormap, int width, boolean is_grass) {
int mult = 0xFFFFFF;
try { try {
return swampcnt[x - x_base][z - z_base]; int rx = x - x_base;
} catch (Exception ex) { int rz = z - z_base;
return 0; BiomeMap bm = biomemap[rx][rz];
if(sameneighborbiomecnt[rx][rz] >= (byte)8) { /* All neighbors same? */
mult = colormap[bm.biomeLookup(width)];
}
else {
int raccum = 0;
int gaccum = 0;
int baccum = 0;
for(int xoff = -1; xoff < 2; xoff++) {
for(int zoff = -1; zoff < 2; zoff++) {
bm = biomemap[rx+xoff][rz+zoff];
int rmult = colormap[bm.biomeLookup(width)];
raccum += (rmult >> 16) & 0xFF;
gaccum += (rmult >> 8) & 0xFF;
baccum += rmult & 0xFF;
}
}
mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9);
}
if(is_grass)
return bm.getModifiedGrassMultiplier(mult);
else
return bm.getModifiedFoliageMultiplier(mult);
} catch (Exception x) {
Log.info("exception");
return 0xFFFFFF;
} }
} }
public final int getSmoothGrassColorMultiplier(int[] colormap, int width) {
public final int countSmoothedSwampBiomes(int sx, int sz, int scale) { int mult = 0xFFFFFF;
try { try {
int xx = x - x_base; int rx = x - x_base;
int zz = z - z_base; int rz = z - z_base;
sx <<= 1; BiomeMap bm = biomemap[rx][rz];
sz <<= 1; if(sameneighborbiomecnt[rx][rz] >= (byte)8) { /* All neighbors same? */
int s0 = swampcnt[xx][zz]; mult = bm.getModifiedGrassMultiplier(colormap[bm.biomeLookup(width)]);
int w;
int tot;
if(sx < scale) {
w = scale - sx;
tot = (w * swampcnt[xx-1][zz]) + ((scale - w) * s0);
}
else if(sx > scale) {
w = sx - scale;
tot = (w * swampcnt[xx+1][zz]) + ((scale - w) * s0);
} }
else { else {
tot = scale * s0; int raccum = 0;
int gaccum = 0;
int baccum = 0;
for(int xoff = -1; xoff < 2; xoff++) {
for(int zoff = -1; zoff < 2; zoff++) {
bm = biomemap[rx+xoff][rz+zoff];
int rmult = bm.getModifiedGrassMultiplier(colormap[bm.biomeLookup(width)]);
raccum += (rmult >> 16) & 0xFF;
gaccum += (rmult >> 8) & 0xFF;
baccum += rmult & 0xFF;
}
}
mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9);
} }
if(sz < scale) { } catch (Exception x) {
w = scale - sz; Log.info("exception");
tot += (w * swampcnt[xx][zz-1]) + ((scale - w) * s0); mult = 0xFFFFFF;
} }
else if(sz > scale) { return mult;
w = sz - scale; }
tot += (w * swampcnt[xx][zz+1]) + ((scale - w) * s0); public final int getSmoothFoliageColorMultiplier(int[] colormap, int width) {
int mult = 0xFFFFFF;
try {
int rx = x - x_base;
int rz = z - z_base;
BiomeMap bm = biomemap[rx][rz];
if(sameneighborbiomecnt[rx][rz] >= (byte)8) { /* All neighbors same? */
mult = bm.getModifiedFoliageMultiplier(colormap[bm.biomeLookup(width)]);
} }
else { else {
tot += scale * s0; int raccum = 0;
int gaccum = 0;
int baccum = 0;
for(int xoff = -1; xoff < 2; xoff++) {
for(int zoff = -1; zoff < 2; zoff++) {
bm = biomemap[rx+xoff][rz+zoff];
int rmult = bm.getModifiedFoliageMultiplier(colormap[bm.biomeLookup(width)]);
raccum += (rmult >> 16) & 0xFF;
gaccum += (rmult >> 8) & 0xFF;
baccum += rmult & 0xFF;
}
}
mult = ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9);
} }
return tot; } catch (Exception x) {
} catch (Exception ex) { Log.info("exception");
return 0; mult = 0xFFFFFF;
}
return mult;
}
public final int getSmoothWaterColorMultiplier() {
try {
int rx = x - x_base;
int rz = z - z_base;
BiomeMap bm = biomemap[rx][rz];
if(sameneighborbiomecnt[rx][rz] >= (byte)8) { /* All neighbors same? */
return bm.getWaterColorMult();
}
int raccum = 0;
int gaccum = 0;
int baccum = 0;
for(int xoff = -1; xoff < 2; xoff++) {
for(int zoff = -1; zoff < 2; zoff++) {
bm = biomemap[rx+xoff][rz+zoff];
int mult = bm.getWaterColorMult();
raccum += (mult >> 16) & 0xFF;
gaccum += (mult >> 8) & 0xFF;
baccum += mult & 0xFF;
}
}
return ((raccum / 9) << 16) | ((gaccum / 9) << 8) | (baccum / 9);
} catch (Exception x) {
return 0xFFFFFF;
} }
} }