Performance tuning, improve workaround for bukkit scheduler bugs
This commit is contained in:
parent
b51bb22b9e
commit
2c16c800e9
14 changed files with 412 additions and 303 deletions
|
|
@ -14,6 +14,7 @@ import org.dynmap.DynmapChunk;
|
|||
import org.dynmap.DynmapPlugin;
|
||||
import org.dynmap.DynmapWorld;
|
||||
import org.dynmap.Log;
|
||||
import org.dynmap.utils.MapIterator.BlockStep;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -42,13 +43,18 @@ public class LegacyMapChunkCache implements MapChunkCache {
|
|||
|
||||
private LegacyChunkSnapshot[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
|
||||
|
||||
private static final BlockStep unstep[] = { BlockStep.X_MINUS, BlockStep.Y_MINUS, BlockStep.Z_MINUS,
|
||||
BlockStep.X_PLUS, BlockStep.Y_PLUS, BlockStep.Z_PLUS };
|
||||
|
||||
/**
|
||||
* Iterator for traversing map chunk cache (base is for non-snapshot)
|
||||
*/
|
||||
public class OurMapIterator implements MapIterator {
|
||||
private int x, y, z;
|
||||
private LegacyChunkSnapshot snap;
|
||||
|
||||
private BlockStep laststep;
|
||||
private int typeid;
|
||||
|
||||
OurMapIterator(int x0, int y0, int z0) {
|
||||
initialize(x0, y0, z0);
|
||||
}
|
||||
|
|
@ -61,9 +67,13 @@ public class LegacyMapChunkCache implements MapChunkCache {
|
|||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
laststep = BlockStep.Y_MINUS;
|
||||
typeid = -1;
|
||||
}
|
||||
public final int getBlockTypeID() {
|
||||
return snap.getBlockTypeId(x & 0xF, y, z & 0xF);
|
||||
if(typeid < 0)
|
||||
typeid = snap.getBlockTypeId(x & 0xF, y, z & 0xF);
|
||||
return typeid;
|
||||
}
|
||||
public final int getBlockData() {
|
||||
return snap.getBlockData(x & 0xF, y, z & 0xF);
|
||||
|
|
@ -86,55 +96,76 @@ public class LegacyMapChunkCache implements MapChunkCache {
|
|||
public double getRawBiomeRainfall() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public final void incrementX() {
|
||||
x++;
|
||||
if((x & 0xF) == 0) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
/**
|
||||
* Step current position in given direction
|
||||
*/
|
||||
public final void stepPosition(BlockStep step) {
|
||||
switch(step) {
|
||||
case X_PLUS:
|
||||
x++;
|
||||
if((x & 0xF) == 0) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case X_MINUS:
|
||||
x--;
|
||||
if((x & 0xF) == 15) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Y_PLUS:
|
||||
y++;
|
||||
break;
|
||||
case Y_MINUS:
|
||||
y--;
|
||||
break;
|
||||
case Z_PLUS:
|
||||
z++;
|
||||
if((z & 0xF) == 0) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Z_MINUS:
|
||||
z--;
|
||||
if((z & 0xF) == 15) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
laststep = step;
|
||||
typeid = -1;
|
||||
}
|
||||
public final void decrementX() {
|
||||
x--;
|
||||
if((x & 0xF) == 15) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
public final void incrementY() {
|
||||
y++;
|
||||
}
|
||||
public final void decrementY() {
|
||||
y--;
|
||||
}
|
||||
public final void incrementZ() {
|
||||
z++;
|
||||
if((z & 0xF) == 0) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
public final void decrementZ() {
|
||||
z--;
|
||||
if((z & 0xF) == 15) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Unstep current position to previous position
|
||||
*/
|
||||
public BlockStep unstepPosition() {
|
||||
BlockStep ls = laststep;
|
||||
stepPosition(unstep[ls.ordinal()]);
|
||||
return ls;
|
||||
}
|
||||
public final void setY(int y) {
|
||||
if(y > this.y)
|
||||
laststep = BlockStep.Y_PLUS;
|
||||
else
|
||||
laststep = BlockStep.Y_PLUS;
|
||||
this.y = y;
|
||||
typeid = -1;
|
||||
}
|
||||
public final int getX() {
|
||||
return x;
|
||||
|
|
@ -145,12 +176,28 @@ public class LegacyMapChunkCache implements MapChunkCache {
|
|||
public final int getZ() {
|
||||
return z;
|
||||
}
|
||||
public final int getBlockTypeIDAbove() {
|
||||
if(y < 127)
|
||||
return snap.getBlockTypeId(x & 0xF, y+1, z & 0xF);
|
||||
public final int getBlockTypeIDAt(BlockStep s) {
|
||||
if(s == BlockStep.Y_MINUS) {
|
||||
if(y > 0)
|
||||
return snap.getBlockTypeId(x & 0xF, y-1, z & 0xF);
|
||||
}
|
||||
else if(s == BlockStep.Y_PLUS) {
|
||||
if(y < 127)
|
||||
return snap.getBlockTypeId(x & 0xF, y+1, z & 0xF);
|
||||
}
|
||||
else {
|
||||
BlockStep ls = laststep;
|
||||
stepPosition(s);
|
||||
int tid = snap.getBlockTypeId(x & 0xF, y, z & 0xF);
|
||||
unstepPosition();
|
||||
laststep = ls;
|
||||
return tid;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public BlockStep getLastStep() {
|
||||
return laststep;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,6 +6,15 @@ import org.bukkit.block.Biome;
|
|||
* Iterator for traversing map chunk cache (base is for non-snapshot)
|
||||
*/
|
||||
public interface MapIterator {
|
||||
/* Represents last step of movement of the ray (don't alter order here - ordinal sensitive) */
|
||||
public enum BlockStep {
|
||||
X_PLUS,
|
||||
Y_PLUS,
|
||||
Z_PLUS,
|
||||
X_MINUS,
|
||||
Y_MINUS,
|
||||
Z_MINUS;
|
||||
};
|
||||
/**
|
||||
* Initialize iterator at given coordinates
|
||||
*
|
||||
|
|
@ -53,29 +62,13 @@ public interface MapIterator {
|
|||
*/
|
||||
public double getRawBiomeRainfall();
|
||||
/**
|
||||
* Increment X of current position
|
||||
* Step current position in given direction
|
||||
*/
|
||||
void incrementX();
|
||||
void stepPosition(BlockStep step);
|
||||
/**
|
||||
* Decrement X of current position
|
||||
* Unstep current position to previous position : return step to take to return
|
||||
*/
|
||||
void decrementX();
|
||||
/**
|
||||
* Increment Y of current position
|
||||
*/
|
||||
void incrementY();
|
||||
/**
|
||||
* Decrement Y of current position
|
||||
*/
|
||||
void decrementY();
|
||||
/**
|
||||
* Increment Z of current position
|
||||
*/
|
||||
void incrementZ();
|
||||
/**
|
||||
* Decrement Y of current position
|
||||
*/
|
||||
void decrementZ();
|
||||
BlockStep unstepPosition();
|
||||
/**
|
||||
* Set Y coordinate of current position
|
||||
* @param y
|
||||
|
|
@ -94,10 +87,13 @@ public interface MapIterator {
|
|||
*/
|
||||
int getZ();
|
||||
/**
|
||||
* Get block ID at one above current coordinates
|
||||
* Get block ID at 1 step in given direction
|
||||
*
|
||||
* @return block id
|
||||
*/
|
||||
int getBlockTypeIDAbove();
|
||||
|
||||
int getBlockTypeIDAt(BlockStep s);
|
||||
/**
|
||||
* Get last step taken
|
||||
*/
|
||||
BlockStep getLastStep();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import org.dynmap.DynmapPlugin;
|
|||
import org.dynmap.DynmapWorld;
|
||||
import org.dynmap.Log;
|
||||
import org.dynmap.MapManager;
|
||||
import org.dynmap.utils.MapIterator.BlockStep;
|
||||
|
||||
/**
|
||||
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
|
||||
|
|
@ -42,13 +43,18 @@ public class NewMapChunkCache implements MapChunkCache {
|
|||
private boolean isempty = true;
|
||||
|
||||
private ChunkSnapshot[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
|
||||
|
||||
|
||||
private static final BlockStep unstep[] = { BlockStep.X_MINUS, BlockStep.Y_MINUS, BlockStep.Z_MINUS,
|
||||
BlockStep.X_PLUS, BlockStep.Y_PLUS, BlockStep.Z_PLUS };
|
||||
|
||||
/**
|
||||
* Iterator for traversing map chunk cache (base is for non-snapshot)
|
||||
*/
|
||||
public class OurMapIterator implements MapIterator {
|
||||
private int x, y, z;
|
||||
private int x, y, z, chunkindex, bx, bz;
|
||||
private ChunkSnapshot snap;
|
||||
private BlockStep laststep;
|
||||
private int typeid = -1;
|
||||
|
||||
OurMapIterator(int x0, int y0, int z0) {
|
||||
initialize(x0, y0, z0);
|
||||
|
|
@ -57,84 +63,125 @@ public class NewMapChunkCache implements MapChunkCache {
|
|||
this.x = x0;
|
||||
this.y = y0;
|
||||
this.z = z0;
|
||||
this.chunkindex = ((x >> 4) - x_min) + (((z >> 4) - z_min) * x_dim);
|
||||
this.bx = x & 0xF;
|
||||
this.bz = z & 0xF;
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
snap = snaparray[chunkindex];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
laststep = BlockStep.Y_MINUS;
|
||||
typeid = -1;
|
||||
}
|
||||
public final int getBlockTypeID() {
|
||||
return snap.getBlockTypeId(x & 0xF, y, z & 0xF);
|
||||
if(typeid < 0)
|
||||
typeid = snap.getBlockTypeId(bx, y, bz);
|
||||
return typeid;
|
||||
}
|
||||
public final int getBlockData() {
|
||||
return snap.getBlockData(x & 0xF, y, z & 0xF);
|
||||
return snap.getBlockData(bx, y, bz);
|
||||
}
|
||||
public final int getHighestBlockYAt() {
|
||||
return snap.getHighestBlockYAt(x & 0xF, z & 0xF);
|
||||
return snap.getHighestBlockYAt(bx, bz);
|
||||
}
|
||||
public final int getBlockSkyLight() {
|
||||
return snap.getBlockSkyLight(x & 0xF, y, z & 0xF);
|
||||
return snap.getBlockSkyLight(bx, y, bz);
|
||||
}
|
||||
public final int getBlockEmittedLight() {
|
||||
return snap.getBlockEmittedLight(x & 0xF, y, z & 0xF);
|
||||
return snap.getBlockEmittedLight(bx, y, bz);
|
||||
}
|
||||
public Biome getBiome() {
|
||||
return snap.getBiome(x & 0xF, z & 0xF);
|
||||
return snap.getBiome(bx, bz);
|
||||
}
|
||||
public double getRawBiomeTemperature() {
|
||||
return snap.getRawBiomeTemperature(x & 0xf, z & 0xf);
|
||||
return snap.getRawBiomeTemperature(bx, bz);
|
||||
}
|
||||
public double getRawBiomeRainfall() {
|
||||
return snap.getRawBiomeRainfall(x & 0xf, z & 0xf);
|
||||
return snap.getRawBiomeRainfall(bx, bz);
|
||||
}
|
||||
public final void incrementX() {
|
||||
x++;
|
||||
if((x & 0xF) == 0) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
/**
|
||||
* Step current position in given direction
|
||||
*/
|
||||
public final void stepPosition(BlockStep step) {
|
||||
switch(step.ordinal()) {
|
||||
case 0:
|
||||
x++;
|
||||
bx++;
|
||||
if(bx == 16) { /* Next chunk? */
|
||||
try {
|
||||
bx = 0;
|
||||
chunkindex++;
|
||||
snap = snaparray[chunkindex];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
y++;
|
||||
break;
|
||||
case 2:
|
||||
z++;
|
||||
bz++;
|
||||
if(bz == 16) { /* Next chunk? */
|
||||
try {
|
||||
bz = 0;
|
||||
chunkindex += x_dim;
|
||||
snap = snaparray[chunkindex];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
x--;
|
||||
bx--;
|
||||
if(bx == -1) { /* Next chunk? */
|
||||
try {
|
||||
bx = 15;
|
||||
chunkindex--;
|
||||
snap = snaparray[chunkindex];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
y--;
|
||||
break;
|
||||
case 5:
|
||||
z--;
|
||||
bz--;
|
||||
if(bz == -1) { /* Next chunk? */
|
||||
try {
|
||||
bz = 15;
|
||||
chunkindex -= x_dim;
|
||||
snap = snaparray[chunkindex];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
laststep = step;
|
||||
typeid = -1;
|
||||
}
|
||||
public final void decrementX() {
|
||||
x--;
|
||||
if((x & 0xF) == 15) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
public final void incrementY() {
|
||||
y++;
|
||||
}
|
||||
public final void decrementY() {
|
||||
y--;
|
||||
}
|
||||
public final void incrementZ() {
|
||||
z++;
|
||||
if((z & 0xF) == 0) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
public final void decrementZ() {
|
||||
z--;
|
||||
if((z & 0xF) == 15) { /* Next chunk? */
|
||||
try {
|
||||
snap = snaparray[((x>>4) - x_min) + ((z>>4) - z_min) * x_dim];
|
||||
} catch (ArrayIndexOutOfBoundsException aioobx) {
|
||||
snap = EMPTY;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Unstep current position to previous position
|
||||
*/
|
||||
public BlockStep unstepPosition() {
|
||||
BlockStep ls = laststep;
|
||||
stepPosition(unstep[ls.ordinal()]);
|
||||
return ls;
|
||||
}
|
||||
public final void setY(int y) {
|
||||
if(y > this.y)
|
||||
laststep = BlockStep.Y_PLUS;
|
||||
else
|
||||
laststep = BlockStep.Y_PLUS;
|
||||
this.y = y;
|
||||
typeid = -1;
|
||||
}
|
||||
public final int getX() {
|
||||
return x;
|
||||
|
|
@ -145,11 +192,28 @@ public class NewMapChunkCache implements MapChunkCache {
|
|||
public final int getZ() {
|
||||
return z;
|
||||
}
|
||||
public final int getBlockTypeIDAbove() {
|
||||
if(y < 127)
|
||||
return snap.getBlockTypeId(x & 0xF, y+1, z & 0xF);
|
||||
public final int getBlockTypeIDAt(BlockStep s) {
|
||||
if(s == BlockStep.Y_MINUS) {
|
||||
if(y > 0)
|
||||
return snap.getBlockTypeId(bx, y-1, bz);
|
||||
}
|
||||
else if(s == BlockStep.Y_PLUS) {
|
||||
if(y < 127)
|
||||
return snap.getBlockTypeId(bx, y+1, bz);
|
||||
}
|
||||
else {
|
||||
BlockStep ls = laststep;
|
||||
stepPosition(s);
|
||||
int tid = snap.getBlockTypeId(bx, y, bz);
|
||||
unstepPosition();
|
||||
laststep = ls;
|
||||
return tid;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public BlockStep getLastStep() {
|
||||
return laststep;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue