Add tile data coloring (aka colored wool support), combine rendering

of default tiles and their zoomed counterparts (saves reloading the
default tile, and keeps the scale levels of the map consistent during
a fullrender and otherwise)
This commit is contained in:
Mike Primm 2011-05-11 23:07:31 -05:00 committed by FrozenCow
parent 0a8f2a182a
commit 17644a5778
10 changed files with 241 additions and 106 deletions

View File

@ -68,6 +68,22 @@ Black Cloth
34 0 0 0 255 0 0 0 255 0 0 0 255 0 0 0 255
Wool
35 222 222 222 255 177 177 177 255 111 111 111 255 88 88 88 255
35:0 222 222 222 255 177 177 177 255 111 111 111 255 88 88 88 255
35:1 204 111 48 255 162 89 38 255 102 56 24 255 81 44 19 255
35:2 166 66 175 255 133 53 140 255 83 33 87 255 66 26 69 255
35:3 91 121 185 255 73 96 147 255 46 61 92 255 36 48 73 255
35:4 170 158 24 255 135 126 19 255 85 79 12 255 67 62 10 255
35:5 51 165 42 255 41 131 33 255 26 82 21 255 20 65 17 255
35:6 190 115 135 255 151 92 108 255 95 57 67 255 75 46 53 255
35:7 58 58 58 255 47 47 47 255 29 29 29 255 23 23 23 255
35:8 138 145 145 255 110 115 115 255 69 72 72 255 55 57 57 255
35:9 34 102 131 255 27 81 104 255 17 51 65 255 13 40 52 255
35:10 113 47 171 255 90 37 136 255 57 24 85 255 45 19 68 255
35:11 34 44 134 255 27 35 107 255 17 22 67 255 13 18 53 255
35:12 75 44 24 255 60 35 19 255 37 22 12 255 30 18 10 255
35:13 49 67 21 255 39 53 17 255 24 34 10 255 19 27 8 255
35:14 143 39 36 255 114 31 28 255 71 20 18 255 57 16 14 255
35:15 24 20 20 255 19 16 16 255 12 10 10 255 9 8 8 255
Gray Cloth
36 125 125 125 255 114 114 114 255 104 104 104 255 86 86 86 255
Yellow Flower

View File

@ -68,6 +68,22 @@ Black Cloth
34 0 0 0 255 0 0 0 255 0 0 0 255 0 0 0 255
Wool
35 247 255 239 255 244 251 236 255 204 210 197 255 244 251 236 255
35:0 247 255 239 255 244 251 236 255 204 210 197 255 244 251 236 255
35:1 227 128 52 255 224 126 51 255 187 105 42 255 224 126 51 255
35:2 185 76 188 255 183 75 186 255 153 63 155 255 183 75 186 255
35:3 102 139 199 255 100 137 196 255 84 114 164 255 100 137 196 255
35:4 189 181 26 255 187 178 26 255 156 149 22 255 187 178 26 255
35:5 57 189 45 255 56 186 44 255 47 156 37 255 56 186 44 255
35:6 211 132 145 255 209 130 143 255 174 109 120 255 209 130 143 255
35:7 65 67 63 255 64 66 62 255 54 55 52 255 64 66 62 255
35:8 154 166 156 255 152 163 154 255 127 137 128 255 152 163 154 255
35:9 38 117 141 255 37 115 139 255 31 96 116 255 37 115 139 255
35:10 126 54 184 255 124 53 181 255 104 44 151 255 124 53 181 255
35:11 38 51 144 255 37 50 143 255 31 42 119 255 37 50 143 255
35:12 83 51 26 255 82 50 26 255 69 42 22 255 82 50 26 255
35:13 54 77 22 255 54 76 22 255 45 63 19 255 54 76 22 255
35:14 159 45 38 255 157 44 38 255 131 37 32 255 157 44 38 255
35:15 26 23 22 255 26 23 21 255 22 19 18 255 26 23 21 255
Gray Cloth
36 125 125 125 255 114 114 114 255 104 104 104 255 86 86 86 255
Yellow Flower

View File

