mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 05:05:16 +01:00
Re-merge the nether render support, and update race condition fixes
This commit is contained in:
parent
600dd00bcd
commit
0ffc825b05
@ -75,7 +75,7 @@ worlds:
|
||||
renderers:
|
||||
- class: org.dynmap.kzedmap.DefaultTileRenderer
|
||||
prefix: nt
|
||||
maximumheight: 64
|
||||
maximumheight: 127
|
||||
colorscheme: default
|
||||
|
||||
web:
|
||||
|
@ -115,6 +115,10 @@ public class DynmapPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
registerEvents();
|
||||
|
||||
/* Print version info */
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
log.info("[dynmap] version " + pdfFile.getVersion() + " is enabled" );
|
||||
}
|
||||
|
||||
public void loadWebserver() {
|
||||
@ -157,9 +161,7 @@ public class DynmapPlugin extends JavaPlugin {
|
||||
} catch (IOException e) {
|
||||
log.severe("Failed to start WebServer on " + bindAddress + ":" + port + "!");
|
||||
}
|
||||
/* Print version info */
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
log.info("[dynmap] version " + pdfFile.getVersion() + " is enabled" );
|
||||
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
@ -11,10 +11,11 @@ public class UpdateQueue {
|
||||
|
||||
private static final int maxUpdateAge = 120000;
|
||||
|
||||
public synchronized void pushUpdate(Object obj) {
|
||||
public void pushUpdate(Object obj) {
|
||||
synchronized (lock) {
|
||||
/* Do inside lock - prevent delay between time and actual work */
|
||||
long now = System.currentTimeMillis();
|
||||
long deadline = now - maxUpdateAge;
|
||||
synchronized (lock) {
|
||||
ListIterator<Update> i = updateQueue.listIterator(0);
|
||||
while (i.hasNext()) {
|
||||
Update u = i.next();
|
||||
@ -27,11 +28,11 @@ public class UpdateQueue {
|
||||
|
||||
private ArrayList<Object> tmpupdates = new ArrayList<Object>();
|
||||
|
||||
public synchronized Object[] getUpdatedObjects(long since) {
|
||||
long now = System.currentTimeMillis();
|
||||
long deadline = now - maxUpdateAge;
|
||||
public Object[] getUpdatedObjects(long since) {
|
||||
Object[] updates;
|
||||
synchronized (lock) {
|
||||
long now = System.currentTimeMillis();
|
||||
long deadline = now - maxUpdateAge;
|
||||
tmpupdates.clear();
|
||||
Iterator<Update> it = updateQueue.descendingIterator();
|
||||
while (it.hasNext()) {
|
||||
|
@ -11,6 +11,7 @@ import javax.imageio.ImageIO;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.dynmap.Client;
|
||||
import org.dynmap.ColorScheme;
|
||||
import org.dynmap.DynmapChunk;
|
||||
@ -22,10 +23,17 @@ import org.dynmap.debug.Debug;
|
||||
public class FlatMap extends MapType {
|
||||
private String prefix;
|
||||
private ColorScheme colorScheme;
|
||||
private int maximumHeight = 127;
|
||||
|
||||
public FlatMap(Map<String, Object> configuration) {
|
||||
prefix = (String) configuration.get("prefix");
|
||||
colorScheme = ColorScheme.getScheme((String) configuration.get("colorscheme"));
|
||||
Object o = configuration.get("maximumheight");
|
||||
if (o != null) {
|
||||
maximumHeight = Integer.parseInt(String.valueOf(o));
|
||||
if (maximumHeight > 127)
|
||||
maximumHeight = 127;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,6 +76,7 @@ public class FlatMap extends MapType {
|
||||
public boolean render(MapTile tile, File outputFile) {
|
||||
FlatMapTile t = (FlatMapTile) tile;
|
||||
World w = t.getWorld();
|
||||
boolean isnether = (w.getEnvironment() == Environment.NETHER) && (maximumHeight == 127);
|
||||
|
||||
boolean rendered = false;
|
||||
BufferedImage im = new BufferedImage(t.size, t.size, BufferedImage.TYPE_INT_RGB);
|
||||
@ -79,17 +88,40 @@ public class FlatMap extends MapType {
|
||||
for (int y = 0; y < t.size; y++) {
|
||||
int mx = x + t.x * t.size;
|
||||
int mz = y + t.y * t.size;
|
||||
int my = w.getHighestBlockYAt(mx, mz) - 1;
|
||||
int blockType = w.getBlockTypeIdAt(mx, my, mz);
|
||||
byte data = 0;
|
||||
if(colorScheme.datacolors[blockType] != null) { /* If data colored */
|
||||
data = w.getBlockAt(mx, my, mz).getData();
|
||||
int my;
|
||||
int blockType;
|
||||
if(isnether) {
|
||||
/* Scan until we hit air */
|
||||
my = 127;
|
||||
while((blockType = w.getBlockTypeIdAt(mx, my, mz)) != 0) {
|
||||
my--;
|
||||
if(my < 0) { /* Solid - use top */
|
||||
my = 127;
|
||||
blockType = w.getBlockTypeIdAt(mx, my, mz);
|
||||
break;
|
||||
}
|
||||
Color[] colors;
|
||||
if(data != 0)
|
||||
}
|
||||
if(blockType == 0) { /* Hit air - now find non-air */
|
||||
while((blockType = w.getBlockTypeIdAt(mx, my, mz)) == 0) {
|
||||
my--;
|
||||
if(my < 0) {
|
||||
my = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
my = w.getHighestBlockYAt(mx, mz) - 1;
|
||||
if(my > maximumHeight) my = maximumHeight;
|
||||
blockType = w.getBlockTypeIdAt(mx, my, mz);
|
||||
}
|
||||
byte data = 0;
|
||||
Color[] colors = colorScheme.colors[blockType];
|
||||
if(colorScheme.datacolors[blockType] != null) {
|
||||
data = w.getBlockAt(mx, my, mz).getData();
|
||||
colors = colorScheme.datacolors[blockType][data];
|
||||
else
|
||||
colors = colorScheme.colors[blockType];
|
||||
}
|
||||
if (colors == null)
|
||||
continue;
|
||||
Color c = colors[0];
|
||||
|
@ -12,7 +12,7 @@ public class CaveTileRenderer extends DefaultTileRenderer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color scan(World world, int x, int y, int z, int seq) {
|
||||
protected Color scan(World world, int x, int y, int z, int seq, boolean isnether) {
|
||||
boolean air = true;
|
||||
|
||||
for (;;) {
|
||||
@ -20,6 +20,12 @@ public class CaveTileRenderer extends DefaultTileRenderer {
|
||||
return translucent;
|
||||
|
||||
int id = world.getBlockTypeIdAt(x, y, z);
|
||||
if(isnether) { /* Make ceiling into air in nether */
|
||||
if(id != 0)
|
||||
id = 0;
|
||||
else
|
||||
isnether = false;
|
||||
}
|
||||
|
||||
switch (seq) {
|
||||
case 0:
|
||||
|
@ -12,7 +12,9 @@ import java.util.Map;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.dynmap.Client;
|
||||
import org.dynmap.ColorScheme;
|
||||
import org.dynmap.MapManager;
|
||||
@ -28,25 +30,6 @@ 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() {
|
||||
return name;
|
||||
@ -65,6 +48,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
||||
|
||||
public boolean render(KzedMapTile tile, File outputFile) {
|
||||
World world = tile.getWorld();
|
||||
boolean isnether = (world.getEnvironment() == Environment.NETHER);
|
||||
BufferedImage im = new BufferedImage(KzedMap.tileWidth, KzedMap.tileHeight, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
WritableRaster r = im.getRaster();
|
||||
@ -74,6 +58,10 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
||||
int iy = maximumHeight;
|
||||
int iz = KzedMap.anchorz + tile.px / 2 - tile.py / 2 + ((127-maximumHeight)/2);
|
||||
|
||||
/* Don't mess with existing height-clipped renders */
|
||||
if(maximumHeight < 127)
|
||||
isnether = false;
|
||||
|
||||
int jx, jz;
|
||||
|
||||
int x, y;
|
||||
@ -84,8 +72,8 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
||||
jz = iz;
|
||||
|
||||
for (x = KzedMap.tileWidth - 1; x >= 0; x -= 2) {
|
||||
Color c1 = scan(world, jx, iy, jz, 0);
|
||||
Color c2 = scan(world, jx, iy, jz, 2);
|
||||
Color c1 = scan(world, jx, iy, jz, 0, isnether);
|
||||
Color c2 = scan(world, jx, iy, jz, 2, isnether);
|
||||
isempty = isempty && c1 == translucent && c2 == translucent;
|
||||
r.setPixel(x, y, new int[] {
|
||||
c1.getRed(),
|
||||
@ -107,10 +95,10 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
||||
jz = iz - 1;
|
||||
|
||||
for (x = KzedMap.tileWidth - 1; x >= 0; x -= 2) {
|
||||
Color c1 = scan(world, jx, iy, jz, 2);
|
||||
Color c1 = scan(world, jx, iy, jz, 2, isnether);
|
||||
jx++;
|
||||
jz++;
|
||||
Color c2 = scan(world, jx, iy, jz, 0);
|
||||
Color c2 = scan(world, jx, iy, jz, 0, isnether);
|
||||
isempty = isempty && c1 == translucent && c2 == translucent;
|
||||
r.setPixel(x, y, new int[] {
|
||||
c1.getRed(),
|
||||
@ -217,13 +205,25 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
||||
}
|
||||
|
||||
|
||||
protected Color scan(World world, int x, int y, int z, int seq) {
|
||||
protected Color scan(World world, int x, int y, int z, int seq, boolean isnether) {
|
||||
Color result = translucent;
|
||||
for (;;) {
|
||||
if (y < 0)
|
||||
return translucent;
|
||||
|
||||
if (y < 0) {
|
||||
return result;
|
||||
}
|
||||
int id = world.getBlockTypeIdAt(x, y, z);
|
||||
byte data = 0;
|
||||
if(isnether) { /* Make bedrock ceiling into air in nether */
|
||||
if(id != 0) {
|
||||
/* Remember first color we see, in case we wind up solid */
|
||||
if(result == translucent)
|
||||
if(colorScheme.colors[id] != null)
|
||||
result = colorScheme.colors[id][seq];
|
||||
id = 0;
|
||||
}
|
||||
else
|
||||
isnether = false;
|
||||
}
|
||||
if(colorScheme.datacolors[id] != null) { /* If data colored */
|
||||
data = world.getBlockAt(x, y, z).getData();
|
||||
}
|
||||
@ -263,7 +263,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
||||
}
|
||||
|
||||
/* this block is transparent, so recurse */
|
||||
Color bg = scan(world, x, y, z, seq);
|
||||
Color bg = scan(world, x, y, z, seq, isnether);
|
||||
|
||||
int cr = c.getRed();
|
||||
int cg = c.getGreen();
|
||||
|
@ -23,14 +23,26 @@ public class HighlightTileRenderer extends DefaultTileRenderer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color scan(World world, int x, int y, int z, int seq) {
|
||||
protected Color scan(World world, int x, int y, int z, int seq, boolean isnether) {
|
||||
Color result = translucent;
|
||||
int top_nether_id = 0;
|
||||
for (;;) {
|
||||
if (y < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
int id = world.getBlockTypeIdAt(x, y, z);
|
||||
if(isnether) { /* Make bedrock ceiling into air in nether */
|
||||
if(id != 0) {
|
||||
/* Remember first color we see, in case we wind up solid */
|
||||
if(result == translucent)
|
||||
if(colorScheme.colors[id] != null)
|
||||
result = colorScheme.colors[id][seq];
|
||||
id = 0;
|
||||
}
|
||||
else
|
||||
isnether = false;
|
||||
}
|
||||
byte data = 0;
|
||||
if(colorScheme.datacolors[id] != null) { /* If data colored */
|
||||
data = world.getBlockAt(x, y, z).getData();
|
||||
|
@ -1,18 +1,8 @@
|
||||
package org.dynmap.kzedmap;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.dynmap.Client;
|
||||
import org.dynmap.MapManager;
|
||||
import org.dynmap.debug.Debug;
|
||||
|
||||
public class ZoomedTileRenderer {
|
||||
public ZoomedTileRenderer(Map<String, Object> configuration) {
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ DynMap.prototype = {
|
||||
|
||||
swtch(update.type, {
|
||||
tile: function() {
|
||||
me.onTileUpdated(update.name);
|
||||
me.onTileUpdated(update.name,update.timestamp);
|
||||
},
|
||||
playerjoin: function() {
|
||||
$(me).trigger('playerjoin', [ update.playerName ]);
|
||||
@ -436,12 +436,12 @@ DynMap.prototype = {
|
||||
unregisterTile: function(mapType, tileName) {
|
||||
delete this.registeredTiles[tileName];
|
||||
},
|
||||
onTileUpdated: function(tileName) {
|
||||
onTileUpdated: function(tileName,timestamp) {
|
||||
var me = this;
|
||||
var tile = this.registeredTiles[tileName];
|
||||
|
||||
if (tile) {
|
||||
tile.lastseen = this.lasttimestamp;
|
||||
tile.lastseen = timestamp;
|
||||
tile.mapType.onTileUpdated(tile.tileElement, tileName);
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user