Various performance and concurrency optimizations

This commit is contained in:
Mike Primm 2011-12-10 14:14:52 +08:00 committed by mikeprimm
parent fd887b47b4
commit 05aa0960f2
6 changed files with 115 additions and 74 deletions

View file

@ -21,8 +21,8 @@ public class DefaultHDLighting implements HDLighting {
/* Apply lighting to given pixel colors (1 outcolor if normal, 2 if night/day) */
public void applyLighting(HDPerspectiveState ps, HDShaderState ss, Color incolor, Color[] outcolor) {
for(Color oc: outcolor)
oc.setColor(incolor);
for(int i = 0; i < outcolor.length; i++)
outcolor[i].setColor(incolor);
}
/* Test if Biome Data is needed for this renderer */

View file

@ -117,8 +117,8 @@ public class DefaultHDShader implements HDShader {
* Reset renderer state for new ray
*/
public void reset(HDPerspectiveState ps) {
for(Color c: color)
c.setTransparent();
for(int i = 0; i < color.length; i++)
color[i].setTransparent();
pixelodd = (ps.getPixelX() & 0x3) + (ps.getPixelY()<<1);
}
@ -169,8 +169,8 @@ public class DefaultHDShader implements HDShader {
lighting.applyLighting(ps, this, c, tmpcolor);
/* If we got alpha from subblock model, use it instead */
if(subalpha >= 0) {
for(Color clr : tmpcolor)
clr.setAlpha(Math.max(subalpha,clr.getAlpha()));
for(int j = 0; j < tmpcolor.length; j++)
tmpcolor[j].setAlpha(Math.max(subalpha,tmpcolor[j].getAlpha()));
}
/* Blend color with accumulated color (weighted by alpha) */
if(!transparency) { /* No transparency support */

View file

@ -145,7 +145,8 @@ public class IsoHDPerspective implements HDPerspective {
BlockStep [] steps = { BlockStep.Y_PLUS, BlockStep.X_MINUS, BlockStep.X_PLUS,
BlockStep.Z_MINUS, BlockStep.Z_PLUS };
emitlevel = skylevel = 0;
for(BlockStep s : steps) {
for(int i = 0; i < steps.length; i++) {
BlockStep s = steps[i];
mapiter.stepPosition(s);
int v = mapiter.getBlockEmittedLight();
if(v > emitlevel) emitlevel = v;
@ -448,7 +449,8 @@ public class IsoHDPerspective implements HDPerspective {
mapiter.getBlockTypeIDAt(BlockStep.X_MINUS) }; /* To north */
int flags = 0;
for(int i = 0; i < 4; i++)
if(ids[i] == REDSTONE_BLKTYPEID) flags |= (1<<i);
if(ids[i] == REDSTONE_BLKTYPEID)
flags |= (1<<i);
switch(flags) {
case 0: /* Nothing nearby */
case 15: /* NSEW */
@ -517,8 +519,8 @@ public class IsoHDPerspective implements HDPerspective {
return blockdata;
}
private final boolean containsID(int id, int[] linkids) {
for(int lid: linkids)
if(id == lid)
for(int i = 0; i < linkids.length; i++)
if(id == linkids[i])
return true;
return false;
}
@ -640,16 +642,8 @@ public class IsoHDPerspective implements HDPerspective {
if(visit_block(mapiter, shaderstate, shaderdone)) {
return;
}
/* If X step is next best */
if((t_next_x <= t_next_y) && (t_next_x <= t_next_z)) {
x += x_inc;
t = t_next_x;
t_next_x += dt_dx;
laststep = stepx;
mapiter.stepPosition(laststep);
}
/* If Y step is next best */
else if((t_next_y <= t_next_x) && (t_next_y <= t_next_z)) {
if((t_next_y <= t_next_x) && (t_next_y <= t_next_z)) {
y += y_inc;
t = t_next_y;
t_next_y += dt_dy;
@ -658,6 +652,14 @@ public class IsoHDPerspective implements HDPerspective {
/* If outside 0-127 range */
if((y & (~0x7F)) != 0) return;
}
/* If X step is next best */
else if((t_next_x <= t_next_y) && (t_next_x <= t_next_z)) {
x += x_inc;
t = t_next_x;
t_next_x += dt_dx;
laststep = stepx;
mapiter.stepPosition(laststep);
}
/* Else, Z step is next best */
else {
z += z_inc;

View file

@ -123,8 +123,8 @@ public class TexturePackHDShader implements HDShader {
* Reset renderer state for new ray
*/
public void reset(HDPerspectiveState ps) {
for(Color c: color)
c.setTransparent();
for(int i = 0; i < color.length; i++)
color[i].setTransparent();
lastblkid = 0;
}