@ -68,6 +68,22 @@ Black Cloth
34 0 0 0 255 0 0 0 255 0 0 0 255 0 0 0 255
Wool
35 222 222 222 255 177 177 177 255 111 111 111 255 88 88 88 255
35:0 222 222 222 255 177 177 177 255 111 111 111 255 88 88 88 255
35:1 204 111 48 255 162 89 38 255 102 56 24 255 81 44 19 255
35:2 166 66 175 255 133 53 140 255 83 33 87 255 66 26 69 255
35:3 91 121 185 255 73 96 147 255 46 61 92 255 36 48 73 255
35:4 170 158 24 255 135 126 19 255 85 79 12 255 67 62 10 255
35:5 51 165 42 255 41 131 33 255 26 82 21 255 20 65 17 255
35:6 190 115 135 255 151 92 108 255 95 57 67 255 75 46 53 255
35:7 58 58 58 255 47 47 47 255 29 29 29 255 23 23 23 255
35:8 138 145 145 255 110 115 115 255 69 72 72 255 55 57 57 255
35:9 34 102 131 255 27 81 104 255 17 51 65 255 13 40 52 255
35:10 113 47 171 255 90 37 136 255 57 24 85 255 45 19 68 255
35:11 34 44 134 255 27 35 107 255 17 22 67 255 13 18 53 255
35:12 75 44 24 255 60 35 19 255 37 22 12 255 30 18 10 255
35:13 49 67 21 255 39 53 17 255 24 34 10 255 19 27 8 255
35:14 143 39 36 255 114 31 28 255 71 20 18 255 57 16 14 255
35:15 24 20 20 255 19 16 16 255 12 10 10 255 9 8 8 255
Gray Cloth
36 125 125 125 255 114 114 114 255 104 104 104 255 86 86 86 255
Yellow Flower

View File

@ -17,6 +17,22 @@
18 27 69 37 180 22 57 31 180 19 48 25 180 22 57 31 180
20 178 217 223 90 148 181 186 90 124 151 155 90 148 181 186 90
35 247 255 239 255 244 251 236 255 204 210 197 255 244 251 236 255
35:0 247 255 239 255 244 251 236 255 204 210 197 255 244 251 236 255
35:1 227 128 52 255 224 126 51 255 187 105 42 255 224 126 51 255
35:2 185 76 188 255 183 75 186 255 153 63 155 255 183 75 186 255
35:3 102 139 199 255 100 137 196 255 84 114 164 255 100 137 196 255
35:4 189 181 26 255 187 178 26 255 156 149 22 255 187 178 26 255
35:5 57 189 45 255 56 186 44 255 47 156 37 255 56 186 44 255
35:6 211 132 145 255 209 130 143 255 174 109 120 255 209 130 143 255
35:7 65 67 63 255 64 66 62 255 54 55 52 255 64 66 62 255
35:8 154 166 156 255 152 163 154 255 127 137 128 255 152 163 154 255
35:9 38 117 141 255 37 115 139 255 31 96 116 255 37 115 139 255
35:10 126 54 184 255 124 53 181 255 104 44 151 255 124 53 181 255
35:11 38 51 144 255 37 50 143 255 31 42 119 255 37 50 143 255
35:12 83 51 26 255 82 50 26 255 69 42 22 255 82 50 26 255
35:13 54 77 22 255 54 76 22 255 45 63 19 255 54 76 22 255
35:14 159 45 38 255 157 44 38 255 131 37 32 255 157 44 38 255
35:15 26 23 22 255 26 23 21 255 22 19 18 255 26 23 21 255
36 0 0 0 254 0 0 0 254 0 0 0 254 0 0 0 254
37 73 108 60 254 61 90 50 254 51 75 42 254 61 90 50 254
38 84 139 187 254 70 116 155 254 59 97 130 254 70 116 155 254

View File

