Tune performance on map iterator

This commit is contained in:
Mike Primm 2013-04-26 21:44:29 -05:00
parent e7efbe193a
commit a2ab8c4f2f

View File

@ -43,6 +43,7 @@ public class NewMapChunkCache implements MapChunkCache {
private List<VisibilityLimit> visible_limits = null; private List<VisibilityLimit> visible_limits = null;
private List<VisibilityLimit> hidden_limits = null; private List<VisibilityLimit> hidden_limits = null;
private boolean isempty = true; private boolean isempty = true;
private int snapcnt;
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 DynIntHashMap[] snaptile; private DynIntHashMap[] snaptile;
private byte[][] sameneighborbiomecnt; private byte[][] sameneighborbiomecnt;
@ -88,6 +89,7 @@ public class NewMapChunkCache implements MapChunkCache {
initialize(x0, y0, z0); initialize(x0, y0, z0);
worldheight = w.getMaxHeight(); worldheight = w.getMaxHeight();
} }
@Override @Override
public final void initialize(int x0, int y0, int z0) { public final void initialize(int x0, int y0, int z0) {
this.x = x0; this.x = x0;
@ -97,11 +99,11 @@ public class NewMapChunkCache implements MapChunkCache {
this.bx = x & 0xF; this.bx = x & 0xF;
this.bz = z & 0xF; this.bz = z & 0xF;
this.off = bx + (bz << 4); this.off = bx + (bz << 4);
try { if ((chunkindex >= snapcnt) || (chunkindex < 0)) {
snap = snaparray[chunkindex];
} catch (ArrayIndexOutOfBoundsException aioobx) {
snap = EMPTY; snap = EMPTY;
exceptions++; }
else {
snap = snaparray[chunkindex];
} }
laststep = BlockStep.Y_MINUS; laststep = BlockStep.Y_MINUS;
if((y >= 0) && (y < worldheight)) if((y >= 0) && (y < worldheight))
@ -153,10 +155,14 @@ public class NewMapChunkCache implements MapChunkCache {
Object[] biomebase = null; Object[] biomebase = null;
ChunkSnapshot biome_css = null; ChunkSnapshot biome_css = null;
for(int i = 0; i < x_size; i++) { for(int i = 0; i < x_size; i++) {
initialize(i + x_base, 64, z_base);
for(int j = 0; j < z_size; j++) { for(int j = 0; j < z_size; j++) {
BiomeMap bm; BiomeMap bm;
if (j == 0) {
initialize(i + x_base, 64, z_base);
}
else {
stepPosition(BlockStep.Z_PLUS);
}
if(snap != biome_css) { if(snap != biome_css) {
biomebase = null; biomebase = null;
biome_css = snap; biome_css = snap;
@ -196,8 +202,6 @@ public class NewMapChunkCache implements MapChunkCache {
sameneighborbiomecnt[i][j-1]++; sameneighborbiomecnt[i][j-1]++;
} }
sameneighborbiomecnt[i][j] = (byte)cnt; sameneighborbiomecnt[i][j] = (byte)cnt;
stepPosition(BlockStep.Z_PLUS);
} }
} }
} }
@ -385,14 +389,14 @@ public class NewMapChunkCache implements MapChunkCache {
bx++; bx++;
off++; off++;
if(bx == 16) { /* Next chunk? */ if(bx == 16) { /* Next chunk? */
try { bx = 0;
bx = 0; off -= 16;
off -= 16; chunkindex++;
chunkindex++; if ((chunkindex >= snapcnt) || (chunkindex < 0)) {
snap = snaparray[chunkindex];
} catch (ArrayIndexOutOfBoundsException aioobx) {
snap = EMPTY; snap = EMPTY;
exceptions++; }
else {
snap = snaparray[chunkindex];
} }
} }
break; break;
@ -407,14 +411,14 @@ public class NewMapChunkCache implements MapChunkCache {
bz++; bz++;
off+=16; off+=16;
if(bz == 16) { /* Next chunk? */ if(bz == 16) { /* Next chunk? */
try { bz = 0;
bz = 0; off -= 256;
off -= 256; chunkindex += x_dim;
chunkindex += x_dim; if ((chunkindex >= snapcnt) || (chunkindex < 0)) {
snap = snaparray[chunkindex];
} catch (ArrayIndexOutOfBoundsException aioobx) {
snap = EMPTY; snap = EMPTY;
exceptions++; }
else {
snap = snaparray[chunkindex];
} }
} }
break; break;
@ -423,14 +427,14 @@ public class NewMapChunkCache implements MapChunkCache {
bx--; bx--;
off--; off--;
if(bx == -1) { /* Next chunk? */ if(bx == -1) { /* Next chunk? */
try { bx = 15;
bx = 15; off += 16;
off += 16; chunkindex--;
chunkindex--; if ((chunkindex >= snapcnt) || (chunkindex < 0)) {
snap = snaparray[chunkindex];
} catch (ArrayIndexOutOfBoundsException aioobx) {
snap = EMPTY; snap = EMPTY;
exceptions++; }
else {
snap = snaparray[chunkindex];
} }
} }
break; break;
@ -445,14 +449,14 @@ public class NewMapChunkCache implements MapChunkCache {
bz--; bz--;
off-=16; off-=16;
if(bz == -1) { /* Next chunk? */ if(bz == -1) { /* Next chunk? */
try { bz = 15;
bz = 15; off += 256;
off += 256; chunkindex -= x_dim;
chunkindex -= x_dim; if ((chunkindex >= snapcnt) || (chunkindex < 0)) {
snap = snaparray[chunkindex];
} catch (ArrayIndexOutOfBoundsException aioobx) {
snap = EMPTY; snap = EMPTY;
exceptions++; }
else {
snap = snaparray[chunkindex];
} }
} }
break; break;
@ -773,7 +777,7 @@ public class NewMapChunkCache implements MapChunkCache {
x_dim = x_max - x_min + 1; x_dim = x_max - x_min + 1;
} }
int snapcnt = x_dim * (z_max-z_min+1); snapcnt = x_dim * (z_max-z_min+1);
snaparray = new ChunkSnapshot[snapcnt]; snaparray = new ChunkSnapshot[snapcnt];
snaptile = new DynIntHashMap[snapcnt]; snaptile = new DynIntHashMap[snapcnt];
isSectionNotEmpty = new boolean[snapcnt][]; isSectionNotEmpty = new boolean[snapcnt][];