Tune render performance

This commit is contained in:
Mike Primm 2011-07-25 02:16:00 -05:00
parent cf08f243d0
commit 9e7e333cc5
2 changed files with 152 additions and 154 deletions

View File

@ -96,6 +96,8 @@ public class IsoHDPerspective implements HDPerspective {
Vector3D top, bottom;
int px, py;
BlockStep laststep = BlockStep.Y_MINUS;
BlockStep stepx, stepy, stepz;
/* Raytrace state variables */
double dx, dy, dz;
int x, y, z;
@ -115,6 +117,7 @@ public class IsoHDPerspective implements HDPerspective {
int subalpha;
double mt;
double mtend;
int mxout, myout, mzout;
int[] subblock_xyz = new int[3];
MapIterator mapiter;
@ -238,56 +241,76 @@ public class IsoHDPerspective implements HDPerspective {
/* Compute number of steps and increments for each */
n = 1;
int mxout, myout, mzout;
/* If perpendicular to X axis */
if (dx == 0) {
x_inc = 0;
t_next_x = Double.MAX_VALUE;
stepx = BlockStep.X_PLUS;
mxout = modscale;
}
/* If bottom is right of top */
else if (bottom.x > top.x) {
x_inc = 1;
n += (int) (Math.floor(bottom.x)) - x;
t_next_x = (Math.floor(top.x) + 1 - top.x) * dt_dx;
stepx = BlockStep.X_PLUS;
mxout = modscale;
}
/* Top is right of bottom */
else {
x_inc = -1;
n += x - (int) (Math.floor(bottom.x));
t_next_x = (top.x - Math.floor(top.x)) * dt_dx;
stepx = BlockStep.X_MINUS;
mxout = -1;
}
/* If perpendicular to Y axis */
if (dy == 0) {
y_inc = 0;
t_next_y = Double.MAX_VALUE;
stepy = BlockStep.Y_PLUS;
myout = modscale;
}
/* If bottom is above top */
else if (bottom.y > top.y) {
y_inc = 1;
n += (int) (Math.floor(bottom.y)) - y;
t_next_y = (Math.floor(top.y) + 1 - top.y) * dt_dy;
stepy = BlockStep.Y_PLUS;
myout = modscale;
}
/* If top is above bottom */
else {
y_inc = -1;
n += y - (int) (Math.floor(bottom.y));
t_next_y = (top.y - Math.floor(top.y)) * dt_dy;
stepy = BlockStep.Y_MINUS;
myout = -1;
}
/* If perpendicular to Z axis */
if (dz == 0) {
z_inc = 0;
t_next_z = Double.MAX_VALUE;
stepz = BlockStep.Z_PLUS;
mzout = modscale;
}
/* If bottom right of top */
else if (bottom.z > top.z) {
z_inc = 1;
n += (int) (Math.floor(bottom.z)) - z;
t_next_z = (Math.floor(top.z) + 1 - top.z) * dt_dz;
stepz = BlockStep.Z_PLUS;
mzout = modscale;
}
/* If bottom left of top */
else {
z_inc = -1;
n += z - (int) (Math.floor(bottom.z));
t_next_z = (top.z - Math.floor(top.z)) * dt_dz;
stepz = BlockStep.Z_MINUS;
mzout = -1;
}
/* Walk through scene */
laststep = BlockStep.Y_MINUS; /* Last step is down into map */
@ -363,28 +386,7 @@ public class IsoHDPerspective implements HDPerspective {
return cd.ordinal();
}
/**
* Process visit of ray to block
*/
private boolean visit_block(MapIterator mapiter, HDShaderState[] shaderstate, boolean[] shaderdone) {
lastblocktypeid = blocktypeid;
blocktypeid = mapiter.getBlockTypeID();
if(skiptoair) { /* If skipping until we see air */
if(blocktypeid == 0) /* If air, we're done */
skiptoair = false;
}
else if(nonairhit || (blocktypeid != 0)) {
blockdata = mapiter.getBlockData();
if(blocktypeid == FENCE_BLKTYPEID) { /* Special case for fence - need to fake data so we can render properly */
blockdata = generateFenceBlockData(mapiter);
}
else if(blocktypeid == CHEST_BLKTYPEID) { /* Special case for chest - need to fake data so we can render */
blockdata = generateChestBlockData(mapiter);
}
/* Look up to see if block is modelled */
short[] model = scalemodels.getScaledModel(blocktypeid, blockdata);
if(model != null) {
private final boolean handleSubModel(short[] model, HDShaderState[] shaderstate, boolean[] shaderdone) {
boolean firststep = true;
while(!raytraceSubblock(model, firststep)) {
@ -401,6 +403,34 @@ public class IsoHDPerspective implements HDPerspective {
nonairhit = true;
firststep = false;
}
return false;
}
/**
* Process visit of ray to block
*/
private final boolean visit_block(MapIterator mapiter, HDShaderState[] shaderstate, boolean[] shaderdone) {
lastblocktypeid = blocktypeid;
blocktypeid = mapiter.getBlockTypeID();
if(skiptoair) { /* If skipping until we see air */
if(blocktypeid == 0) /* If air, we're done */
skiptoair = false;
}
else if(nonairhit || (blocktypeid != 0)) {
switch(blocktypeid) {
case FENCE_BLKTYPEID: /* Special case for fence - need to fake data so we can render properly */
blockdata = generateFenceBlockData(mapiter);
break;
case CHEST_BLKTYPEID: /* Special case for chest - need to fake data so we can render */
blockdata = generateChestBlockData(mapiter);
break;
default:
blockdata = mapiter.getBlockData();
break;
}
/* Look up to see if block is modelled */
short[] model = scalemodels.getScaledModel(blocktypeid, blockdata);
if(model != null) {
return handleSubModel(model, shaderstate, shaderdone);
}
else {
boolean done = true;
@ -437,12 +467,7 @@ public class IsoHDPerspective implements HDPerspective {
x += x_inc;
t = t_next_x;
t_next_x += dt_dx;
if(x_inc > 0) {
laststep = BlockStep.X_PLUS;
}
else {
laststep = BlockStep.X_MINUS;
}
laststep = stepx;
mapiter.stepPosition(laststep);
}
/* If Y step is next best */
@ -450,30 +475,17 @@ public class IsoHDPerspective implements HDPerspective {
y += y_inc;
t = t_next_y;
t_next_y += dt_dy;
if(y_inc > 0) {
laststep = BlockStep.Y_PLUS;
laststep = stepy;
mapiter.stepPosition(laststep);
if(mapiter.getY() > 127)
return;
}
else {
laststep = BlockStep.Y_MINUS;
mapiter.stepPosition(laststep);
if(mapiter.getY() < 0)
return;
}
/* If outside 0-127 range */
if((y & (~0x7F)) != 0) return;
}
/* Else, Z step is next best */
else {
z += z_inc;
t = t_next_z;
t_next_z += dt_dz;
if(z_inc > 0) {
laststep = BlockStep.Z_PLUS;
}
else {
laststep = BlockStep.Z_MINUS;
}
laststep = stepz;
mapiter.stepPosition(laststep);
}
}
@ -531,56 +543,32 @@ public class IsoHDPerspective implements HDPerspective {
mx += x_inc;
mt = mt_next_x;
mt_next_x += mdt_dx;
if(x_inc > 0) {
laststep = BlockStep.X_PLUS;
if(mx >= modscale)
laststep = stepx;
if(mx == mxout)
return true;
}
else {
laststep = BlockStep.X_MINUS;
if(mx < 0)
//mx += modscale;
return true;
}
}
/* If Y step is next best */
else if((mt_next_y <= mt_next_x) && (mt_next_y <= mt_next_z)) {
my += y_inc;
mt = mt_next_y;
mt_next_y += mdt_dy;
if(y_inc > 0) {
laststep = BlockStep.Y_PLUS;
if(my >= modscale)
laststep = stepy;
if(my == myout)
return true;
}
else {
laststep = BlockStep.Y_MINUS;
if(my < 0)
//my += modscale;
return true;
}
}
/* Else, Z step is next best */
else {
mz += z_inc;
mt = mt_next_z;
mt_next_z += mdt_dz;
if(z_inc > 0) {
laststep = BlockStep.Z_PLUS;
if(mz >= modscale)
laststep = stepz;
if(mz == mzout)
return true;
}
else {
laststep = BlockStep.Z_MINUS;
if(mz < 0)
//mz += modscale;
return true;
}
}
}
return true;
}
public int[] getSubblockCoord() {
public final int[] getSubblockCoord() {
double tt = t + 0.000001;
if(subalpha >= 0)
tt = mt;

View File

@ -55,9 +55,10 @@ public class TexturePack {
private static final String CUSTOMWATERFLOWING_PNG = "custom_water_flowing.png";
/* Color modifier codes (x1000 for value in mapping code) */
private static final int COLORMOD_NONE = 0;
private static final int COLORMOD_GRASSTONED = 1;
private static final int COLORMOD_FOLIAGETONED = 2;
// private static final int COLORMOD_WATERTONED = 3;
private static final int COLORMOD_WATERTONED = 3; /* Not used */
private static final int COLORMOD_ROT90 = 4;
private static final int COLORMOD_ROT180 = 5;
private static final int COLORMOD_ROT270 = 6;
@ -703,7 +704,7 @@ public class TexturePack {
/**
* Read color for given subblock coordinate, with given block id and data and face
*/
public void readColor(HDPerspectiveState ps, MapIterator mapiter, Color rslt, int blkid, int lastblocktype, boolean biome_shaded) {
public final void readColor(final HDPerspectiveState ps, final MapIterator mapiter, final Color rslt, final int blkid, final int lastblocktype, final boolean biome_shaded) {
int blkdata = ps.getBlockData();
HDTextureMap map = HDTextureMap.getMap(blkid, blkdata);
BlockStep laststep = ps.getLastBlockStep();
@ -749,8 +750,12 @@ public class TexturePack {
break;
}
/* Handle U-V transorms before fetching color */
if(textop > 0) {
switch(textop) {
case COLORMOD_NONE:
case COLORMOD_GRASSTONED:
case COLORMOD_FOLIAGETONED:
case COLORMOD_WATERTONED:
break;
case COLORMOD_ROT90:
tmp = u; u = native_scale - v - 1; v = tmp;
break;
@ -764,13 +769,18 @@ public class TexturePack {
u = native_scale - u - 1;
break;
case COLORMOD_SHIFTDOWNHALF:
if(v < native_scale/2) {
rslt.setTransparent();
return;
}
v -= native_scale/2;
break;
case COLORMOD_SHIFTDOWNHALFANDFLIPHORIZ:
if(v < native_scale/2) {
rslt.setTransparent();
return;
}
v -= native_scale/2;
if(textop == COLORMOD_SHIFTDOWNHALFANDFLIPHORIZ)
u = native_scale - u - 1;
break;
case COLORMOD_INCLINEDTORCH:
@ -796,11 +806,12 @@ public class TexturePack {
}
}
break;
}
case COLORMOD_CLEARINSIDE:
break;
}
/* Read color from texture */
rslt.setARGB(texture[v*native_scale + u]);
if(textop > 0) {
LoadedImage li;
/* Switch based on texture modifier */
switch(textop) {
@ -824,7 +835,6 @@ public class TexturePack {
break;
}
}
}
private static final int biomeLookup(int[] argb, int width, double rainfall, double temp) {
int t = (int)((1.0-temp)*(width-1));