From 1862dc918c9c27be8f9d549a1ac5da9b77bb8420 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 17 Jul 2011 16:19:24 -0500 Subject: [PATCH 1/3] Different Bukkit schedule spin workaround, that isn't so slow Generalize texture image loading --- src/main/java/org/dynmap/MapManager.java | 9 +- .../java/org/dynmap/hdmap/HDBlockModels.java | 4 +- .../java/org/dynmap/hdmap/TexturePack.java | 200 +++++++----------- .../org/dynmap/utils/LegacyMapChunkCache.java | 4 +- .../org/dynmap/utils/NewMapChunkCache.java | 4 - texture.txt | 140 ++++++------ 6 files changed, 154 insertions(+), 207 deletions(-) diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index aa04e1cf..89ea419b 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -302,7 +302,7 @@ public class MapManager { while(cnt > 0) { MapChunkCache c = chunkloads.peek(); if(c == null) - return; + break; cnt = cnt - c.loadChunks(cnt); if(c.isDoneLoading()) { chunkloads.poll(); @@ -311,6 +311,8 @@ public class MapManager { } } } + if(mapman.scheduler != null) + mapman.scheduler.scheduleSyncDelayedTask(mapman.plug_in, this, 1); } } @@ -363,8 +365,9 @@ public class MapManager { } scheduler.scheduleSyncRepeatingTask(plugin, new CheckWorldTimes(), 5*20, 5*20); /* Check very 5 seconds */ - scheduler.scheduleSyncRepeatingTask(plugin, new ProcessChunkLoads(), 1, 2); /* Chunk loader task - do every 2 to work around bukkit issue */ - +// scheduler.scheduleSyncRepeatingTask(plugin, new ProcessChunkLoads(), 1, 2); + /* Chunk loader task - work around bukkit issue */ + scheduler.scheduleSyncDelayedTask(plugin, new ProcessChunkLoads()); } void renderFullWorld(Location l, CommandSender sender) { diff --git a/src/main/java/org/dynmap/hdmap/HDBlockModels.java b/src/main/java/org/dynmap/hdmap/HDBlockModels.java index 5eb7b72f..0f071461 100644 --- a/src/main/java/org/dynmap/hdmap/HDBlockModels.java +++ b/src/main/java/org/dynmap/hdmap/HDBlockModels.java @@ -262,10 +262,10 @@ public class HDBlockModels { */ public static void loadModels(File datadir) { /* Load block models */ - HDBlockModels.loadModelFile(new File(datadir, "models.txt")); + loadModelFile(new File(datadir, "models.txt")); File custom = new File(datadir, "custom-models.txt"); if(custom.canRead()) { - HDBlockModels.loadModels(custom); + loadModelFile(custom); } else { try { diff --git a/src/main/java/org/dynmap/hdmap/TexturePack.java b/src/main/java/org/dynmap/hdmap/TexturePack.java index a72d0f2c..f842a678 100644 --- a/src/main/java/org/dynmap/hdmap/TexturePack.java +++ b/src/main/java/org/dynmap/hdmap/TexturePack.java @@ -76,26 +76,29 @@ public class TexturePack { private static final int BLOCKINDEX_MOVINGLAVA = 260; private static final int MAX_BLOCKINDEX = 260; private static final int BLOCKTABLELEN = MAX_BLOCKINDEX+1; - + + private static class LoadedImage { + int[] argb; + int width, height; + int trivial_color; + } + private int[][] terrain_argb; private int terrain_width, terrain_height; private int native_scale; - private int[] grasscolor_argb; - private int grasscolor_width, grasscolor_height; - private int trivial_grasscolor; - - private int[] foliagecolor_argb; - private int foliagecolor_width, foliagecolor_height; - private int trivial_foliagecolor; - - private int[] watercolor_argb; - private int watercolor_width, watercolor_height; - private int trivial_watercolor; - - private int[] water_argb; - private int water_width, water_height; + private static final int IMG_GRASSCOLOR = 0; + private static final int IMG_FOLIAGECOLOR = 1; + private static final int IMG_WATERCOLOR = 2; + private static final int IMG_WATER = 3; + private static final int IMG_CUSTOMWATERMOVING = 4; + private static final int IMG_CUSTOMWATERSTILL = 5; + private static final int IMG_CUSTOMLAVAMOVING = 6; + private static final int IMG_CUSTOMLAVASTILL = 7; + private static final int IMG_CNT = 8; + private LoadedImage[] imgs = new LoadedImage[IMG_CNT]; + private HashMap scaled_textures; @@ -179,28 +182,30 @@ public class TexturePack { if(ze == null) throw new FileNotFoundException(); is = zf.getInputStream(ze); - loadGrassColorPNG(is); + loadBiomeShadingImage(is, IMG_GRASSCOLOR); is.close(); /* Try to find and load misc/foliagecolor.png */ ze = zf.getEntry(FOLIAGECOLOR_PNG); if(ze == null) throw new FileNotFoundException(); is = zf.getInputStream(ze); - loadFoliageColorPNG(is); + loadBiomeShadingImage(is, IMG_FOLIAGECOLOR); is.close(); /* Try to find and load misc/watercolor.png */ ze = zf.getEntry(WATERCOLOR_PNG); if(ze == null) throw new FileNotFoundException(); is = zf.getInputStream(ze); - loadWaterColorPNG(is); + loadBiomeShadingImage(is, IMG_WATERCOLOR); is.close(); /* Try to find and load misc/water.png */ ze = zf.getEntry(WATER_PNG); if(ze == null) throw new FileNotFoundException(); is = zf.getInputStream(ze); - loadWaterPNG(is); + loadImage(is, IMG_WATER); + patchTextureWithImage(IMG_WATER, BLOCKINDEX_STATIONARYWATER); + patchTextureWithImage(IMG_WATER, BLOCKINDEX_MOVINGWATER); is.close(); zf.close(); @@ -223,22 +228,25 @@ public class TexturePack { /* Check for misc/grasscolor.png */ f = new File(texturedir, tpname + "/" + GRASSCOLOR_PNG); fis = new FileInputStream(f); - loadGrassColorPNG(fis); + loadBiomeShadingImage(fis, IMG_GRASSCOLOR); fis.close(); /* Check for misc/foliagecolor.png */ f = new File(texturedir, tpname + "/" + FOLIAGECOLOR_PNG); fis = new FileInputStream(f); - loadFoliageColorPNG(fis); + loadBiomeShadingImage(fis, IMG_FOLIAGECOLOR); fis.close(); /* Check for misc/waterecolor.png */ f = new File(texturedir, tpname + "/" + WATERCOLOR_PNG); fis = new FileInputStream(f); - loadWaterColorPNG(fis); + loadBiomeShadingImage(fis, IMG_WATERCOLOR); fis.close(); /* Check for misc/water.png */ f = new File(texturedir, tpname + "/" + WATER_PNG); fis = new FileInputStream(f); - loadWaterPNG(fis); + loadImage(fis, IMG_WATER); + patchTextureWithImage(IMG_WATER, BLOCKINDEX_STATIONARYWATER); + patchTextureWithImage(IMG_WATER, BLOCKINDEX_MOVINGWATER); + fis.close(); } catch (IOException iox) { if(fis != null) { @@ -255,24 +263,7 @@ public class TexturePack { this.terrain_height = tp.terrain_height; this.native_scale = tp.native_scale; - this.grasscolor_argb = tp.grasscolor_argb; - this.grasscolor_height = tp.grasscolor_height; - this.grasscolor_width = tp.grasscolor_width; - this.trivial_grasscolor = tp.trivial_grasscolor; - - this.watercolor_argb = tp.watercolor_argb; - this.watercolor_height = tp.watercolor_height; - this.watercolor_width = tp.watercolor_width; - this.trivial_watercolor = tp.trivial_watercolor; - - this.foliagecolor_argb = tp.foliagecolor_argb; - this.foliagecolor_height = tp.foliagecolor_height; - this.foliagecolor_width = tp.foliagecolor_width; - this.trivial_foliagecolor = tp.trivial_foliagecolor; - - this.water_argb = tp.water_argb; - this.water_height = tp.water_height; - this.water_width = tp.water_width; + this.imgs = tp.imgs; } /* Load terrain.png */ @@ -300,94 +291,47 @@ public class TexturePack { img.flush(); } - /* Load misc/grasscolor.png */ - private void loadGrassColorPNG(InputStream is) throws IOException { + /* Load image into image array */ + private void loadImage(InputStream is, int idx) throws IOException { /* Load image */ BufferedImage img = ImageIO.read(is); if(img == null) { throw new FileNotFoundException(); } - grasscolor_width = img.getWidth(); - grasscolor_height = img.getHeight(); - grasscolor_argb = new int[grasscolor_width * grasscolor_height]; - img.getRGB(0, 0, grasscolor_width, grasscolor_height, grasscolor_argb, 0, grasscolor_width); + imgs[idx] = new LoadedImage(); + imgs[idx].width = img.getWidth(); + imgs[idx].height = img.getHeight(); + imgs[idx].argb = new int[imgs[idx].width * imgs[idx].height]; + img.getRGB(0, 0, imgs[idx].width, imgs[idx].height, imgs[idx].argb, 0, imgs[idx].width); img.flush(); - /* Figure out trivial color */ - trivial_grasscolor = grasscolor_argb[grasscolor_height*grasscolor_width*3/4 + grasscolor_width/2]; + } + + /* Load biome shading image into image array */ + private void loadBiomeShadingImage(InputStream is, int idx) throws IOException { + loadImage(is, idx); /* Get image */ + LoadedImage li = imgs[idx]; + /* Get trivial color for biome-shading image */ + int clr = li.argb[li.height*li.width*3/4 + li.width/2]; boolean same = true; - for(int j = 0; same && (j < grasscolor_height); j++) { + for(int j = 0; same && (j < li.height); j++) { for(int i = 0; same && (i <= j); i++) { - if(grasscolor_argb[grasscolor_width*j+i] != trivial_grasscolor) + if(li.argb[li.width*j+i] != clr) same = false; } } /* All the same - no biome lookup needed */ if(same) - grasscolor_argb = null; + imgs[idx].argb = null; + li.trivial_color = clr; } - /* Load misc/foliagecolor.png */ - private void loadFoliageColorPNG(InputStream is) throws IOException { - /* Load image */ - BufferedImage img = ImageIO.read(is); - if(img == null) { throw new FileNotFoundException(); } - foliagecolor_width = img.getWidth(); - foliagecolor_height = img.getHeight(); - foliagecolor_argb = new int[foliagecolor_width * foliagecolor_height]; - img.getRGB(0, 0, foliagecolor_width, foliagecolor_height, foliagecolor_argb, 0, foliagecolor_width); - img.flush(); - /* Figure out trivial color */ - trivial_foliagecolor = foliagecolor_argb[foliagecolor_height*foliagecolor_width*3/4 + foliagecolor_width/2]; - boolean same = true; - for(int j = 0; same && (j < foliagecolor_height); j++) { - for(int i = 0; same && (i <= j); i++) { - if(foliagecolor_argb[foliagecolor_width*j+i] != trivial_foliagecolor) - same = false; - } - } - /* All the same - no biome lookup needed */ - if(same) - foliagecolor_argb = null; - } - - /* Load misc/watercolor.png */ - private void loadWaterColorPNG(InputStream is) throws IOException { - /* Load image */ - BufferedImage img = ImageIO.read(is); - if(img == null) { throw new FileNotFoundException(); } - watercolor_width = img.getWidth(); - watercolor_height = img.getHeight(); - watercolor_argb = new int[watercolor_width * watercolor_height]; - img.getRGB(0, 0, watercolor_width, watercolor_height, watercolor_argb, 0, watercolor_width); - img.flush(); - /* Figure out trivial color */ - trivial_watercolor = watercolor_argb[watercolor_height*watercolor_width*3/4 + watercolor_width/2]; - boolean same = true; - for(int j = 0; same && (j < watercolor_height); j++) { - for(int i = 0; same && (i <= j); i++) { - if(watercolor_argb[watercolor_width*j+i] != trivial_watercolor) - same = false; - } - } - /* All the same - no biome lookup needed */ - if(same) - watercolor_argb = null; - } - - /* Load misc/water.png */ - private void loadWaterPNG(InputStream is) throws IOException { - /* Load image */ - BufferedImage img = ImageIO.read(is); - if(img == null) { throw new FileNotFoundException(); } - water_width = img.getWidth(); - water_height = img.getHeight(); - water_argb = new int[water_width * water_height]; - img.getRGB(0, 0, water_width, water_height, water_argb, 0, water_width); - img.flush(); + /* Patch image into texture table */ + private void patchTextureWithImage(int image_idx, int block_idx) { /* Now, patch in to block table */ - int new_water_argb[] = new int[native_scale*native_scale]; - scaleTerrainPNGSubImage(water_width, native_scale, water_argb, new_water_argb); - terrain_argb[BLOCKINDEX_STATIONARYWATER] = new_water_argb; - terrain_argb[BLOCKINDEX_MOVINGWATER] = new_water_argb; + int new_argb[] = new int[native_scale*native_scale]; + scaleTerrainPNGSubImage(imgs[image_idx].width, native_scale, imgs[image_idx].argb, new_argb); + terrain_argb[block_idx] = new_argb; + } + /* Get texture pack directory */ private static File getTexturePackDirectory() { return new File(DynmapPlugin.dataDirectory, "texturepacks"); @@ -586,7 +530,7 @@ public class TexturePack { while((line = rdr.readLine()) != null) { if(line.startsWith("block:")) { ArrayList blkids = new ArrayList(); - int databits = 0; + int databits = -1; int faces[] = new int[] { -1, -1, -1, -1, -1, -1 }; line = line.substring(6); String[] args = line.split(","); @@ -638,8 +582,10 @@ public class TexturePack { faces[BlockStep.Y_PLUS.ordinal()] = Integer.parseInt(av[1]); } } + /* If no data bits, assume all */ + if(databits < 0) databits = 0xFFFF; /* If we have everything, build block */ - if((blkids.size() > 0) && (databits != 0)) { + if(blkids.size() > 0) { HDTextureMap map = new HDTextureMap(blkids, databits, faces); map.addToTable(); cnt++; @@ -767,30 +713,34 @@ public class TexturePack { /* Read color from texture */ rslt.setARGB(texture[v*native_scale + u]); if(textop > 0) { + LoadedImage li; /* Switch based on texture modifier */ switch(textop) { case COLORMOD_GRASSTONED: - if(grasscolor_argb == null) { - rslt.blendColor(trivial_grasscolor); + li = imgs[IMG_GRASSCOLOR]; + if(li.argb == null) { + rslt.blendColor(li.trivial_color); } else { - rslt.blendColor(biomeLookup(grasscolor_argb, grasscolor_width, mapiter.getRawBiomeRainfall(), mapiter.getRawBiomeTemperature())); + rslt.blendColor(biomeLookup(li.argb, li.width, mapiter.getRawBiomeRainfall(), mapiter.getRawBiomeTemperature())); } break; case COLORMOD_FOLIAGETONED: - if(foliagecolor_argb == null) { - rslt.blendColor(trivial_foliagecolor); + li = imgs[IMG_FOLIAGECOLOR]; + if(li.argb == null) { + rslt.blendColor(li.trivial_color); } else { - rslt.blendColor(biomeLookup(foliagecolor_argb, foliagecolor_width, mapiter.getRawBiomeRainfall(), mapiter.getRawBiomeTemperature())); + rslt.blendColor(biomeLookup(li.argb, li.width, mapiter.getRawBiomeRainfall(), mapiter.getRawBiomeTemperature())); } break; case COLORMOD_WATERTONED: - if(watercolor_argb == null) { - rslt.blendColor(trivial_watercolor); + li = imgs[IMG_WATERCOLOR]; + if(li.argb == null) { + rslt.blendColor(li.trivial_color); } else { - rslt.blendColor(biomeLookup(watercolor_argb, watercolor_width, mapiter.getRawBiomeRainfall(), mapiter.getRawBiomeTemperature())); + rslt.blendColor(biomeLookup(li.argb, li.width, mapiter.getRawBiomeRainfall(), mapiter.getRawBiomeTemperature())); } break; } diff --git a/src/main/java/org/dynmap/utils/LegacyMapChunkCache.java b/src/main/java/org/dynmap/utils/LegacyMapChunkCache.java index 35ebc8ca..d977f01c 100644 --- a/src/main/java/org/dynmap/utils/LegacyMapChunkCache.java +++ b/src/main/java/org/dynmap/utils/LegacyMapChunkCache.java @@ -264,9 +264,7 @@ public class LegacyMapChunkCache implements MapChunkCache { } catch (NoSuchMethodException nsmx) { } initialized = true; - if(gethandle != null) - Log.info("Chunk snapshot support enabled"); - else { + if(gethandle == null) { Log.severe("ERROR: Chunk snapshot support not found - rendering not functiona!l"); return; } diff --git a/src/main/java/org/dynmap/utils/NewMapChunkCache.java b/src/main/java/org/dynmap/utils/NewMapChunkCache.java index ead6cfc0..463af3fd 100644 --- a/src/main/java/org/dynmap/utils/NewMapChunkCache.java +++ b/src/main/java/org/dynmap/utils/NewMapChunkCache.java @@ -258,10 +258,6 @@ public class NewMapChunkCache implements MapChunkCache { } catch (ClassNotFoundException cnfx) { } catch (NoSuchMethodException nsmx) { } - if(getsnapshot2 != null) - Log.info("Biome data support is enabled"); - else - Log.info("Biome data support is disabled"); init = true; } } diff --git a/texture.txt b/texture.txt index 15a39d5b..d03713f8 100644 --- a/texture.txt +++ b/texture.txt @@ -6,15 +6,15 @@ # 10xxx=inclined-torch,11xxx=grass-side,12xxx=clear if same block ###### # Stone -block:id=1,data=*,allfaces=1 +block:id=1,allfaces=1 # Grass -block:id=2,data=*,allsides=11003,top=1000,bottom=2 +block:id=2,allsides=11003,top=1000,bottom=2 # Dirt -block:id=3,data=*,allfaces=2 +block:id=3,allfaces=2 # Cobblestone -block:id=4,data=*,allfaces=16 +block:id=4,allfaces=16 # Wooden Plank -block:id=5,data=*,allsides=4,topbottom=4004 +block:id=5,allsides=4,topbottom=4004 # Sapling block:id=6,data=0,data=3,allsides=15 # Sapling (Spruce) @@ -22,25 +22,25 @@ block:id=6,data=1,allsides=63 # Sapling (Birch) block:id=6,data=2,allsides=79 # Bedrock -block:id=7,data=*,allfaces=16 +block:id=7,allfaces=16 # Water -block:id=8,data=*,allfaces=12258 +block:id=8,allfaces=12258 # Stationary water -block:id=9,data=*,allfaces=12257 +block:id=9,allfaces=12257 # Lava -block:id=10,data=*,allfaces=260 +block:id=10,allfaces=260 # Stationary Lava -block:id=11,data=*,allfaces=259 +block:id=11,allfaces=259 # Sand -block:id=12,data=*,allfaces=18 +block:id=12,allfaces=18 # Gravel -block:id=13,data=*,allfaces=19 +block:id=13,allfaces=19 # Gold Ore -block:id=14,data=*,allfaces=32 +block:id=14,allfaces=32 # Iron Ore -block:id=15,data=*,allfaces=33 +block:id=15,allfaces=33 # Coal Ore -block:id=16,data=*,allfaces=34 +block:id=16,allfaces=34 # Wood (std) block:id=17,data=0,allsides=20,top=21,bottom=21 # Wood (spruce/pine) @@ -54,13 +54,13 @@ block:id=18,data=1,allfaces=2132 # Leaves (birch) block:id=18,data=2,allfaces=2052 # Sponge -block:id=19,data=*,allfaces=48 +block:id=19,allfaces=48 # Glass -block:id=20,data=*,allfaces=12049 +block:id=20,allfaces=12049 # Lapis Lazuli Ore -block:id=21,data=*,allfaces=160 +block:id=21,allfaces=160 # Lapis Lazuli Block -block:id=22,data=*,allfaces=144 +block:id=22,allfaces=144 # Dispenser (facing east) block:id=23,data=2,top=62,east=46,south=45,north=45,west=45,bottom=62 # Dispenser (facing west) @@ -70,7 +70,7 @@ block:id=23,data=4,top=62,north=46,south=45,east=45,west=45,bottom=62 # Dispenser (facing south) block:id=23,data=5,top=62,south=46,north=45,east=45,west=45,bottom=62 # Sandstone -block:id=24,data=*,top=176,bottom=208,allsides=192 +block:id=24,top=176,bottom=208,allsides=192 # Note Block block:id=25,allfaces=74 # Bed - head - pointing west @@ -126,7 +126,7 @@ block:id=29,data=4,data=12,north=106,south=109,top=108,bottom=5108,east=6108,wes # Sticky piston - facing south block:id=29,data=5,data=13,north=109,south=106,top=5108,bottom=108,east=4108,west=6108 # Web -block:id=30,data=*,allfaces=11 +block:id=30,allfaces=11 # Dead shrub block:id=31,data=0,allsides=55,top=20 # Tall Grass @@ -134,7 +134,7 @@ block:id=31,data=1,allfaces=1039 # Fern block:id=31,data=2,allsides=1056,top=1000 # Dead shrub -block:id=32,data=*,allsides=55,top=20 +block:id=32,allsides=55,top=20 # Piston - facing down block:id=33,data=0,data=8,top=109,bottom=107,allsides=5108 # Piston - facing up @@ -148,7 +148,7 @@ block:id=33,data=4,data=12,north=107,south=109,top=108,bottom=5108,east=6108,wes # Piston - facing south block:id=33,data=5,data=13,north=109,south=107,top=5108,bottom=108,east=4108,west=6108 # Piston extesions - skipped - render all as if closed -block:id=34,data=* +block:id=34 # Wool - white block:id=35,data=0,allfaces=64 # Wool - orange @@ -182,19 +182,19 @@ block:id=35,data=14,allfaces=129 # Wool - Black block:id=35,data=15,allfaces=113 # Block move by piston - don't render -block:id=36,data=* +block:id=36 # Dandelion -block:id=37,data=*,allsides=13,top=162 +block:id=37,allsides=13,top=162 # Rose -block:id=38,data=*,allsides=12,top=129 +block:id=38,allsides=12,top=129 # Brown mushroom -block:id=39,data=*,allsides=29,top=161 +block:id=39,allsides=29,top=161 # Red mushroom -block:id=40,data=*,allsides=28,top=129 +block:id=40,allsides=28,top=129 # Gold block -block:id=41,data=*,allfaces=23 +block:id=41,allfaces=23 # Iron block -block:id=42,data=*,allfaces=22 +block:id=42,allfaces=22 # Double Slab - stone block:id=43,data=0,allsides=5,topbottom=6 # Double Slab - Sandstone @@ -212,35 +212,35 @@ block:id=44,data=2,allsides=4,topbottom=4004 # Slab - Cobblestone block:id=44,data=3,allfaces=16 # Brick Block -block:id=45,data=*,allfaces=7 +block:id=45,allfaces=7 # TNT -block:id=46,data=*,top=9,bottom=10,allsides=8 +block:id=46,top=9,bottom=10,allsides=8 # Bookshelf -block:id=47,data=*,topbottom=4,allsides=35 +block:id=47,topbottom=4,allsides=35 # Mossy Cobblestone -block:id=48,data=*,allfaces=36 +block:id=48,allfaces=36 # Obsidian -block:id=49,data=*,allfaces=37 +block:id=49,allfaces=37 # Torch - inclined block:id=50,data=1,data=2,data=3,data=4,allsides=10080,top=162,bottom=4 # Torch - up block:id=50,data=5,allsides=80,top=162,bottom=4 # Fire -block:id=51,data=*,allsides=129,top=162 +block:id=51,allsides=129,top=162 # Monster spawner -block:id=52,data=*,allfaces=65 +block:id=52,allfaces=65 # Wooden stairs -block:id=53,data=*,allsides=4,topbottom=4004 +block:id=53,allsides=4,topbottom=4004 # Chest - TODO: get entity data so we can see orientation -block:id=54,data=*,top=25,south=27,north=27,east=26,west=26 +block:id=54,top=25,south=27,north=27,east=26,west=26 # Redstone wire (model handling shape - use red wool for color) -block:id=55,data=*,allfaces=129 +block:id=55,allfaces=129 # Diamond ore -block:id=56,data=*,allfaces=50 +block:id=56,allfaces=50 # Diamond block -block:id=57,data=*,allfaces=24 +block:id=57,allfaces=24 # Crafting table -block:id=58,data=*,topbottom=43,east=59,west=59,north=60,south=60 +block:id=58,topbottom=43,east=59,west=59,north=60,south=60 # Crops (size 1) block:id=59,data=0,allsides=88,top=1000 # Crops (size 2) @@ -270,13 +270,13 @@ block:id=61,data=4,top=62,north=61,south=45,east=45,west=45,bottom=62 # Furnace (facing south) block:id=61,data=5,top=62,south=61,north=45,east=45,west=45,bottom=62 # Signpost -block:id=62,data=*,allsides=4,topbottom=4004 +block:id=62,allsides=4,topbottom=4004 # Wooden Door - bottom block:id=64,data=0,data=1,data=2,data=3,data=4,data=5,data=6,data=7,allsides=97,topbottom=4 # Wooden Door - top block:id=64,data=8,data=9,data=10,data=11,data=12,data=13,data=14,data=15,allsides=81,topbottom=4 # Ladders -block:id=65,data=*,allsides=83,topbottom=4 +block:id=65,allsides=83,topbottom=4 # Rail - heading east-west # Rail - incline to east # Rail - incline to west @@ -294,21 +294,21 @@ block:id=66,data=8,topbottom=6112,allsides=4 # Rails - northwest corner block:id=66,data=9,topbottom=112,allsides=4 # Cobblestone Stairs -block:id=67,data=*,allfaces=16 +block:id=67,allfaces=16 # Wall sign -block:id=68,data=*,allsides=4,topbottom=4004 +block:id=68,allsides=4,topbottom=4004 # Switch (just do stone for now) -block:id=69,data=*,allfaces=1 +block:id=69,allfaces=1 # Stone pressure plate -block:id=70,data=*,allfaces=1 +block:id=70,allfaces=1 # Iron Door - bottom block:id=71,data=0,data=1,data=2,data=3,data=4,data=5,data=6,data=7,allsides=98,topbottom=22 # Iron Door - top block:id=71,data=8,data=9,data=10,data=11,data=12,data=13,data=14,data=15,allsides=82,topbottom=22 # Wooden pressure plate -block:id=72,data=*,allsides=4,topbottom=4004 +block:id=72,allsides=4,topbottom=4004 # Redstone Ore -block:id=73,id=74,data=*,allfaces=51 +block:id=73,id=74,allfaces=51 # Redstone Torch - unlit - inclined block:id=75,data=1,data=2,data=3,data=4,allsides=10115,top=162,bottom=4 # Redstone Torch - unlit - up @@ -318,33 +318,33 @@ block:id=76,data=1,data=2,data=3,data=4,allsides=10099,top=162,bottom=4 # Redstone Torch - lit - up block:id=76,data=5,allsides=99,top=162,bottom=4 # Stone button -block:id=77,data=*,allfaces=1 +block:id=77,allfaces=1 # Snow -block:id=78,data=*,allfaces=66 +block:id=78,allfaces=66 # Ice -block:id=79,data=*,allfaces=12067 +block:id=79,allfaces=12067 # Snow block -block:id=80,data=*,allfaces=66 +block:id=80,allfaces=66 # Cactus -block:id=81,data=*,top=69,allsides=70,bottom=71 +block:id=81,top=69,allsides=70,bottom=71 # Clay block -block:id=82,data=*,allfaces=72 +block:id=82,allfaces=72 # Sugar Cane -block:id=83,data=*,allsides=73,topbottom=21 +block:id=83,allsides=73,topbottom=21 # Jukebox -block:id=84,data=*,allsides=74,topbottom=75 +block:id=84,allsides=74,topbottom=75 # Fence -block:id=85,data=*,allsides=4,topbottom=4004 +block:id=85,allsides=4,topbottom=4004 # Pumpkin -block:id=86,data=*,allsides=118,topbottom=102 +block:id=86,allsides=118,topbottom=102 # Netherrock -block:id=87,data=*,allfaces=103 +block:id=87,allfaces=103 # SoulSand -block:id=88,data=*,allfaces=104 +block:id=88,allfaces=104 # Glowstone Block -block:id=89,data=*,allfaces=105 +block:id=89,allfaces=105 # Portal (no texture for this - using purple wool) -block:id=90,data=*,allfaces=193 +block:id=90,allfaces=193 # Jack O Lantern (east) block:id=91,data=0,north=118,south=118,east=120,west=118,topbottom=102 # Jack O Lantern (south) @@ -354,12 +354,12 @@ block:id=91,data=2,north=118,south=118,east=118,west=120,topbottom=102 # Jack O Lantern (north) block:id=91,data=3,north=120,south=118,east=118,west=118,topbottom=102 # Cake Block -block:id=92,data=*,allsides=122,top=121,bottom=124 +block:id=92,allsides=122,top=121,bottom=124 # Repeater (off) -block:id=93,data=*,top=131,allsides=1,bottom=1 +block:id=93,top=131,allsides=1,bottom=1 # Repeater (on) -block:id=94,data=*,top=147,allsides=1,bottom=1 +block:id=94,top=147,allsides=1,bottom=1 # Locked Chest - TODO: get entity data so we can see orientation -block:id=95,data=*,top=25,south=27,north=27,east=26,west=26 +block:id=95,top=25,south=27,north=27,east=26,west=26 # Trap door -block:id=96,data=*,topbottom=84,allsides=4 +block:id=96,topbottom=84,allsides=4 From c74dd49f67735384e4e78d4b0503121d938e58f4 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 17 Jul 2011 16:32:34 -0500 Subject: [PATCH 2/3] Make workaround for adaptive - be faster when bukkit isn't tripping up --- src/main/java/org/dynmap/MapManager.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index 89ea419b..5de07c69 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -296,8 +296,10 @@ public class MapManager { } private class ProcessChunkLoads implements Runnable { + long last_tick; public void run() { int cnt = max_chunk_loads_per_tick; + long tick = System.currentTimeMillis(); while(cnt > 0) { MapChunkCache c = chunkloads.peek(); @@ -311,8 +313,16 @@ public class MapManager { } } } - if(mapman.scheduler != null) - mapman.scheduler.scheduleSyncDelayedTask(mapman.plug_in, this, 1); + if(mapman.scheduler != null) { + /* Detect if bukkit is being stupid - add delay of 1 tick if we're being overfed */ + if((tick - last_tick) >= 35) { /* If at least 35msec since last run, try immediate */ + mapman.scheduler.scheduleSyncDelayedTask(mapman.plug_in, this); + } + else { + mapman.scheduler.scheduleSyncDelayedTask(mapman.plug_in, this, 1); + } + last_tick = tick; + } } } From ff07b6f34310856ba303c6cdc67efb3d946f15c9 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 17 Jul 2011 18:13:03 -0500 Subject: [PATCH 3/3] Fix texture pack scaling support --- .../java/org/dynmap/hdmap/TexturePack.java | 54 ++++++------------- .../org/dynmap/hdmap/TexturePackHDShader.java | 4 ++ texture.txt | 2 +- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/dynmap/hdmap/TexturePack.java b/src/main/java/org/dynmap/hdmap/TexturePack.java index f842a678..c18cbd7d 100644 --- a/src/main/java/org/dynmap/hdmap/TexturePack.java +++ b/src/main/java/org/dynmap/hdmap/TexturePack.java @@ -33,7 +33,6 @@ import org.dynmap.utils.MapIterator; * misc/water.png - still water tile (required)) * misc/grasscolor.png - tone for grass color, biome sensitive (required) * misc/foliagecolor.png - tone for leaf color, biome sensitive (required) - * misc/watercolor.png - tone for water color, biome sensitive (required) * custom_lava_still.png - custom still lava animation (optional) * custom_lava_flowing.png - custom flowing lava animation (optional) * custom_water_still.png - custom still water animation (optional) @@ -47,7 +46,6 @@ public class TexturePack { private static final String TERRAIN_PNG = "terrain.png"; private static final String GRASSCOLOR_PNG = "misc/grasscolor.png"; 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"; @@ -57,7 +55,7 @@ public class TexturePack { /* Color modifier codes (x1000 for value in mapping code) */ 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; private static final int COLORMOD_ROT90 = 4; private static final int COLORMOD_ROT180 = 5; private static final int COLORMOD_ROT270 = 6; @@ -89,13 +87,12 @@ public class TexturePack { private static final int IMG_GRASSCOLOR = 0; private static final int IMG_FOLIAGECOLOR = 1; - private static final int IMG_WATERCOLOR = 2; - private static final int IMG_WATER = 3; - private static final int IMG_CUSTOMWATERMOVING = 4; - private static final int IMG_CUSTOMWATERSTILL = 5; - private static final int IMG_CUSTOMLAVAMOVING = 6; - private static final int IMG_CUSTOMLAVASTILL = 7; - private static final int IMG_CNT = 8; + private static final int IMG_WATER = 2; + private static final int IMG_CUSTOMWATERMOVING = 3; + private static final int IMG_CUSTOMWATERSTILL = 4; + private static final int IMG_CUSTOMLAVAMOVING = 5; + private static final int IMG_CUSTOMLAVASTILL = 6; + private static final int IMG_CNT = 7; private LoadedImage[] imgs = new LoadedImage[IMG_CNT]; @@ -166,9 +163,10 @@ public class TexturePack { private TexturePack(String tpname) throws FileNotFoundException { ZipFile zf = null; File texturedir = getTexturePackDirectory(); + File f = new File(texturedir, tpname); try { /* Try to open zip */ - zf = new ZipFile(new File(texturedir, tpname + ".zip")); + zf = new ZipFile(f); /* Find and load terrain.png */ ZipEntry ze = zf.getEntry(TERRAIN_PNG); /* Try to find terrain.png */ if(ze == null) { @@ -191,13 +189,6 @@ public class TexturePack { is = zf.getInputStream(ze); loadBiomeShadingImage(is, IMG_FOLIAGECOLOR); is.close(); - /* Try to find and load misc/watercolor.png */ - ze = zf.getEntry(WATERCOLOR_PNG); - if(ze == null) - throw new FileNotFoundException(); - is = zf.getInputStream(ze); - loadBiomeShadingImage(is, IMG_WATERCOLOR); - is.close(); /* Try to find and load misc/water.png */ ze = zf.getEntry(WATER_PNG); if(ze == null) @@ -214,10 +205,8 @@ public class TexturePack { if(zf != null) { try { zf.close(); } catch (IOException io) {} } - /* No zip, or bad - try directory next */ } /* Try loading terrain.png from directory of name */ - File f = null; FileInputStream fis = null; try { /* Open and load terrain.png */ @@ -235,11 +224,6 @@ public class TexturePack { fis = new FileInputStream(f); loadBiomeShadingImage(fis, IMG_FOLIAGECOLOR); fis.close(); - /* Check for misc/waterecolor.png */ - f = new File(texturedir, tpname + "/" + WATERCOLOR_PNG); - fis = new FileInputStream(f); - loadBiomeShadingImage(fis, IMG_WATERCOLOR); - fis.close(); /* Check for misc/water.png */ f = new File(texturedir, tpname + "/" + WATER_PNG); fis = new FileInputStream(f); @@ -252,6 +236,8 @@ public class TexturePack { if(fis != null) { try { fis.close(); } catch (IOException io) {} } + Log.info("Cannot process " + f.getPath() + " - " + iox); + throw new FileNotFoundException(); } } @@ -307,6 +293,7 @@ public class TexturePack { /* Load biome shading image into image array */ private void loadBiomeShadingImage(InputStream is, int idx) throws IOException { loadImage(is, idx); /* Get image */ + LoadedImage li = imgs[idx]; /* Get trivial color for biome-shading image */ int clr = li.argb[li.height*li.width*3/4 + li.width/2]; @@ -362,9 +349,9 @@ public class TexturePack { * @param tp */ private void scaleTerrainPNG(TexturePack tp) { - tp.terrain_argb = new int[256][]; + tp.terrain_argb = new int[terrain_argb.length][]; /* Terrain.png is 16x16 array of images : process one at a time */ - for(int idx = 0; idx < 256; idx++) { + for(int idx = 0; idx < terrain_argb.length; idx++) { tp.terrain_argb[idx] = new int[tp.native_scale*tp.native_scale]; scaleTerrainPNGSubImage(native_scale, tp.native_scale, terrain_argb[idx], tp.terrain_argb[idx]); } @@ -499,6 +486,8 @@ public class TexturePack { * Load texture pack mappings */ public static void loadTextureMapping(File datadir) { + /* Initialize map with blank map for all entries */ + HDTextureMap.initializeTable(); /* Load block models */ loadTextureFile(new File(datadir, "texture.txt")); File custom = new File(datadir, "custom-texture.txt"); @@ -521,8 +510,6 @@ public class TexturePack { private static void loadTextureFile(File txtfile) { LineNumberReader rdr = null; int cnt = 0; - /* Initialize map with blank map for all entries */ - HDTextureMap.initializeTable(); try { String line; @@ -734,15 +721,6 @@ public class TexturePack { rslt.blendColor(biomeLookup(li.argb, li.width, mapiter.getRawBiomeRainfall(), mapiter.getRawBiomeTemperature())); } break; - case COLORMOD_WATERTONED: - li = imgs[IMG_WATERCOLOR]; - if(li.argb == null) { - rslt.blendColor(li.trivial_color); - } - else { - rslt.blendColor(biomeLookup(li.argb, li.width, mapiter.getRawBiomeRainfall(), mapiter.getRawBiomeTemperature())); - } - break; } } } diff --git a/src/main/java/org/dynmap/hdmap/TexturePackHDShader.java b/src/main/java/org/dynmap/hdmap/TexturePackHDShader.java index 07f88466..faa0292e 100644 --- a/src/main/java/org/dynmap/hdmap/TexturePackHDShader.java +++ b/src/main/java/org/dynmap/hdmap/TexturePackHDShader.java @@ -1,6 +1,10 @@ package org.dynmap.hdmap; import static org.dynmap.JSONUtils.s; + +import java.io.File; +import java.io.IOException; + import org.bukkit.block.Biome; import org.dynmap.Color; import org.dynmap.ColorScheme; diff --git a/texture.txt b/texture.txt index d03713f8..b99e9161 100644 --- a/texture.txt +++ b/texture.txt @@ -1,7 +1,7 @@ # Mapping of texture resources to block ID and data values # block:id=,data=,top=,bottom=,north=,south=,east=,west=,allfaces=,allsides= # =0-255 (index of patch in terrain.png), -1=clear, 1xxx=biome tint from grasscolor.png,257=stationary water,258=moving water, -# 259=stationary lava,260=moving lava,2xxx=biome tint from foliagecolor.png,3xxx=biome tint from watercolor.png,4xxx=rotate texture 90, +# 259=stationary lava,260=moving lava,2xxx=biome tint from foliagecolor.png,4xxx=rotate texture 90, # 5xxx=rotate texture 180, 6xxx=rotate texture 270, 7xxx=flip texture horizontally, 8xxx=shift down 1/2 block, 9=shift down 1/2,flip horiz, # 10xxx=inclined-torch,11xxx=grass-side,12xxx=clear if same block ######