From 8e47bede86cb316a401faf7657865c58a925460a Mon Sep 17 00:00:00 2001 From: piegamesde Date: Tue, 29 Aug 2017 10:24:42 +0200 Subject: [PATCH 01/12] Redone minimal changes But this time with setting the formatter to only affect the lines that got edited. --- .../togos/minecraft/maprend/RegionMap.java | 3 +- .../minecraft/maprend/RegionRenderer.java | 136 +++++++----------- .../minecraft/maprend/RenderSettings.java | 48 +++++++ .../minecraft/maprend/io/RegionFile.java | 12 +- 4 files changed, 110 insertions(+), 89 deletions(-) create mode 100644 src/main/java/togos/minecraft/maprend/RenderSettings.java diff --git a/src/main/java/togos/minecraft/maprend/RegionMap.java b/src/main/java/togos/minecraft/maprend/RegionMap.java index 196b53e..e34ed85 100644 --- a/src/main/java/togos/minecraft/maprend/RegionMap.java +++ b/src/main/java/togos/minecraft/maprend/RegionMap.java @@ -8,7 +8,8 @@ public class RegionMap { - static class Region { + + public static class Region { public int rx, rz; public File regionFile; public File imageFile; diff --git a/src/main/java/togos/minecraft/maprend/RegionRenderer.java b/src/main/java/togos/minecraft/maprend/RegionRenderer.java index 34425a1..1595957 100644 --- a/src/main/java/togos/minecraft/maprend/RegionRenderer.java +++ b/src/main/java/togos/minecraft/maprend/RegionRenderer.java @@ -3,28 +3,10 @@ import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; -import java.io.DataInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - +import java.io.*; +import java.util.*; import javax.imageio.ImageIO; - -import org.jnbt.ByteArrayTag; -import org.jnbt.ByteTag; -import org.jnbt.CompoundTag; -import org.jnbt.ListTag; -import org.jnbt.NBTInputStream; -import org.jnbt.Tag; - +import org.jnbt.*; import togos.minecraft.maprend.BiomeMap.Biome; import togos.minecraft.maprend.BlockMap.Block; import togos.minecraft.maprend.RegionMap.Region; @@ -61,6 +43,7 @@ class RenderThread extends Thread { this.force = force; } + @Override public void run() { try { for( Region reg : regions ) renderRegion(reg, outputDir, force); @@ -74,47 +57,25 @@ public void run() { public final Set defaultedBlockIds = new HashSet(); public final Set defaultedBlockIdDataValues = new HashSet(); public final Set defaultedBiomeIds = new HashSet(); - public final boolean debug; public final BlockMap blockMap; public final BiomeMap biomeMap; public final int air16Color; // Color of 16 air blocks stacked - public final int minHeight; - public final int maxHeight; - public final int shadingReferenceAltitude; - public final int altitudeShadingFactor; - public final int minAltitudeShading; - public final int maxAltitudeShading; - public final String mapTitle; - public final int[] mapScales; /** * Alpha below which blocks are considered transparent for purposes of shading * (i.e. blocks with alpha < this will not be shaded, but blocks below them will be) */ private int shadeOpacityCutoff = 0x20; - - public RegionRenderer( - BlockMap blockMap, BiomeMap biomeMap, boolean debug, int minHeight, int maxHeight, - int shadingRefAlt, int minAltShading, int maxAltShading, int altShadingFactor, - String mapTitle, int[] mapScales - ) { - assert blockMap != null; - assert biomeMap != null; - - this.blockMap = blockMap; - this.biomeMap = biomeMap; - this.air16Color = Color.overlay( 0, getColor(0, 0, 0), 16 ); - this.debug = debug; - - this.minHeight = minHeight; - this.maxHeight = maxHeight; - this.shadingReferenceAltitude = shadingRefAlt; - this.minAltitudeShading = minAltShading; - this.maxAltitudeShading = maxAltShading; - this.altitudeShadingFactor = altShadingFactor; - - this.mapTitle = mapTitle; - this.mapScales = mapScales; + + public final RenderSettings settings; + + public RegionRenderer(RenderSettings settings) throws IOException { + this.settings = settings; + + blockMap = settings.colorMapFile == null ? BlockMap.loadDefault() : BlockMap.load(settings.colorMapFile); + biomeMap = settings.biomeMapFile == null ? BiomeMap.loadDefault() : BiomeMap.load(settings.biomeMapFile); + + this.air16Color = Color.overlay(0, getColor(0, 0, 0), 16); } /** @@ -249,9 +210,11 @@ protected void shade( short[] height, int[] color ) { if( shade > 10 ) shade = 10; if( shade < -10 ) shade = -10; - int altShade = altitudeShadingFactor * (height[idx] - shadingReferenceAltitude) / 255; - if( altShade < minAltitudeShading ) altShade = minAltitudeShading; - if( altShade > maxAltitudeShading ) altShade = maxAltitudeShading; + int altShade = settings.altitudeShadingFactor * (height[idx] - settings.shadingReferenceAltitude) / 255; + if (altShade < settings.minAltitudeShading) + altShade = settings.minAltitudeShading; + if (altShade > settings.maxAltitudeShading) + altShade = settings.maxAltitudeShading; shade += altShade; @@ -309,15 +272,18 @@ protected void preRender( RegionFile rf, int[] colors, short[] heights ) { for( int s=0; s= maxHeight ) continue; - if( absY+16 <= minHeight ) continue; + if (absY >= settings.maxHeight) + continue; + if (absY + 16 <= settings.minHeight) + continue; if( usedSections[s] ) { short[] blockIds = sectionBlockIds[s]; byte[] blockData = sectionBlockData[s]; for( int idx=z*16+x, y=0; y<16; ++y, idx+=256, ++absY ) { - if( absY < minHeight || absY >= maxHeight ) continue; + if (absY < settings.minHeight || absY >= settings.maxHeight) + continue; final short blockId = blockIds[idx]; final byte blockDatum = blockData[idx]; @@ -328,7 +294,7 @@ protected void preRender( RegionFile rf, int[] colors, short[] heights ) { } } } else { - if( minHeight <= absY && maxHeight >= absY+16 ) { + if (settings.minHeight <= absY && settings.maxHeight >= absY + 16) { // Optimize the 16-blocks-of-air case: pixelColor = Color.overlay( pixelColor, air16Color ); } else { @@ -412,7 +378,8 @@ public void renderAll( RegionMap rm, File outputDir, boolean force, int threadCo renderThreads.add(renderThread); } - if( debug ) System.err.println("Using "+renderThreads.size()+" render threads"); + if (settings.debug) + System.err.println("Using " + renderThreads.size() + " render threads"); for( RenderThread renderThread : renderThreads ) renderThread.start(); @@ -424,7 +391,8 @@ public void renderAll( RegionMap rm, File outputDir, boolean force, int threadCo public void renderRegion( Region r, File outputDir, boolean force ) throws IOException { if( r == null ) return; - if( debug ) System.err.print("Region "+pad(r.rx, 4)+", "+pad(r.rz, 4)+"..."); + if (settings.debug) + System.err.print("Region " + pad(r.rx, 4) + ", " + pad(r.rz, 4) + "..."); String imageFilename = "tile."+r.rx+"."+r.rz+".png"; File fullSizeImageFile = r.imageFile = new File( outputDir, imageFilename ); @@ -433,11 +401,12 @@ public void renderRegion( Region r, File outputDir, boolean force ) throws IOExc if( force || !fullSizeImageFile.exists() || fullSizeImageFile.lastModified() < r.regionFile.lastModified() ) { fullSizeNeedsReRender = true; } else { - if( debug ) System.err.println("image already up-to-date"); + if (settings.debug) + System.err.println("image already up-to-date"); } boolean anyScalesNeedReRender = false; - for( int scale : mapScales ) { + for (int scale : settings.mapScales) { if( scale == 1 ) continue; File f = new File( outputDir, "tile."+r.rx+"."+r.rz+".1-"+scale+".png" ); if( force || !f.exists() || f.lastModified() < r.regionFile.lastModified() ) { @@ -448,7 +417,8 @@ public void renderRegion( Region r, File outputDir, boolean force ) throws IOExc BufferedImage fullSize; if( fullSizeNeedsReRender ) { fullSizeImageFile.delete(); - if( debug ) System.err.println("generating "+imageFilename+"..."); + if (settings.debug) + System.err.println("generating " + imageFilename + "..."); RegionFile rf = new RegionFile( r.regionFile ); try { @@ -472,10 +442,11 @@ public void renderRegion( Region r, File outputDir, boolean force ) throws IOExc return; } - for( int scale : mapScales ) { + for (int scale : settings.mapScales) { if( scale == 1 ) continue; // Already wrote! File f = new File( outputDir, "tile."+r.rx+"."+r.rz+".1-"+scale+".png" ); - if( debug ) System.err.println("generating "+f+"..."); + if (settings.debug) + System.err.println("generating " + f + "..."); int size = 512 / scale; BufferedImage rescaled = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g = rescaled.createGraphics(); @@ -492,8 +463,9 @@ public void renderRegion( Region r, File outputDir, boolean force ) throws IOExc * within the given bounds (inclusive) */ public void createTileHtml( int minX, int minZ, int maxX, int maxZ, File outputDir ) { - if( debug ) System.err.println("Writing HTML tiles..."); - for( int scale : mapScales ) { + if (settings.debug) + System.err.println("Writing HTML tiles..."); + for (int scale : settings.mapScales) { int regionSize = 512 / scale; try { @@ -522,7 +494,7 @@ public void createTileHtml( int minX, int minZ, int maxX, int maxZ, File outputD ))); try { w.write("\n"); - w.write(""+mapTitle+" - 1:"+scale+"\n"); + w.write("" + settings.mapTitle + " - 1:" + scale + "\n"); w.write("\n"); w.write("\n"); w.write("
"); @@ -554,11 +526,11 @@ public void createTileHtml( int minX, int minZ, int maxX, int maxZ, File outputD } w.write("
\n"); - if( mapScales.length > 1 ) { + if (settings.mapScales.length > 1) { w.write("
"); w.write("

Scales:

"); w.write("