More performance tweaks, add missing Override annotations

This commit is contained in:
Mike Primm 2026-03-06 18:56:15 -05:00
parent 0664472a6b
commit e0ed7d2ef0
3 changed files with 56 additions and 33 deletions

View file

@ -52,7 +52,13 @@ public class HDMapTile extends MapTile {
@Override @Override
public int hashCode() { public int hashCode() {
return tx ^ ty ^ perspective.hashCode() ^ world.hashCode() ^ boostzoom ^ tilescale; int h = perspective.hashCode();
h = h * 31 + world.hashCode();
h = h * 31 + tx;
h = h * 31 + ty;
h = h * 31 + boostzoom;
h = h * 31 + tilescale;
return h;
} }
@Override @Override
@ -87,19 +93,24 @@ public class HDMapTile extends MapTile {
@Override @Override
public boolean isBlockTypeDataNeeded() { return MapManager.mapman.hdmapman.isBlockTypeDataNeeded(this); } public boolean isBlockTypeDataNeeded() { return MapManager.mapman.hdmapman.isBlockTypeDataNeeded(this); }
@Override
public boolean render(MapChunkCache cache, String mapname) { public boolean render(MapChunkCache cache, String mapname) {
return perspective.render(cache, this, mapname); return perspective.render(cache, this, mapname);
} }
@Override
public List<DynmapChunk> getRequiredChunks() { public List<DynmapChunk> getRequiredChunks() {
return perspective.getRequiredChunks(this); return perspective.getRequiredChunks(this);
} }
@Override
public MapTile[] getAdjecentTiles() { public MapTile[] getAdjecentTiles() {
return perspective.getAdjecentTiles(this); return perspective.getAdjecentTiles(this);
} }
@Override
public int tileOrdinalX() { return tx; } public int tileOrdinalX() { return tx; }
@Override
public int tileOrdinalY() { return ty; } public int tileOrdinalY() { return ty; }
} }

View file

