From 4e810fc9d8402e6508d5e9d18659c2a498b7f7ea Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 17 Jul 2011 11:02:22 -0500 Subject: [PATCH] Woraround bukkit schedule spin, add custom-models.txt, custom-texture.txt --- src/main/java/org/dynmap/MapManager.java | 2 +- .../java/org/dynmap/hdmap/HDBlockModels.java | 33 +++++-- .../java/org/dynmap/hdmap/HDMapManager.java | 5 +- .../org/dynmap/hdmap/HDPerspectiveState.java | 2 +- .../org/dynmap/hdmap/IsoHDPerspective.java | 10 ++- .../java/org/dynmap/hdmap/TexturePack.java | 90 +++++++++---------- 6 files changed, 84 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index 38d1c336..aa04e1cf 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -363,7 +363,7 @@ public class MapManager { } scheduler.scheduleSyncRepeatingTask(plugin, new CheckWorldTimes(), 5*20, 5*20); /* Check very 5 seconds */ - scheduler.scheduleSyncRepeatingTask(plugin, new ProcessChunkLoads(), 1, 1); /* Chunk loader task */ + scheduler.scheduleSyncRepeatingTask(plugin, new ProcessChunkLoads(), 1, 2); /* Chunk loader task - do every 2 to work around bukkit issue */ } diff --git a/src/main/java/org/dynmap/hdmap/HDBlockModels.java b/src/main/java/org/dynmap/hdmap/HDBlockModels.java index 6b8f8eef..5eb7b72f 100644 --- a/src/main/java/org/dynmap/hdmap/HDBlockModels.java +++ b/src/main/java/org/dynmap/hdmap/HDBlockModels.java @@ -1,7 +1,9 @@ package org.dynmap.hdmap; import java.io.File; +import java.io.FileOutputStream; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.LineNumberReader; import java.util.ArrayList; @@ -256,9 +258,28 @@ public class HDBlockModels { return model; } /** - * Load models from model.txt file + * Load models */ - public static void loadModels(File plugindir) { + public static void loadModels(File datadir) { + /* Load block models */ + HDBlockModels.loadModelFile(new File(datadir, "models.txt")); + File custom = new File(datadir, "custom-models.txt"); + if(custom.canRead()) { + HDBlockModels.loadModels(custom); + } + else { + try { + FileWriter fw = new FileWriter(custom); + fw.write("# The user is free to add new and custom models here - Dynmap's install will not overwrite it\n"); + fw.close(); + } catch (IOException iox) { + } + } + } + /** + * Load models from file + */ + private static void loadModelFile(File modelfile) { LineNumberReader rdr = null; int cnt = 0; try { @@ -267,7 +288,7 @@ public class HDBlockModels { int layerbits = 0; int rownum = 0; int scale = 0; - rdr = new LineNumberReader(new FileReader(new File(plugindir, "models.txt"))); + rdr = new LineNumberReader(new FileReader(modelfile)); while((line = rdr.readLine()) != null) { if(line.startsWith("block:")) { ArrayList blkids = new ArrayList(); @@ -300,7 +321,7 @@ public class HDBlockModels { } } else { - Log.severe("Block model missing required parameters = line " + rdr.getLineNumber() + " of models.txt"); + Log.severe("Block model missing required parameters = line " + rdr.getLineNumber() + " of " + modelfile.getPath()); } layerbits = 0; } @@ -379,11 +400,11 @@ public class HDBlockModels { } } } - Log.info("Loaded " + cnt + " block models"); + Log.verboseinfo("Loaded " + cnt + " block models from " + modelfile.getPath()); } catch (IOException iox) { Log.severe("Error reading models.txt - " + iox.toString()); } catch (NumberFormatException nfx) { - Log.severe("Format error - line " + rdr.getLineNumber() + " of models.txt"); + Log.severe("Format error - line " + rdr.getLineNumber() + " of " + modelfile.getPath()); } finally { if(rdr != null) { try { diff --git a/src/main/java/org/dynmap/hdmap/HDMapManager.java b/src/main/java/org/dynmap/hdmap/HDMapManager.java index 590d76f3..654a6317 100644 --- a/src/main/java/org/dynmap/hdmap/HDMapManager.java +++ b/src/main/java/org/dynmap/hdmap/HDMapManager.java @@ -1,5 +1,8 @@ package org.dynmap.hdmap; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -23,7 +26,7 @@ public class HDMapManager { public HashMap lightings = new HashMap(); public HashSet maps = new HashSet(); public HashMap> maps_by_world_perspective = new HashMap>(); - + public void loadHDShaders(ConfigurationNode shadercfg) { Log.verboseinfo("Loading shaders..."); for(HDShader shader : shadercfg.createInstances("shaders", new Class[0], new Object[0])) { diff --git a/src/main/java/org/dynmap/hdmap/HDPerspectiveState.java b/src/main/java/org/dynmap/hdmap/HDPerspectiveState.java index 6791a4fd..12b52cfd 100644 --- a/src/main/java/org/dynmap/hdmap/HDPerspectiveState.java +++ b/src/main/java/org/dynmap/hdmap/HDPerspectiveState.java @@ -59,5 +59,5 @@ public interface HDPerspectiveState { /** * Return subblock coordinates of current ray position */ - void getSubblockCoord(int[] xyz); + int[] getSubblockCoord(); } diff --git a/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java b/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java index 83127146..03677759 100644 --- a/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java +++ b/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java @@ -89,6 +89,7 @@ public class IsoHDPerspective implements HDPerspective { boolean nonairhit; int subalpha; double mt; + int[] subblock_xyz = new int[3]; /** * Get sky light level - only available if shader requested it */ @@ -454,16 +455,17 @@ public class IsoHDPerspective implements HDPerspective { } return true; } - public void getSubblockCoord(int[] v) { + public int[] getSubblockCoord() { double tt = t + 0.000001; if(subalpha >= 0) tt = mt; double xx = top.x + tt * (bottom.x - top.x); double yy = top.y + tt * (bottom.y - top.y); double zz = top.z + tt * (bottom.z - top.z); - v[0] = (int)((xx - Math.floor(xx)) * modscale); - v[1] = (int)((yy - Math.floor(yy)) * modscale); - v[2] = (int)((zz - Math.floor(zz)) * modscale); + subblock_xyz[0] = (int)((xx - Math.floor(xx)) * modscale); + subblock_xyz[1] = (int)((yy - Math.floor(yy)) * modscale); + subblock_xyz[2] = (int)((zz - Math.floor(zz)) * modscale); + return subblock_xyz; } } diff --git a/src/main/java/org/dynmap/hdmap/TexturePack.java b/src/main/java/org/dynmap/hdmap/TexturePack.java index 714f5621..a72d0f2c 100644 --- a/src/main/java/org/dynmap/hdmap/TexturePack.java +++ b/src/main/java/org/dynmap/hdmap/TexturePack.java @@ -5,6 +5,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.LineNumberReader; @@ -48,6 +49,10 @@ public class TexturePack { private static final String FOLIAGECOLOR_PNG = "misc/foliagecolor.png"; private static final String WATERCOLOR_PNG = "misc/watercolor.png"; private static final String WATER_PNG = "misc/water.png"; + private static final String CUSTOMLAVASTILL_PNG = "custom_lava_still.png"; + private static final String CUSTOMLAVAFLOWING_PNG = "custom_lava_flowing.png"; + private static final String CUSTOMWATERSTILL_PNG = "custom_water_still.png"; + private static final String CUSTOMWATERFLOWING_PNG = "custom_water_flowing.png"; /* Color modifier codes (x1000 for value in mapping code) */ private static final int COLORMOD_GRASSTONED = 1; @@ -545,11 +550,31 @@ public class TexturePack { BufferedImage img = KzedMap.createBufferedImage(outbuf, terrain_width, terrain_height); ImageIO.write(img, "png", f); } - + + /** + * Load texture pack mappings + */ + public static void loadTextureMapping(File datadir) { + /* Load block models */ + loadTextureFile(new File(datadir, "texture.txt")); + File custom = new File(datadir, "custom-texture.txt"); + if(custom.canRead()) { + loadTextureFile(custom); + } + else { + try { + FileWriter fw = new FileWriter(custom); + fw.write("# The user is free to add new and custom texture mappings here - Dynmap's install will not overwrite it\n"); + fw.close(); + } catch (IOException iox) { + } + } + } + /** * Load texture pack mappings from texture.txt file */ - public static void loadTextureMapping(File plugindir) { + private static void loadTextureFile(File txtfile) { LineNumberReader rdr = null; int cnt = 0; /* Initialize map with blank map for all entries */ @@ -557,7 +582,7 @@ public class TexturePack { try { String line; - rdr = new LineNumberReader(new FileReader(new File(plugindir, "texture.txt"))); + rdr = new LineNumberReader(new FileReader(txtfile)); while((line = rdr.readLine()) != null) { if(line.startsWith("block:")) { ArrayList blkids = new ArrayList(); @@ -620,17 +645,17 @@ public class TexturePack { cnt++; } else { - Log.severe("Texture mapping missing required parameters = line " + rdr.getLineNumber() + " of texture.txt"); + Log.severe("Texture mapping missing required parameters = line " + rdr.getLineNumber() + " of " + txtfile.getPath()); } } else if(line.startsWith("#") || line.startsWith(";")) { } } - Log.info("Loaded " + cnt + " texture mappings"); + Log.verboseinfo("Loaded " + cnt + " texture mappings from " + txtfile.getPath()); } catch (IOException iox) { - Log.severe("Error reading texture.txt - " + iox.toString()); + Log.severe("Error reading " + txtfile.getPath() + " - " + iox.toString()); } catch (NumberFormatException nfx) { - Log.severe("Format error - line " + rdr.getLineNumber() + " of texture.txt"); + Log.severe("Format error - line " + rdr.getLineNumber() + " of " + txtfile.getPath()); } finally { if(rdr != null) { try { @@ -656,10 +681,18 @@ public class TexturePack { /* See if not basic block texture */ int textop = textid / 1000; textid = textid % 1000; + + /* If clear-inside op, get out early */ + if(textop == COLORMOD_CLEARINSIDE) { + /* Check if previous block is same block type as we are: surface is transparent if it is */ + if(blkid == lastblocktype) { + rslt.setTransparent(); + return; + } + } + int[] texture = terrain_argb[textid]; - int clrval = 0; - int[] xyz = new int[3]; - ps.getSubblockCoord(xyz); + int[] xyz = ps.getSubblockCoord(); /* Get texture coordinates (U=horizontal(left=0),V=vertical(top=0)) */ int u = 0, v = 0, tmp; @@ -729,18 +762,10 @@ public class TexturePack { } } break; - case COLORMOD_CLEARINSIDE: - /* Check if previous block is same block type as we are: surface is transparent if it is */ - if(blkid == lastblocktype) { - rslt.setTransparent(); - return; - } - break; } } - clrval = texture[v*native_scale + u]; - - rslt.setARGB(clrval); + /* Read color from texture */ + rslt.setARGB(texture[v*native_scale + u]); if(textop > 0) { /* Switch based on texture modifier */ switch(textop) { @@ -777,29 +802,4 @@ public class TexturePack { int h = width - (int)(temp*rainfall*(width-1)) - 1; return argb[width*h + t]; } - - public static void main(String[] args) { - TexturePack.loadTextureMapping(new File(".")); - TexturePack tp = TexturePack.getTexturePack("standard"); - TexturePack tp2 = tp.resampleTexturePack(4); - try { - tp2.saveTerrainPNG(new File("test_terrain_4.png")); - } catch (IOException iox) {} - tp2 = tp.resampleTexturePack(16); - try { - tp2.saveTerrainPNG(new File("test_terrain_16.png")); - } catch (IOException iox) {} - tp2 = tp.resampleTexturePack(24); - try { - tp2.saveTerrainPNG(new File("test_terrain_24.png")); - } catch (IOException iox) {} - tp2 = tp.resampleTexturePack(64); - try { - tp2.saveTerrainPNG(new File("test_terrain_64.png")); - } catch (IOException iox) {} - tp2 = tp.resampleTexturePack(1); - try { - tp2.saveTerrainPNG(new File("test_terrain_1.png")); - } catch (IOException iox) {} - } }