@ -17,11 +17,14 @@ public class ColorScheme {
private static final HashMap<String, ColorScheme> cache = new HashMap<String, ColorScheme>();
public String name;
public java.util.Map<Integer, Color[]> colors;
/* Switch to arrays - faster than map */
public Color[][] colors; /* [blk-type][step] */
public Color[][][] datacolors; /* [bkt-type][blk-dat][step] */
public ColorScheme(String name, java.util.Map<Integer, Color[]> colors) {
public ColorScheme(String name, Color[][] colors, Color[][][] datacolors) {
this.name = name;
this.colors = colors;
this.datacolors = datacolors;
}
private static File getColorSchemeDirectory() {
@ -41,8 +44,10 @@ public class ColorScheme {
public static ColorScheme loadScheme(String name) {
File colorSchemeFile = new File(getColorSchemeDirectory(), name + ".txt");
java.util.Map<Integer, Color[]> colors = new HashMap<Integer, Color[]>();
Color[][] colors = new Color[256][];
Color[][][] datacolors = new Color[256][][];
InputStream stream;
boolean enab_datacolor = MapManager.mapman.doSyncRender();
try {
Debug.debug("Loading colors from '" + colorSchemeFile + "'...");
stream = new FileInputStream(colorSchemeFile);
@ -59,9 +64,17 @@ public class ColorScheme {
if (split.length < 17) {
continue;
}
Integer id = new Integer(split[0]);
System.out.println(split[0]);
Integer id;
Integer dat = null;
int idx = split[0].indexOf(':');
if(idx > 0) { /* ID:data - data color */
id = new Integer(split[0].substring(0, idx));
dat = new Integer(split[0].substring(idx+1));
}
else {
id = new Integer(split[0]);
}
Color[] c = new Color[4];
/* store colors by raycast sequence number */
@ -70,16 +83,44 @@ public class ColorScheme {
c[1] = new Color(Integer.parseInt(split[9]), Integer.parseInt(split[10]), Integer.parseInt(split[11]), Integer.parseInt(split[12]));
c[2] = new Color(Integer.parseInt(split[13]), Integer.parseInt(split[14]), Integer.parseInt(split[15]), Integer.parseInt(split[16]));
colors.put(id, c);
if(dat != null) {
if(enab_datacolor) {
Color[][] dcolor = datacolors[id]; /* Existing list? */
if(dcolor == null) {
dcolor = new Color[16][]; /* Make 16 index long list */
datacolors[id] = dcolor;
}
if((dat >= 0) && (dat < 16)) { /* Add color to list */
dcolor[dat] = c;
}
}
if(dat == 0) { /* Index zero is base color too */
colors[id] = c;
}
}
else {
colors[id] = c;
}
nc += 1;
}
scanner.close();
/* Last, push base color into any open slots in data colors list */
for(int k = 0; k < 256; k++) {
Color[][] dc = datacolors[k]; /* see if data colors too */
if(dc != null) {
Color[] c = colors[k];
for(int i = 0; i < 16; i++) {
if(dc[i] == null)
dc[i] = c;
}
}
}
} catch (RuntimeException e) {
log.log(Level.SEVERE, "Could not load colors '" + name + "' ('" + colorSchemeFile + "').", e);
return null;
} catch (FileNotFoundException e) {
log.log(Level.SEVERE, "Could not load colors '" + name + "' ('" + colorSchemeFile + "'): File not found.", e);
}
return new ColorScheme(name, colors);
return new ColorScheme(name, colors, datacolors);
}
}

View File

@ -180,6 +180,10 @@ public class MapManager {
w.run.run();
}
}, 10);
do_timesliced_render = configuration.getBoolean("timeslicerender", true);
timeslice_interval = configuration.getDouble("timesliceinterval", 0.5);
do_sync_render = configuration.getBoolean("renderonsync", true);
for(Object worldConfigurationObj : (List<?>)configuration.getProperty("worlds")) {
Map<?, ?> worldConfiguration = (Map<?, ?>)worldConfigurationObj;
@ -196,9 +200,6 @@ public class MapManager {
if (bukkitWorld != null)
activateWorld(bukkitWorld);
}
do_timesliced_render = configuration.getBoolean("timeslicerender", true);
timeslice_interval = configuration.getDouble("timesliceinterval", 0.5);
do_sync_render = configuration.getBoolean("renderonsync", true);
scheduler = plugin.getServer().getScheduler();
plug_in = plugin;
@ -370,7 +371,7 @@ public class MapManager {
}
private HashMap<World, File> worldTileDirectories = new HashMap<World, File>();
private File getTileFile(MapTile tile) {
public File getTileFile(MapTile tile) {
World world = tile.getWorld();
File worldTileDirectory = worldTileDirectories.get(world);
if (worldTileDirectory == null) {
@ -410,4 +411,8 @@ public class MapManager {
handler.run = run;
writeQueue.push(handler);
}
public boolean doSyncRender() {
return do_sync_render;
}
}

View File

@ -81,7 +81,7 @@ public class FlatMap extends MapType {
int mz = y + t.y * t.size;
int my = w.getHighestBlockYAt(mx, mz) - 1;
int blockType = w.getBlockTypeIdAt(mx, my, mz);
Color[] colors = colorScheme.colors.get(blockType);
Color[] colors = colorScheme.colors[blockType];
if (colors == null)
continue;
Color c = colors[0];

View File

@ -1,6 +1,8 @@
package org.dynmap.kzedmap;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
@ -25,6 +27,25 @@ public class DefaultTileRenderer implements MapTileRenderer {
protected HashSet<Integer> highlightBlocks = new HashSet<Integer>();
protected Color highlightColor = new Color(255, 0, 0);
private static final Color[] woolshades = {
Color.WHITE,
Color.ORANGE,
Color.MAGENTA,
new Color(51,204,255),
Color.YELLOW,
new Color(102,255,102),
Color.PINK,
Color.GRAY,
Color.LIGHT_GRAY,
Color.CYAN,
new Color(255,0,255),
Color.BLUE,
new Color(102,51,51),
Color.GREEN,
Color.RED,
Color.BLACK
};
@Override
public String getName() {
@ -111,27 +132,90 @@ public class DefaultTileRenderer implements MapTileRenderer {
final File fname = outputFile;
final KzedMapTile mtile = tile;
final BufferedImage img = im;
MapManager.mapman.enqueueImageWrite(new Runnable() {
final KzedZoomedMapTile zmtile = new KzedZoomedMapTile(mtile.getWorld(),
(KzedMap) mtile.getMap(), mtile);
final File zoomFile = MapManager.mapman.getTileFile(zmtile);
MapManager.mapman.enqueueImageWrite(new Runnable() {
public void run() {
Debug.debug("saving image " + fname.getPath());
try {
ImageIO.write(img, "png", fname);
} catch (IOException e) {
Debug.error("Failed to save image: " + fname.getPath(), e);
} catch (java.lang.NullPointerException e) {
Debug.error("Failed to save image (NullPointerException): " + fname.getPath(), e);
}
img.flush();
mtile.file = fname;
((KzedMap)mtile.getMap()).invalidateTile(
new KzedZoomedMapTile(mtile.getWorld(), (KzedMap) mtile.getMap(), mtile));
MapManager.mapman.pushUpdate(mtile.getWorld(),
new Client.Tile(mtile.getFilename()));
doFileWrites(fname, mtile, img, zmtile, zoomFile);
}
});
return !isempty;
}
private void doFileWrites(final File fname, final KzedMapTile mtile,
final BufferedImage img, final KzedZoomedMapTile zmtile, final File zoomFile) {
Debug.debug("saving image " + fname.getPath());
try {
ImageIO.write(img, "png", fname);
} catch (IOException e) {
Debug.error("Failed to save image: " + fname.getPath(), e);
} catch (java.lang.NullPointerException e) {
Debug.error("Failed to save image (NullPointerException): " + fname.getPath(), e);
}
mtile.file = fname;
// Since we've already got the new tile, and we're on an async thread, just
// make the zoomed tile here
int px = mtile.px;
int py = mtile.py;
int zpx = zmtile.getTileX();
int zpy = zmtile.getTileY();
/* scaled size */
int scw = KzedMap.tileWidth / 2;
int sch = KzedMap.tileHeight / 2;
/* origin in zoomed-out tile */
int ox = 0;
int oy = 0;
if (zpx != px)
ox = scw;
if (zpy != py)
oy = sch;
BufferedImage zIm = null;
try {
zIm = ImageIO.read(zoomFile);
} catch (IOException e) {
} catch (IndexOutOfBoundsException e) {
}
if (zIm == null) {
/* create new one */
zIm = new BufferedImage(KzedMap.tileWidth, KzedMap.tileHeight, BufferedImage.TYPE_INT_RGB);
Debug.debug("New zoom-out tile created " + zmtile.getFilename());
} else {
Debug.debug("Loaded zoom-out tile from " + zmtile.getFilename());
}
/* blit scaled rendered tile onto zoom-out tile */
Graphics2D g2 = zIm.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(img, ox, oy, scw, sch, null);
img.flush();
/* save zoom-out tile */
try {
ImageIO.write(zIm, "png", zoomFile);
Debug.debug("Saved zoom-out tile at " + zoomFile.getName());
} catch (IOException e) {
Debug.error("Failed to save zoom-out tile: " + zoomFile.getName(), e);
} catch (java.lang.NullPointerException e) {
Debug.error("Failed to save zoom-out tile (NullPointerException): " + zoomFile.getName(), e);
}
zIm.flush();
/* Push updates for both files.*/
MapManager.mapman.pushUpdate(mtile.getWorld(),
new Client.Tile(mtile.getFilename()));
MapManager.mapman.pushUpdate(zmtile.getWorld(),
new Client.Tile(zmtile.getFilename()));
}
protected Color scan(World world, int x, int y, int z, int seq) {
for (;;) {
@ -139,7 +223,10 @@ public class DefaultTileRenderer implements MapTileRenderer {
return translucent;
int id = world.getBlockTypeIdAt(x, y, z);
byte data = 0;
if(colorScheme.datacolors[id] != null) { /* If data colored */
data = world.getBlockAt(x, y, z).getData();
}
switch (seq) {
case 0:
x--;
@ -161,7 +248,11 @@ public class DefaultTileRenderer implements MapTileRenderer {
if (highlightBlocks.contains(id)) {
return highlightColor;
}
Color[] colors = colorScheme.colors.get(id);
Color[] colors;
if(data != 0)
colors = colorScheme.datacolors[id][data];
else
colors = colorScheme.colors[id];
if (colors != null) {
Color c = colors[seq];
if (c.getAlpha() > 0) {

View File

@ -31,6 +31,10 @@ public class HighlightTileRenderer extends DefaultTileRenderer {
}
int id = world.getBlockTypeIdAt(x, y, z);
byte data = 0;
if(colorScheme.datacolors[id] != null) { /* If data colored */
data = world.getBlockAt(x, y, z).getData();
}
switch (seq) {
case 0:
@ -50,7 +54,11 @@ public class HighlightTileRenderer extends DefaultTileRenderer {
seq = (seq + 1) & 3;
if (id != 0) {
Color[] colors = colorScheme.colors.get(id);
Color[] colors;
if(data != 0)
colors = colorScheme.datacolors[id][data];
else
colors = colorScheme.colors[id];
if (colors != null) {
Color c = colors[seq];

View File

@ -18,80 +18,6 @@ public class ZoomedTileRenderer {
}
public void render(final KzedZoomedMapTile zt, final File outputPath) {
/* Hand it all to map manager write thread */
MapManager.mapman.enqueueImageWrite(new Runnable() {
public void run() {
KzedMapTile originalTile = zt.originalTile;
int px = originalTile.px;
int py = originalTile.py;
int zpx = zt.getTileX();
int zpy = zt.getTileY();
BufferedImage image = null;
try {
image = ImageIO.read(originalTile.file);
} catch (IOException e) {
} catch (IndexOutOfBoundsException e) {
}
if (image == null) {
Debug.debug("Could not load original tile, won't render zoom-out tile.");
return;
}
BufferedImage zIm = null;
File zoomFile = outputPath;
try {
zIm = ImageIO.read(zoomFile);
} catch (IOException e) {
} catch (IndexOutOfBoundsException e) {
}
if (zIm == null) {
/* create new one */
zIm = new BufferedImage(KzedMap.tileWidth, KzedMap.tileHeight, BufferedImage.TYPE_INT_RGB);
Debug.debug("New zoom-out tile created " + zt.getFilename());
} else {
Debug.debug("Loaded zoom-out tile from " + zt.getFilename());
}
/* update zoom-out tile */
/* scaled size */
int scw = KzedMap.tileWidth / 2;
int sch = KzedMap.tileHeight / 2;
/* origin in zoomed-out tile */
int ox = 0;
int oy = 0;
if (zpx != px)
ox = scw;
if (zpy != py)
oy = sch;
/* blit scaled rendered tile onto zoom-out tile */
// WritableRaster zr = zIm.getRaster();
Graphics2D g2 = zIm.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(image, ox, oy, scw, sch, null);
image.flush();
/* save zoom-out tile */
try {
ImageIO.write(zIm, "png", zoomFile);
Debug.debug("Saved zoom-out tile at " + zoomFile.getName());
} catch (IOException e) {
Debug.error("Failed to save zoom-out tile: " + zoomFile.getName(), e);
} catch (java.lang.NullPointerException e) {
Debug.error("Failed to save zoom-out tile (NullPointerException): " + zoomFile.getName(), e);
}
zIm.flush();
MapManager.mapman.pushUpdate(zt.getWorld(),
new Client.Tile(zt.getFilename()));
}
});
return; /* Doing this in Default render, since image already loaded */
}
}