@ -90,6 +90,7 @@ public class IsoHDPerspective implements HDPerspective {
/* Scaled models for non-cube blocks */ /* Scaled models for non-cube blocks */
private final HDScaledBlockModels scalemodels; private final HDScaledBlockModels scalemodels;
private final int modscale; private final int modscale;
private final int modscale2; /* modscale * modscale, precomputed for raytraceSubblock */
/* Section-level raytrace variables */ /* Section-level raytrace variables */
int sx, sy, sz; int sx, sy, sz;
@ -153,6 +154,7 @@ public class IsoHDPerspective implements HDPerspective {
custom_meshes = new DynLongHashMap(4096); custom_meshes = new DynLongHashMap(4096);
custom_fluid_meshes = new DynLongHashMap(4096); custom_fluid_meshes = new DynLongHashMap(4096);
modscale = basemodscale << scaled; modscale = basemodscale << scaled;
modscale2 = modscale * modscale;
scalemodels = HDBlockModels.getModelsForScale(basemodscale << scaled); scalemodels = HDBlockModels.getModelsForScale(basemodscale << scaled);
} }
@ -250,18 +252,22 @@ public class IsoHDPerspective implements HDPerspective {
/** /**
* Get pixel X coordinate * Get pixel X coordinate
*/ */
@Override
public final int getPixelX() { return px; } public final int getPixelX() { return px; }
/** /**
* Get pixel Y coordinate * Get pixel Y coordinate
*/ */
@Override
public final int getPixelY() { return py; } public final int getPixelY() { return py; }
/** /**
* Get map iterator * Get map iterator
*/ */
@Override
public final MapIterator getMapIterator() { return mapiter; } public final MapIterator getMapIterator() { return mapiter; }
/** /**
* Return submodel alpha value (-1 if no submodel rendered) * Return submodel alpha value (-1 if no submodel rendered)
*/ */
@Override
public int getSubmodelAlpha() { public int getSubmodelAlpha() {
return subalpha; return subalpha;
} }
@ -283,9 +289,9 @@ public class IsoHDPerspective implements HDPerspective {
n = 1; n = 1;
/* Initial section coord */ /* Initial section coord */
sx = fastFloor(top.x/16.0); sx = fastFloor(top.x * 0.0625);
sy = fastFloor(top.y/16.0); sy = fastFloor(top.y * 0.0625);
sz = fastFloor(top.z/16.0); sz = fastFloor(top.z * 0.0625);
/* Compute parametric step (dt) per step on each axis */ /* Compute parametric step (dt) per step on each axis */
sdt_dx = 16.0 / dx; sdt_dx = 16.0 / dx;
sdt_dy = 16.0 / dy; sdt_dy = 16.0 / dy;
@ -302,7 +308,7 @@ public class IsoHDPerspective implements HDPerspective {
else if (bottom.x > top.x) { else if (bottom.x > top.x) {
x_inc = 1; x_inc = 1;
n += fastFloor(bottom.x) - x; n += fastFloor(bottom.x) - x;
st_next_x = (fastFloor(top.x/16.0) + 1 - (top.x/16.0)) * sdt_dx; st_next_x = (fastFloor(top.x * 0.0625) + 1 - (top.x * 0.0625)) * sdt_dx;
stepx = BlockStep.X_PLUS; stepx = BlockStep.X_PLUS;
mxout = modscale; mxout = modscale;
} }
@ -310,7 +316,7 @@ public class IsoHDPerspective implements HDPerspective {
else { else {
x_inc = -1; x_inc = -1;
n += x - fastFloor(bottom.x); n += x - fastFloor(bottom.x);
st_next_x = ((top.x/16.0) - fastFloor(top.x/16.0)) * sdt_dx; st_next_x = ((top.x * 0.0625) - fastFloor(top.x * 0.0625)) * sdt_dx;
stepx = BlockStep.X_MINUS; stepx = BlockStep.X_MINUS;
mxout = -1; mxout = -1;
} }
@ -325,7 +331,7 @@ public class IsoHDPerspective implements HDPerspective {
else if (bottom.y > top.y) { else if (bottom.y > top.y) {
y_inc = 1; y_inc = 1;
n += fastFloor(bottom.y) - y; n += fastFloor(bottom.y) - y;
st_next_y = (fastFloor(top.y/16.0) + 1 - (top.y/16.0)) * sdt_dy; st_next_y = (fastFloor(top.y * 0.0625) + 1 - (top.y * 0.0625)) * sdt_dy;
stepy = BlockStep.Y_PLUS; stepy = BlockStep.Y_PLUS;
myout = modscale; myout = modscale;
} }
@ -333,7 +339,7 @@ public class IsoHDPerspective implements HDPerspective {
else { else {
y_inc = -1; y_inc = -1;
n += y - fastFloor(bottom.y); n += y - fastFloor(bottom.y);
st_next_y = ((top.y/16.0) - fastFloor(top.y/16.0)) * sdt_dy; st_next_y = ((top.y * 0.0625) - fastFloor(top.y * 0.0625)) * sdt_dy;
stepy = BlockStep.Y_MINUS; stepy = BlockStep.Y_MINUS;
myout = -1; myout = -1;
} }
@ -348,7 +354,7 @@ public class IsoHDPerspective implements HDPerspective {
else if (bottom.z > top.z) { else if (bottom.z > top.z) {
z_inc = 1; z_inc = 1;
n += fastFloor(bottom.z) - z; n += fastFloor(bottom.z) - z;
st_next_z = (fastFloor(top.z/16.0) + 1 - (top.z/16.0)) * sdt_dz; st_next_z = (fastFloor(top.z * 0.0625) + 1 - (top.z * 0.0625)) * sdt_dz;
stepz = BlockStep.Z_PLUS; stepz = BlockStep.Z_PLUS;
mzout = modscale; mzout = modscale;
} }
@ -356,7 +362,7 @@ public class IsoHDPerspective implements HDPerspective {
else { else {
z_inc = -1; z_inc = -1;
n += z - fastFloor(bottom.z); n += z - fastFloor(bottom.z);
st_next_z = ((top.z/16.0) - fastFloor(top.z/16.0)) * sdt_dz; st_next_z = ((top.z * 0.0625) - fastFloor(top.z * 0.0625)) * sdt_dz;
stepz = BlockStep.Z_MINUS; stepz = BlockStep.Z_MINUS;
mzout = -1; mzout = -1;
} }
@ -810,7 +816,7 @@ public class IsoHDPerspective implements HDPerspective {
while(mt <= mtend) { while(mt <= mtend) {
if(!skip) { if(!skip) {
try { try {
int blkalpha = model[modscale*modscale*my + modscale*mz + mx]; int blkalpha = model[modscale2*my + modscale*mz + mx];
if(blkalpha > 0) { if(blkalpha > 0) {
subalpha = blkalpha; subalpha = blkalpha;
return false; return false;
@ -857,6 +863,7 @@ public class IsoHDPerspective implements HDPerspective {
return true; return true;
} }
@Override
public final int[] getSubblockCoord() { public final int[] getSubblockCoord() {
if(cur_patch >= 0) { /* If patch hit */ if(cur_patch >= 0) { /* If patch hit */
double tt = cur_patch_t; double tt = cur_patch_t;
@ -885,6 +892,7 @@ public class IsoHDPerspective implements HDPerspective {
} }
// Is the hit on a cullable face? // Is the hit on a cullable face?
@Override
public final boolean isOnFace() { public final boolean isOnFace() {
double tt; double tt;
if(cur_patch >= 0) { /* If patch hit */ if(cur_patch >= 0) { /* If patch hit */
@ -1294,11 +1302,14 @@ public class IsoHDPerspective implements HDPerspective {
miny = tile.getDynmapWorld().minY; miny = tile.getDynmapWorld().minY;
} }
for(int x = 0; x < tileSize * sizescale; x++) { final int tilePixelSize = tileSize * sizescale;
final double invSizescale = 1.0 / sizescale;
for(int x = 0; x < tilePixelSize; x++) {
ps.px = x; ps.px = x;
for(int y = 0; y < tileSize * sizescale; y++) { final double px_center = xbase + (x + 0.5) * invSizescale;
ps.top.x = ps.bottom.x = xbase + (x + 0.5) / sizescale; /* Start at center of pixel at Y=height+0.5, bottom at Y=-0.5 */ for(int y = 0; y < tilePixelSize; y++) {
ps.top.y = ps.bottom.y = ybase + (y + 0.5) / sizescale; ps.top.x = ps.bottom.x = px_center;
ps.top.y = ps.bottom.y = ybase + (y + 0.5) * invSizescale;
ps.top.z = height + 0.5; ps.bottom.z = miny - 0.5; ps.top.z = height + 0.5; ps.bottom.z = miny - 0.5;
map_to_world.transform(ps.top); /* Transform to world coordinates */ map_to_world.transform(ps.top); /* Transform to world coordinates */
map_to_world.transform(ps.bottom); map_to_world.transform(ps.bottom);
@ -1314,6 +1325,7 @@ public class IsoHDPerspective implements HDPerspective {
Log.severe("Error while raytracing tile: perspective=" + this.name + ", coord=" + mapiter.getX() + "," + mapiter.getY() + "," + mapiter.getZ() + ", blockid=" + mapiter.getBlockType() + ", lighting=" + mapiter.getBlockSkyLight() + ":" + mapiter.getBlockEmittedLight() + ", biome=" + mapiter.getBiome().toString(), ex); Log.severe("Error while raytracing tile: perspective=" + this.name + ", coord=" + mapiter.getX() + "," + mapiter.getY() + "," + mapiter.getZ() + ", blockid=" + mapiter.getBlockType() + ", lighting=" + mapiter.getBlockSkyLight() + ":" + mapiter.getBlockEmittedLight() + ", biome=" + mapiter.getBiome().toString(), ex);
ex.printStackTrace(); ex.printStackTrace();
} }
final int rowOffset = (tilePixelSize - y - 1) * tilePixelSize + x;
for(int i = 0; i < numshaders; i++) { for(int i = 0; i < numshaders; i++) {
if(shaderdone[i] == false) { if(shaderdone[i] == false) {
shaderstate[i].rayFinished(ps); shaderstate[i].rayFinished(ps);
@ -1325,21 +1337,11 @@ public class IsoHDPerspective implements HDPerspective {
shaderstate[i].getRayColor(rslt, 0); shaderstate[i].getRayColor(rslt, 0);
int c_argb = rslt.getARGB(); int c_argb = rslt.getARGB();
if (c_argb != 0) rendered[i] = true; if (c_argb != 0) rendered[i] = true;
if (isOpaque[i] && (c_argb == 0)) { argb_buf[i][rowOffset] = (isOpaque[i] && (c_argb == 0)) ? bgnight[i] : c_argb;
argb_buf[i][(tileSize*sizescale-y-1)*tileSize*sizescale + x] = bgnight[i];
}
else {
argb_buf[i][(tileSize*sizescale-y-1)*tileSize*sizescale + x] = c_argb;
}
if (day_argb_buf[i] != null) { if (day_argb_buf[i] != null) {
shaderstate[i].getRayColor(rslt, 1); shaderstate[i].getRayColor(rslt, 1);
c_argb = rslt.getARGB(); c_argb = rslt.getARGB();
if (isOpaque[i] && (c_argb == 0)) { day_argb_buf[i][rowOffset] = (isOpaque[i] && (c_argb == 0)) ? bgday[i] : c_argb;
day_argb_buf[i][(tileSize*sizescale-y-1)*tileSize*sizescale + x] = bgday[i];
}
else {
day_argb_buf[i][(tileSize*sizescale-y-1)*tileSize*sizescale + x] = c_argb;
}
} }
} }
} }

View file

@ -181,6 +181,7 @@ public class TexturePackHDShader implements HDShader {
* Process next ray step - called for each block on route * Process next ray step - called for each block on route
* @return true if ray is done, false if ray needs to continue * @return true if ray is done, false if ray needs to continue
*/ */
@Override
public boolean processBlock(HDPerspectiveState ps) { public boolean processBlock(HDPerspectiveState ps) {
DynmapBlockState blocktype = ps.getBlockState(); DynmapBlockState blocktype = ps.getBlockState();
if ((hiddenids != null) && hiddenids.get(blocktype.globalStateIndex)) { if ((hiddenids != null) && hiddenids.get(blocktype.globalStateIndex)) {
@ -265,7 +266,7 @@ public class TexturePackHDShader implements HDShader {
if(color[0].isTransparent()) { if(color[0].isTransparent()) {
for(int i = 0; i < color.length; i++) for(int i = 0; i < color.length; i++)
color[i].setColor(tmpcolor[i]); color[i].setColor(tmpcolor[i]);
return (color[0].getAlpha() == 255); return (tmpcolor[0].getAlpha() == 255);
} }
/* Else, blend and generate new alpha */ /* Else, blend and generate new alpha */
else { else {
@ -273,10 +274,14 @@ public class TexturePackHDShader implements HDShader {
int alpha2 = tmpcolor[0].getAlpha() * (255-alpha) / 255; int alpha2 = tmpcolor[0].getAlpha() * (255-alpha) / 255;
int talpha = alpha + alpha2; int talpha = alpha + alpha2;
if(talpha > 0) if(talpha > 0)
for(int i = 0; i < color.length; i++) for(int i = 0; i < color.length; i++) {
color[i].setRGBA((tmpcolor[i].getRed()*alpha2 + color[i].getRed()*alpha) / talpha, int tc = tmpcolor[i].getARGB();
(tmpcolor[i].getGreen()*alpha2 + color[i].getGreen()*alpha) / talpha, int cc = color[i].getARGB();
(tmpcolor[i].getBlue()*alpha2 + color[i].getBlue()*alpha) / talpha, talpha); color[i].setARGB((talpha << 24)
| (((((tc >> 16) & 0xFF) * alpha2 + ((cc >> 16) & 0xFF) * alpha) / talpha) << 16)
| (((((tc >> 8) & 0xFF) * alpha2 + ((cc >> 8) & 0xFF) * alpha) / talpha) << 8)
| ((( tc & 0xFF) * alpha2 + ( cc & 0xFF) * alpha) / talpha));
}
else else
for(int i = 0; i < color.length; i++) for(int i = 0; i < color.length; i++)
color[i].setTransparent(); color[i].setTransparent();
@ -290,6 +295,7 @@ public class TexturePackHDShader implements HDShader {
/** /**
* Ray ended - used to report that ray has exited map (called if renderer has not reported complete) * Ray ended - used to report that ray has exited map (called if renderer has not reported complete)
*/ */
@Override
public void rayFinished(HDPerspectiveState ps) { public void rayFinished(HDPerspectiveState ps) {
} }
/** /**
@ -297,12 +303,14 @@ public class TexturePackHDShader implements HDShader {
* @param c - object to store color value in * @param c - object to store color value in
* @param index - index of color to request (renderer specific - 0=default, 1=day for night/day renderer * @param index - index of color to request (renderer specific - 0=default, 1=day for night/day renderer
*/ */
@Override
public void getRayColor(Color c, int index) { public void getRayColor(Color c, int index) {
c.setColor(color[index]); c.setColor(color[index]);
} }
/** /**
* Clean up state object - called after last ray completed * Clean up state object - called after last ray completed
*/ */
@Override
public void cleanup() { public void cleanup() {
if (ctm_cache != null) { if (ctm_cache != null) {
ctm_cache.clear(); ctm_cache.clear();
@ -338,11 +346,13 @@ public class TexturePackHDShader implements HDShader {
* @param scale - scale of perspective * @param scale - scale of perspective
* @return state object to use for all rays in tile * @return state object to use for all rays in tile
*/ */
@Override
public HDShaderState getStateInstance(HDMap map, MapChunkCache cache, MapIterator mapiter, int scale) { public HDShaderState getStateInstance(HDMap map, MapChunkCache cache, MapIterator mapiter, int scale) {
return new ShaderState(mapiter, map, cache, scale); return new ShaderState(mapiter, map, cache, scale);
} }
/* Add shader's contributions to JSON for map object */ /* Add shader's contributions to JSON for map object */
@Override
public void addClientConfiguration(JSONObject mapObject) { public void addClientConfiguration(JSONObject mapObject) {
s(mapObject, "shader", name); s(mapObject, "shader", name);
} }