Add smooth-biome-shading option (1.1-style swamp biome shading)

This commit is contained in:
Mike Primm 2012-01-23 10:37:27 +08:00 committed by mikeprimm
parent 176b40e373
commit f6d9b62101
2 changed files with 60 additions and 26 deletions

View File

@ -57,7 +57,6 @@ 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 BiomeMap[][] snapbiomes; /* Biome cache - getBiome() is expensive */
private TreeSet<?> ourticklist; private TreeSet<?> ourticklist;
private int chunks_read; /* Number of chunks actually loaded */ private int chunks_read; /* Number of chunks actually loaded */
@ -75,11 +74,14 @@ public class NewMapChunkCache implements MapChunkCache {
* Iterator for traversing map chunk cache (base is for non-snapshot) * Iterator for traversing map chunk cache (base is for non-snapshot)
*/ */
public class OurMapIterator implements MapIterator { public class OurMapIterator implements MapIterator {
private int x, y, z, chunkindex, bx, bz; private int x, y, z, chunkindex, bx, bz, off;
private ChunkSnapshot snap; private ChunkSnapshot snap;
private BlockStep laststep; private BlockStep laststep;
private int typeid = -1; private int typeid = -1;
private int blkdata = -1; private int blkdata = -1;
private int lastbiome_x = Integer.MIN_VALUE, lastbiome_z = Integer.MIN_VALUE;
private BiomeMap lastbiome;
private int lastcountswamp_x = Integer.MIN_VALUE, lastcountswamp_z = Integer.MIN_VALUE, lastcountswamp;
OurMapIterator(int x0, int y0, int z0) { OurMapIterator(int x0, int y0, int z0) {
initialize(x0, y0, z0); initialize(x0, y0, z0);
@ -91,6 +93,7 @@ public class NewMapChunkCache implements MapChunkCache {
this.chunkindex = ((x >> 4) - x_min) + (((z >> 4) - z_min) * x_dim); this.chunkindex = ((x >> 4) - x_min) + (((z >> 4) - z_min) * x_dim);
this.bx = x & 0xF; this.bx = x & 0xF;
this.bz = z & 0xF; this.bz = z & 0xF;
this.off = bx + (bz << 4);
try { try {
snap = snaparray[chunkindex]; snap = snaparray[chunkindex];
} catch (ArrayIndexOutOfBoundsException aioobx) { } catch (ArrayIndexOutOfBoundsException aioobx) {
@ -120,26 +123,56 @@ public class NewMapChunkCache implements MapChunkCache {
return snap.getBlockEmittedLight(bx, y, bz); return snap.getBlockEmittedLight(bx, y, bz);
} }
public final BiomeMap getBiome() { public final BiomeMap getBiome() {
BiomeMap[] b = snapbiomes[chunkindex]; if((x == lastbiome_x) && (z == lastbiome_z)) {
if(b == null) { return lastbiome;
b = snapbiomes[chunkindex] = new BiomeMap[256];
} }
int off = bx + (bz << 4); BiomeMap bio;
BiomeMap bio = b[off];
if(bio == null) {
Biome bb = snap.getBiome(bx, bz); Biome bb = snap.getBiome(bx, bz);
if(bb != null) if(bb != null)
bio = biome_to_bmap[bb.ordinal()]; bio = biome_to_bmap[bb.ordinal()];
else else
bio = BiomeMap.NULL; bio = BiomeMap.NULL;
b[off] = bio; lastbiome_x = x;
} lastbiome_z = z;
lastbiome = bio;
return bio; return bio;
} }
public double getRawBiomeTemperature() { public final int countSmoothedSwampBiomes() {
if((lastcountswamp_x == x) && (lastcountswamp_z == z))
return lastcountswamp;
int cnt = 0;
BlockStep s_bak = laststep;
if(getBiome() == BiomeMap.SWAMPLAND) cnt++;
stepPosition(BlockStep.X_MINUS);
if(getBiome() == BiomeMap.SWAMPLAND) cnt++;
stepPosition(BlockStep.Z_MINUS);
if(getBiome() == BiomeMap.SWAMPLAND) cnt++;
stepPosition(BlockStep.X_PLUS);
if(getBiome() == BiomeMap.SWAMPLAND) cnt++;
stepPosition(BlockStep.X_PLUS);
if(getBiome() == BiomeMap.SWAMPLAND) cnt++;
stepPosition(BlockStep.Z_PLUS);
if(getBiome() == BiomeMap.SWAMPLAND) cnt++;
stepPosition(BlockStep.Z_PLUS);
if(getBiome() == BiomeMap.SWAMPLAND) cnt++;
stepPosition(BlockStep.X_MINUS);
if(getBiome() == BiomeMap.SWAMPLAND) cnt++;
stepPosition(BlockStep.X_MINUS);
if(getBiome() == BiomeMap.SWAMPLAND) cnt++;
stepPosition(BlockStep.X_PLUS);
stepPosition(BlockStep.Z_MINUS);
laststep = s_bak;
lastcountswamp_x = x;
lastcountswamp_z = z;
lastcountswamp = cnt;
return cnt;
}
public final double getRawBiomeTemperature() {
return snap.getRawBiomeTemperature(bx, bz); return snap.getRawBiomeTemperature(bx, bz);
} }
public double getRawBiomeRainfall() { public final double getRawBiomeRainfall() {
return snap.getRawBiomeRainfall(bx, bz); return snap.getRawBiomeRainfall(bx, bz);
} }
/** /**
@ -150,9 +183,11 @@ public class NewMapChunkCache implements MapChunkCache {
case 0: case 0:
x++; x++;
bx++; bx++;
off++;
if(bx == 16) { /* Next chunk? */ if(bx == 16) { /* Next chunk? */
try { try {
bx = 0; bx = 0;
off -= 16;
chunkindex++; chunkindex++;
snap = snaparray[chunkindex]; snap = snaparray[chunkindex];
} catch (ArrayIndexOutOfBoundsException aioobx) { } catch (ArrayIndexOutOfBoundsException aioobx) {
@ -167,9 +202,11 @@ public class NewMapChunkCache implements MapChunkCache {
case 2: case 2:
z++; z++;
bz++; bz++;
off+=16;
if(bz == 16) { /* Next chunk? */ if(bz == 16) { /* Next chunk? */
try { try {
bz = 0; bz = 0;
off -= 256;
chunkindex += x_dim; chunkindex += x_dim;
snap = snaparray[chunkindex]; snap = snaparray[chunkindex];
} catch (ArrayIndexOutOfBoundsException aioobx) { } catch (ArrayIndexOutOfBoundsException aioobx) {
@ -181,9 +218,11 @@ public class NewMapChunkCache implements MapChunkCache {
case 3: case 3:
x--; x--;
bx--; bx--;
off--;
if(bx == -1) { /* Next chunk? */ if(bx == -1) { /* Next chunk? */
try { try {
bx = 15; bx = 15;
off += 16;
chunkindex--; chunkindex--;
snap = snaparray[chunkindex]; snap = snaparray[chunkindex];
} catch (ArrayIndexOutOfBoundsException aioobx) { } catch (ArrayIndexOutOfBoundsException aioobx) {
@ -198,9 +237,11 @@ public class NewMapChunkCache implements MapChunkCache {
case 5: case 5:
z--; z--;
bz--; bz--;
off-=16;
if(bz == -1) { /* Next chunk? */ if(bz == -1) { /* Next chunk? */
try { try {
bz = 15; bz = 15;
off += 256;
chunkindex -= x_dim; chunkindex -= x_dim;
snap = snaparray[chunkindex]; snap = snaparray[chunkindex];
} catch (ArrayIndexOutOfBoundsException aioobx) { } catch (ArrayIndexOutOfBoundsException aioobx) {
@ -486,7 +527,6 @@ public class NewMapChunkCache implements MapChunkCache {
} }
snaparray = new ChunkSnapshot[x_dim * (z_max-z_min+1)]; snaparray = new ChunkSnapshot[x_dim * (z_max-z_min+1)];
snapbiomes = new BiomeMap[x_dim * (z_max-z_min+1)][];
} }
private ChunkSnapshot checkSpoutData(Chunk c, ChunkSnapshot ss) { private ChunkSnapshot checkSpoutData(Chunk c, ChunkSnapshot ss) {

View File

@ -195,6 +195,8 @@ enabletilehash: true
use-generated-textures: true use-generated-textures: true
correct-water-lighting: true correct-water-lighting: true
correct-biome-shading: true correct-biome-shading: true
# To enable smooth biome shading (as done in MC 1.1.0+), set this to true (this does increase render processing about 10%)
smooth-biome-shading: true
# Control loading of player faces (if set to false, skins are never fetched) # Control loading of player faces (if set to false, skins are never fetched)
#fetchskins: false #fetchskins: false
@ -321,14 +323,6 @@ msg:
maptypes: "Map Types" maptypes: "Map Types"
players: "Players" players: "Players"
# NOTE: the 'templates' section is now found in the 'templates' directory
# Templates CAN still be defined in configuration.txt, as before 0.20
templates:
# NOTE: the 'worlds' section is now found in the worlds.txt (example custom settings can be found in worlds.txt.sample)
# Worlds CAN still be defined in configuration.txt, as before 0.20
worlds:
# Set to true to enable verbose startup messages - can help with debugging map configuration problems # Set to true to enable verbose startup messages - can help with debugging map configuration problems
# Set to false for a much quieter startup log # Set to false for a much quieter startup log
verbose: false verbose: false