mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-25 18:17:37 +01:00
Added unstable fullmap rendering. Also... messed up formatting by pressing ctrl+shift+f in eclipse, sigh
This commit is contained in:
parent
138aed8c33
commit
c8cf39a440
9
src/main/java/org/dynmap/DynmapChunk.java
Normal file
9
src/main/java/org/dynmap/DynmapChunk.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package org.dynmap;
|
||||||
|
|
||||||
|
public class DynmapChunk {
|
||||||
|
public int x,y;
|
||||||
|
public DynmapChunk(int x, int y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,12 @@ public class DynmapPlayerListener extends PlayerListener {
|
|||||||
} else for (int i=2;i<split.length;i++)
|
} else for (int i=2;i<split.length;i++)
|
||||||
playerList.show(split[i]);
|
playerList.show(split[i]);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
} else if (split[1].equals("fullrender")) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
mgr.renderFullWorld(player.getLocation());
|
||||||
|
} else if (split[1].equals("fullrenderasync")) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
mgr.renderFullWorldAsync(player.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@ package org.dynmap;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
@ -16,20 +16,20 @@ import org.dynmap.debug.Debugger;
|
|||||||
|
|
||||||
public class MapManager extends Thread {
|
public class MapManager extends Thread {
|
||||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
private World world;
|
private World world;
|
||||||
private Debugger debugger;
|
private Debugger debugger;
|
||||||
private MapType[] maps;
|
private MapType[] maps;
|
||||||
public StaleQueue staleQueue;
|
public StaleQueue staleQueue;
|
||||||
public ChatQueue chatQueue;
|
public ChatQueue chatQueue;
|
||||||
public PlayerList playerList;
|
public PlayerList playerList;
|
||||||
|
|
||||||
/* lock for our data structures */
|
/* lock for our data structures */
|
||||||
public static final Object lock = new Object();
|
public static final Object lock = new Object();
|
||||||
|
|
||||||
/* whether the worker thread should be running now */
|
/* whether the worker thread should be running now */
|
||||||
private boolean running = false;
|
private boolean running = false;
|
||||||
|
|
||||||
/* path to image tile directory */
|
/* path to image tile directory */
|
||||||
public File tileDirectory;
|
public File tileDirectory;
|
||||||
|
|
||||||
@ -45,20 +45,23 @@ public class MapManager extends Thread {
|
|||||||
/* time to pause between rendering tiles (ms) */
|
/* time to pause between rendering tiles (ms) */
|
||||||
public int renderWait = 500;
|
public int renderWait = 500;
|
||||||
|
|
||||||
public void debug(String msg)
|
public boolean loadChunks = true;
|
||||||
{
|
|
||||||
|
public void debug(String msg) {
|
||||||
debugger.debug(msg);
|
debugger.debug(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File combinePaths(File parent, String path) { return combinePaths(parent, new File(path)); }
|
private static File combinePaths(File parent, String path) {
|
||||||
|
return combinePaths(parent, new File(path));
|
||||||
|
}
|
||||||
|
|
||||||
private static File combinePaths(File parent, File path) {
|
private static File combinePaths(File parent, File path) {
|
||||||
if (path.isAbsolute()) return path;
|
if(path.isAbsolute())
|
||||||
|
return path;
|
||||||
return new File(parent, path.getPath());
|
return new File(parent, path.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapManager(World world, Debugger debugger, ConfigurationNode configuration)
|
public MapManager(World world, Debugger debugger, ConfigurationNode configuration) {
|
||||||
{
|
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.debugger = debugger;
|
this.debugger = debugger;
|
||||||
this.staleQueue = new StaleQueue();
|
this.staleQueue = new StaleQueue();
|
||||||
@ -66,28 +69,130 @@ public class MapManager extends Thread {
|
|||||||
|
|
||||||
tileDirectory = combinePaths(DynmapPlugin.dataRoot, configuration.getString("tilespath", "web/tiles"));
|
tileDirectory = combinePaths(DynmapPlugin.dataRoot, configuration.getString("tilespath", "web/tiles"));
|
||||||
webDirectory = combinePaths(DynmapPlugin.dataRoot, configuration.getString("webpath", "web"));
|
webDirectory = combinePaths(DynmapPlugin.dataRoot, configuration.getString("webpath", "web"));
|
||||||
renderWait = (int)(configuration.getDouble("renderinterval", 0.5) * 1000);
|
renderWait = (int) (configuration.getDouble("renderinterval", 0.5) * 1000);
|
||||||
|
loadChunks = configuration.getBoolean("loadchunks", true);
|
||||||
|
|
||||||
if (!tileDirectory.isDirectory())
|
if(!tileDirectory.isDirectory())
|
||||||
tileDirectory.mkdirs();
|
tileDirectory.mkdirs();
|
||||||
|
|
||||||
maps = loadMapTypes(configuration);
|
maps = loadMapTypes(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void renderFullWorldAsync(Location l) {
|
||||||
|
fullmapTiles.clear();
|
||||||
|
fullmapTilesRendered.clear();
|
||||||
|
debugger.debug("Full render starting...");
|
||||||
|
for(MapType map : maps) {
|
||||||
|
for(MapTile tile : map.getTiles(l)) {
|
||||||
|
fullmapTiles.add(tile);
|
||||||
|
invalidateTile(tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debugger.debug("Full render finished.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void renderFullWorld(Location l) {
|
||||||
|
debugger.debug("Full render starting...");
|
||||||
|
for(MapType map : maps) {
|
||||||
|
HashSet<MapTile> found = new HashSet<MapTile>();
|
||||||
|
LinkedList<MapTile> renderQueue = new LinkedList<MapTile>();
|
||||||
|
|
||||||
|
for(MapTile tile : map.getTiles(l)) {
|
||||||
|
if(!(found.contains(tile) || map.isRendered(tile))) {
|
||||||
|
found.add(tile);
|
||||||
|
renderQueue.add(tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(!renderQueue.isEmpty()) {
|
||||||
|
MapTile tile = renderQueue.pollFirst();
|
||||||
|
|
||||||
|
loadRequiredChunks(tile);
|
||||||
|
debugger.debug("renderQueue: " + renderQueue.size() + "/" + found.size());
|
||||||
|
if(map.render(tile)) {
|
||||||
|
found.remove(tile);
|
||||||
|
staleQueue.onTileUpdated(tile);
|
||||||
|
for(MapTile adjTile : map.getAdjecentTiles(tile)) {
|
||||||
|
if(!(found.contains(adjTile) || map.isRendered(adjTile))) {
|
||||||
|
found.add(adjTile);
|
||||||
|
renderQueue.add(adjTile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
found.remove(tile);
|
||||||
|
System.gc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debugger.debug("Full render finished.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<MapTile> fullmapTiles = new HashSet<MapTile>();
|
||||||
|
public boolean fullmapRenderStarting = false;
|
||||||
|
public HashSet<MapTile> fullmapTilesRendered = new HashSet<MapTile>();
|
||||||
|
|
||||||
|
void handleFullMapRender(MapTile tile) {
|
||||||
|
if(!fullmapTiles.contains(tile)) {
|
||||||
|
debugger.debug("Non fullmap-render tile: " + tile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fullmapTilesRendered.add(tile);
|
||||||
|
MapType map = tile.getMap();
|
||||||
|
MapTile[] adjecenttiles = map.getAdjecentTiles(tile);
|
||||||
|
for(int i = 0; i < adjecenttiles.length; i++) {
|
||||||
|
MapTile adjecentTile = adjecenttiles[i];
|
||||||
|
if(!fullmapTiles.contains(adjecentTile)) {
|
||||||
|
fullmapTiles.add(adjecentTile);
|
||||||
|
staleQueue.pushStaleTile(adjecentTile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debugger.debug("Queue size: " + staleQueue.size() + "+" + fullmapTilesRendered.size() + "/" + fullmapTiles.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasEnoughMemory() {
|
||||||
|
return Runtime.getRuntime().freeMemory() >= 100 * 1024 * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void waitForMemory() {
|
||||||
|
if(!hasEnoughMemory()) {
|
||||||
|
debugger.debug("Waiting for memory...");
|
||||||
|
// Wait until there is at least 50mb of free memory.
|
||||||
|
do {
|
||||||
|
System.gc();
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch(InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} while(!hasEnoughMemory());
|
||||||
|
debugger.debug(Runtime.getRuntime().freeMemory() / (1024 * 1024) + "MB of memory free, will continue...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadRequiredChunks(MapTile tile) {
|
||||||
|
if(!loadChunks)
|
||||||
|
return;
|
||||||
|
waitForMemory();
|
||||||
|
|
||||||
|
// Actually load the chunks.
|
||||||
|
for(DynmapChunk chunk : tile.getMap().getRequiredChunks(tile)) {
|
||||||
|
if(!world.isChunkLoaded(chunk.x, chunk.y))
|
||||||
|
world.loadChunk(chunk.x, chunk.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private MapType[] loadMapTypes(ConfigurationNode configuration) {
|
private MapType[] loadMapTypes(ConfigurationNode configuration) {
|
||||||
List<?> configuredMaps = (List<?>)configuration.getProperty("maps");
|
List<?> configuredMaps = (List<?>) configuration.getProperty("maps");
|
||||||
ArrayList<MapType> mapTypes = new ArrayList<MapType>();
|
ArrayList<MapType> mapTypes = new ArrayList<MapType>();
|
||||||
for(Object configuredMapObj : configuredMaps) {
|
for(Object configuredMapObj : configuredMaps) {
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> configuredMap = (Map<String, Object>)configuredMapObj;
|
Map<String, Object> configuredMap = (Map<String, Object>) configuredMapObj;
|
||||||
String typeName = (String)configuredMap.get("class");
|
String typeName = (String) configuredMap.get("class");
|
||||||
log.info("Loading map '" + typeName.toString() + "'...");
|
log.info("Loading map '" + typeName.toString() + "'...");
|
||||||
Class<?> mapTypeClass = Class.forName(typeName);
|
Class<?> mapTypeClass = Class.forName(typeName);
|
||||||
Constructor<?> constructor = mapTypeClass.getConstructor(MapManager.class, World.class, Debugger.class, Map.class);
|
Constructor<?> constructor = mapTypeClass.getConstructor(MapManager.class, World.class, Debugger.class, Map.class);
|
||||||
MapType mapType = (MapType)constructor.newInstance(this, world, debugger, configuredMap);
|
MapType mapType = (MapType) constructor.newInstance(this, world, debugger, configuredMap);
|
||||||
mapTypes.add(mapType);
|
mapTypes.add(mapType);
|
||||||
} catch (Exception e) {
|
} catch(Exception e) {
|
||||||
debugger.error("Error loading map", e);
|
debugger.error("Error loading map", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,30 +202,28 @@ public class MapManager extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* initialize and start map manager */
|
/* initialize and start map manager */
|
||||||
public void startManager()
|
public void startManager() {
|
||||||
{
|
|
||||||
synchronized(lock) {
|
synchronized(lock) {
|
||||||
running = true;
|
running = true;
|
||||||
this.start();
|
this.start();
|
||||||
try {
|
try {
|
||||||
this.setPriority(MIN_PRIORITY);
|
this.setPriority(MIN_PRIORITY);
|
||||||
log.info("Set minimum priority for worker thread");
|
log.info("Set minimum priority for worker thread");
|
||||||
} catch(SecurityException e) {
|
} catch(SecurityException e) {
|
||||||
log.info("Failed to set minimum priority for worker thread!");
|
log.info("Failed to set minimum priority for worker thread!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stop map manager */
|
/* stop map manager */
|
||||||
public void stopManager()
|
public void stopManager() {
|
||||||
{
|
|
||||||
synchronized(lock) {
|
synchronized(lock) {
|
||||||
if(!running)
|
if(!running)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
log.info("Stopping map renderer...");
|
log.info("Stopping map renderer...");
|
||||||
running = false;
|
running = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.join();
|
this.join();
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
@ -128,31 +231,24 @@ public class MapManager extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the worker/renderer thread */
|
/* the worker/renderer thread */
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
log.info("Map renderer has started.");
|
log.info("Map renderer has started.");
|
||||||
|
|
||||||
while(running) {
|
while(running) {
|
||||||
MapTile t = staleQueue.popStaleTile();
|
MapTile t = staleQueue.popStaleTile();
|
||||||
if(t != null) {
|
if(t != null) {
|
||||||
MapType map = t.getMap();
|
loadRequiredChunks(t);
|
||||||
World world = map.getWorld();
|
|
||||||
|
|
||||||
Chunk[] requiredChunks = map.getRequiredChunks(t);
|
|
||||||
debugger.debug("Loading " + requiredChunks.length + " chunks for tile " + t + "...");
|
|
||||||
for (int i=0;i<requiredChunks.length;i++) {
|
|
||||||
Chunk requiredChunk = requiredChunks[i];
|
|
||||||
if (!world.isChunkLoaded(requiredChunk))
|
|
||||||
world.loadChunk(requiredChunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
debugger.debug("Rendering tile " + t + "...");
|
debugger.debug("Rendering tile " + t + "...");
|
||||||
t.getMap().render(t);
|
boolean isNonEmptyTile = t.getMap().render(t);
|
||||||
staleQueue.onTileUpdated(t);
|
staleQueue.onTileUpdated(t);
|
||||||
|
|
||||||
|
if(isNonEmptyTile)
|
||||||
|
handleFullMapRender(t);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(renderWait);
|
Thread.sleep(renderWait);
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
@ -164,17 +260,18 @@ public class MapManager extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Map renderer has stopped.");
|
log.info("Map renderer has stopped.");
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
debugger.error("Exception on rendering-thread: " + ex.toString());
|
debugger.error("Exception on rendering-thread: " + ex.toString());
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void touch(int x, int y, int z) {
|
public void touch(int x, int y, int z) {
|
||||||
for (int i = 0; i < maps.length; i++) {
|
for(int i = 0; i < maps.length; i++) {
|
||||||
MapTile[] tiles = maps[i].getTiles(new Location(world, x, y, z));
|
MapTile[] tiles = maps[i].getTiles(new Location(world, x, y, z));
|
||||||
for(int j=0;j<tiles.length;j++) {
|
for(int j = 0; j < tiles.length; j++) {
|
||||||
invalidateTile(tiles[j]);
|
invalidateTile(tiles[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,8 +282,7 @@ public class MapManager extends Thread {
|
|||||||
staleQueue.pushStaleTile(tile);
|
staleQueue.pushStaleTile(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addChatEvent(PlayerChatEvent event)
|
public void addChatEvent(PlayerChatEvent event) {
|
||||||
{
|
|
||||||
chatQueue.pushChatMessage(event);
|
chatQueue.pushChatMessage(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package org.dynmap;
|
package org.dynmap;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.dynmap.debug.Debugger;
|
import org.dynmap.debug.Debugger;
|
||||||
@ -29,7 +28,7 @@ public abstract class MapType {
|
|||||||
|
|
||||||
public abstract MapTile[] getTiles(Location l);
|
public abstract MapTile[] getTiles(Location l);
|
||||||
public abstract MapTile[] getAdjecentTiles(MapTile tile);
|
public abstract MapTile[] getAdjecentTiles(MapTile tile);
|
||||||
public abstract Chunk[] getRequiredChunks(MapTile tile);
|
public abstract DynmapChunk[] getRequiredChunks(MapTile tile);
|
||||||
public abstract boolean render(MapTile tile);
|
public abstract boolean render(MapTile tile);
|
||||||
public abstract boolean isRendered(MapTile tile);
|
public abstract boolean isRendered(MapTile tile);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,10 @@ public class StaleQueue {
|
|||||||
tileUpdates = new LinkedList<TileUpdate>();
|
tileUpdates = new LinkedList<TileUpdate>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return staleTilesQueue.size();
|
||||||
|
}
|
||||||
|
|
||||||
/* put a MapTile that needs to be regenerated on the list of stale tiles */
|
/* put a MapTile that needs to be regenerated on the list of stale tiles */
|
||||||
public boolean pushStaleTile(MapTile m)
|
public boolean pushStaleTile(MapTile m)
|
||||||
{
|
{
|
||||||
|
@ -68,13 +68,13 @@ public class BukkitPlayerDebugger implements Debugger {
|
|||||||
|
|
||||||
public synchronized void error(String message) {
|
public synchronized void error(String message) {
|
||||||
sendToDebuggees(prepend + ChatColor.RED + message);
|
sendToDebuggees(prepend + ChatColor.RED + message);
|
||||||
if (isLogging) log.log(Level.SEVERE, prepend + message);
|
log.log(Level.SEVERE, prepend + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void error(String message, Throwable thrown) {
|
public synchronized void error(String message, Throwable thrown) {
|
||||||
sendToDebuggees(prepend + ChatColor.RED + message);
|
sendToDebuggees(prepend + ChatColor.RED + message);
|
||||||
sendToDebuggees(thrown.toString());
|
sendToDebuggees(thrown.toString());
|
||||||
if (isLogging) log.log(Level.SEVERE, prepend + message);
|
log.log(Level.SEVERE, prepend + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class CommandListener extends PlayerListener {
|
protected class CommandListener extends PlayerListener {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.dynmap.debug;
|
package org.dynmap.debug;
|
||||||
|
|
||||||
public class NullDebugger implements Debugger {
|
public class NullDebugger implements Debugger {
|
||||||
|
public static final NullDebugger instance = new NullDebugger();
|
||||||
public void debug(String message) {
|
public void debug(String message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,9 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.dynmap.DynmapChunk;
|
||||||
import org.dynmap.MapManager;
|
import org.dynmap.MapManager;
|
||||||
import org.dynmap.MapTile;
|
import org.dynmap.MapTile;
|
||||||
import org.dynmap.MapType;
|
import org.dynmap.MapType;
|
||||||
@ -52,17 +51,17 @@ public class KzedMap extends MapType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private MapTileRenderer[] loadRenderers(Map<String, Object> configuration) {
|
private MapTileRenderer[] loadRenderers(Map<String, Object> configuration) {
|
||||||
List<?> configuredRenderers = (List<?>)configuration.get("renderers");
|
List<?> configuredRenderers = (List<?>) configuration.get("renderers");
|
||||||
ArrayList<MapTileRenderer> renderers = new ArrayList<MapTileRenderer>();
|
ArrayList<MapTileRenderer> renderers = new ArrayList<MapTileRenderer>();
|
||||||
for(Object configuredRendererObj : configuredRenderers) {
|
for (Object configuredRendererObj : configuredRenderers) {
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> configuredRenderer = (Map<String, Object>)configuredRendererObj;
|
Map<String, Object> configuredRenderer = (Map<String, Object>) configuredRendererObj;
|
||||||
String typeName = (String)configuredRenderer.get("class");
|
String typeName = (String) configuredRenderer.get("class");
|
||||||
log.info("Loading renderer '" + typeName.toString() + "'...");
|
log.info("Loading renderer '" + typeName.toString() + "'...");
|
||||||
Class<?> mapTypeClass = Class.forName(typeName);
|
Class<?> mapTypeClass = Class.forName(typeName);
|
||||||
Constructor<?> constructor = mapTypeClass.getConstructor(Debugger.class, Map.class);
|
Constructor<?> constructor = mapTypeClass.getConstructor(Debugger.class, Map.class);
|
||||||
MapTileRenderer mapTileRenderer = (MapTileRenderer)constructor.newInstance(getDebugger(), configuredRenderer);
|
MapTileRenderer mapTileRenderer = (MapTileRenderer) constructor.newInstance(getDebugger(), configuredRenderer);
|
||||||
renderers.add(mapTileRenderer);
|
renderers.add(mapTileRenderer);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
getDebugger().error("Error loading renderer", e);
|
getDebugger().error("Error loading renderer", e);
|
||||||
@ -84,28 +83,28 @@ public class KzedMap extends MapType {
|
|||||||
int dz = z - anchorz;
|
int dz = z - anchorz;
|
||||||
int px = dx + dz;
|
int px = dx + dz;
|
||||||
int py = dx - dz - dy;
|
int py = dx - dz - dy;
|
||||||
|
|
||||||
int tx = tilex(px);
|
int tx = tilex(px);
|
||||||
int ty = tiley(py);
|
int ty = tiley(py);
|
||||||
|
|
||||||
ArrayList<MapTile> tiles = new ArrayList<MapTile>();
|
ArrayList<MapTile> tiles = new ArrayList<MapTile>();
|
||||||
|
|
||||||
addTile(tiles, tx, ty);
|
addTile(tiles, tx, ty);
|
||||||
|
|
||||||
boolean ledge = tilex(px - 4) != tx;
|
boolean ledge = tilex(px - 4) != tx;
|
||||||
boolean tedge = tiley(py - 4) != ty;
|
boolean tedge = tiley(py - 4) != ty;
|
||||||
boolean redge = tilex(px + 4) != tx;
|
boolean redge = tilex(px + 4) != tx;
|
||||||
boolean bedge = tiley(py + 4) != ty;
|
boolean bedge = tiley(py + 4) != ty;
|
||||||
|
|
||||||
if(ledge) addTile(tiles, tx - tileWidth, ty);
|
if (ledge) addTile(tiles, tx - tileWidth, ty);
|
||||||
if(redge) addTile(tiles, tx + tileWidth, ty);
|
if (redge) addTile(tiles, tx + tileWidth, ty);
|
||||||
if(tedge) addTile(tiles, tx, ty - tileHeight);
|
if (tedge) addTile(tiles, tx, ty - tileHeight);
|
||||||
if(bedge) addTile(tiles, tx, ty + tileHeight);
|
if (bedge) addTile(tiles, tx, ty + tileHeight);
|
||||||
|
|
||||||
if(ledge && tedge) addTile(tiles, tx - tileWidth, ty - tileHeight);
|
if (ledge && tedge) addTile(tiles, tx - tileWidth, ty - tileHeight);
|
||||||
if(ledge && bedge) addTile(tiles, tx - tileWidth, ty + tileHeight);
|
if (ledge && bedge) addTile(tiles, tx - tileWidth, ty + tileHeight);
|
||||||
if(redge && tedge) addTile(tiles, tx + tileWidth, ty - tileHeight);
|
if (redge && tedge) addTile(tiles, tx + tileWidth, ty - tileHeight);
|
||||||
if(redge && bedge) addTile(tiles, tx + tileWidth, ty + tileHeight);
|
if (redge && bedge) addTile(tiles, tx + tileWidth, ty + tileHeight);
|
||||||
|
|
||||||
MapTile[] result = new MapTile[tiles.size()];
|
MapTile[] result = new MapTile[tiles.size()];
|
||||||
tiles.toArray(result);
|
tiles.toArray(result);
|
||||||
@ -115,20 +114,20 @@ public class KzedMap extends MapType {
|
|||||||
@Override
|
@Override
|
||||||
public MapTile[] getAdjecentTiles(MapTile tile) {
|
public MapTile[] getAdjecentTiles(MapTile tile) {
|
||||||
if (tile instanceof KzedMapTile) {
|
if (tile instanceof KzedMapTile) {
|
||||||
KzedMapTile t = (KzedMapTile)tile;
|
KzedMapTile t = (KzedMapTile) tile;
|
||||||
MapTileRenderer renderer = t.renderer;
|
MapTileRenderer renderer = t.renderer;
|
||||||
return new MapTile[] {
|
return new MapTile[] {
|
||||||
new KzedMapTile(this, renderer, t.px-tileWidth, t.py),
|
new KzedMapTile(this, renderer, t.px - tileWidth, t.py),
|
||||||
new KzedMapTile(this, renderer, t.px+tileWidth, t.py),
|
new KzedMapTile(this, renderer, t.px + tileWidth, t.py),
|
||||||
new KzedMapTile(this, renderer, t.px, t.py-tileHeight),
|
new KzedMapTile(this, renderer, t.px, t.py - tileHeight),
|
||||||
new KzedMapTile(this, renderer, t.px, t.py+tileHeight)
|
new KzedMapTile(this, renderer, t.px, t.py + tileHeight)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return new MapTile[0];
|
return new MapTile[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTile(ArrayList<MapTile> tiles, int px, int py) {
|
public void addTile(ArrayList<MapTile> tiles, int px, int py) {
|
||||||
for (int i=0;i<renderers.length;i++) {
|
for (int i = 0; i < renderers.length; i++) {
|
||||||
tiles.add(new KzedMapTile(this, renderers[i], px, py));
|
tiles.add(new KzedMapTile(this, renderers[i], px, py));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,40 +137,39 @@ public class KzedMap extends MapType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Chunk[] getRequiredChunks(MapTile tile) {
|
public DynmapChunk[] getRequiredChunks(MapTile tile) {
|
||||||
if (tile instanceof KzedMapTile) {
|
if (tile instanceof KzedMapTile) {
|
||||||
KzedMapTile t = (KzedMapTile)tile;
|
KzedMapTile t = (KzedMapTile) tile;
|
||||||
int x1 = t.mx - KzedMap.tileHeight / 2;
|
int x1 = t.mx - KzedMap.tileHeight / 2;
|
||||||
int x2 = t.mx + KzedMap.tileWidth / 2 + KzedMap.tileHeight / 2;
|
int x2 = t.mx + KzedMap.tileWidth / 2 + KzedMap.tileHeight / 2;
|
||||||
|
|
||||||
int z1 = t.mz - KzedMap.tileHeight / 2;
|
int z1 = t.mz - KzedMap.tileHeight / 2;
|
||||||
int z2 = t.mz + KzedMap.tileWidth / 2 + KzedMap.tileHeight / 2;
|
int z2 = t.mz + KzedMap.tileWidth / 2 + KzedMap.tileHeight / 2;
|
||||||
|
|
||||||
int x, z;
|
int x, z;
|
||||||
|
|
||||||
ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
ArrayList<DynmapChunk> chunks = new ArrayList<DynmapChunk>();
|
||||||
World world = getWorld();
|
for (x = x1; x < x2; x += 16) {
|
||||||
for(x=x1; x<x2; x+=16) {
|
for (z = z1; z < z2; z += 16) {
|
||||||
for(z=z1; z<z2; z+=16) {
|
DynmapChunk chunk = new DynmapChunk(x / 16, z / 16);
|
||||||
Chunk chunk = world.getChunkAt(x/16, z/16);
|
|
||||||
chunks.add(chunk);
|
chunks.add(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Chunk[] result = new Chunk[chunks.size()];
|
DynmapChunk[] result = new DynmapChunk[chunks.size()];
|
||||||
chunks.toArray(result);
|
chunks.toArray(result);
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
return new Chunk[0];
|
return new DynmapChunk[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean render(MapTile tile) {
|
public boolean render(MapTile tile) {
|
||||||
if (tile instanceof KzedZoomedMapTile) {
|
if (tile instanceof KzedZoomedMapTile) {
|
||||||
zoomrenderer.render((KzedZoomedMapTile)tile, getMapManager().tileDirectory.getAbsolutePath());
|
zoomrenderer.render((KzedZoomedMapTile) tile, getMapManager().tileDirectory.getAbsolutePath());
|
||||||
return true;
|
return true;
|
||||||
} else if (tile instanceof KzedMapTile) {
|
} else if (tile instanceof KzedMapTile) {
|
||||||
return ((KzedMapTile)tile).renderer.render((KzedMapTile)tile, getMapManager().tileDirectory.getAbsolutePath());
|
return ((KzedMapTile) tile).renderer.render((KzedMapTile) tile, getMapManager().tileDirectory.getAbsolutePath());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -179,45 +177,41 @@ public class KzedMap extends MapType {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isRendered(MapTile tile) {
|
public boolean isRendered(MapTile tile) {
|
||||||
if (tile instanceof KzedMapTile) {
|
if (tile instanceof KzedMapTile) {
|
||||||
File tileFile = new File(DefaultTileRenderer.getPath((KzedMapTile)tile, getMapManager().tileDirectory.getAbsolutePath()));
|
File tileFile = new File(DefaultTileRenderer.getPath((KzedMapTile) tile, getMapManager().tileDirectory.getAbsolutePath()));
|
||||||
return tileFile.exists();
|
return tileFile.exists();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tile X for position x */
|
/* tile X for position x */
|
||||||
static int tilex(int x)
|
static int tilex(int x) {
|
||||||
{
|
if (x < 0)
|
||||||
if(x < 0)
|
|
||||||
return x - (tileWidth + (x % tileWidth));
|
return x - (tileWidth + (x % tileWidth));
|
||||||
else
|
else
|
||||||
return x - (x % tileWidth);
|
return x - (x % tileWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tile Y for position y */
|
/* tile Y for position y */
|
||||||
static int tiley(int y)
|
static int tiley(int y) {
|
||||||
{
|
if (y < 0)
|
||||||
if(y < 0)
|
|
||||||
return y - (tileHeight + (y % tileHeight));
|
return y - (tileHeight + (y % tileHeight));
|
||||||
else
|
else
|
||||||
return y - (y % tileHeight);
|
return y - (y % tileHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* zoomed-out tile X for tile position x */
|
/* zoomed-out tile X for tile position x */
|
||||||
static int ztilex(int x)
|
static int ztilex(int x) {
|
||||||
{
|
if (x < 0)
|
||||||
if(x < 0)
|
|
||||||
return x + x % zTileWidth;
|
return x + x % zTileWidth;
|
||||||
else
|
else
|
||||||
return x - (x % zTileWidth);
|
return x - (x % zTileWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* zoomed-out tile Y for tile position y */
|
/* zoomed-out tile Y for tile position y */
|
||||||
static int ztiley(int y)
|
static int ztiley(int y) {
|
||||||
{
|
if (y < 0)
|
||||||
if(y < 0)
|
|
||||||
return y + y % zTileHeight;
|
return y + y % zTileHeight;
|
||||||
//return y - (zTileHeight + (y % zTileHeight));
|
//return y - (zTileHeight + (y % zTileHeight));
|
||||||
else
|
else
|
||||||
return y - (y % zTileHeight);
|
return y - (y % zTileHeight);
|
||||||
}
|
}
|
||||||
@ -404,12 +398,12 @@ public class KzedMap extends MapType {
|
|||||||
return good;
|
return good;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public java.util.Map<Integer, Color[]> loadColorSet(String colorsetpath) {
|
public java.util.Map<Integer, Color[]> loadColorSet(String colorsetpath) {
|
||||||
java.util.Map<Integer, Color[]> colors = new HashMap<Integer, Color[]>();
|
java.util.Map<Integer, Color[]> colors = new HashMap<Integer, Color[]>();
|
||||||
|
|
||||||
InputStream stream;
|
InputStream stream;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/* load colorset */
|
/* load colorset */
|
||||||
File cfile = new File(colorsetpath);
|
File cfile = new File(colorsetpath);
|
||||||
@ -423,32 +417,32 @@ public class KzedMap extends MapType {
|
|||||||
|
|
||||||
Scanner scanner = new Scanner(stream);
|
Scanner scanner = new Scanner(stream);
|
||||||
int nc = 0;
|
int nc = 0;
|
||||||
while(scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String line = scanner.nextLine();
|
String line = scanner.nextLine();
|
||||||
if (line.startsWith("#") || line.equals("")) {
|
if (line.startsWith("#") || line.equals("")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] split = line.split("\t");
|
String[] split = line.split("\t");
|
||||||
if (split.length < 17) {
|
if (split.length < 17) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer id = new Integer(split[0]);
|
Integer id = new Integer(split[0]);
|
||||||
|
|
||||||
Color[] c = new Color[4];
|
Color[] c = new Color[4];
|
||||||
|
|
||||||
/* store colors by raycast sequence number */
|
/* store colors by raycast sequence number */
|
||||||
c[0] = new Color(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]), Integer.parseInt(split[4]));
|
c[0] = new Color(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]), Integer.parseInt(split[4]));
|
||||||
c[3] = new Color(Integer.parseInt(split[5]), Integer.parseInt(split[6]), Integer.parseInt(split[7]), Integer.parseInt(split[8]));
|
c[3] = new Color(Integer.parseInt(split[5]), Integer.parseInt(split[6]), Integer.parseInt(split[7]), Integer.parseInt(split[8]));
|
||||||
c[1] = new Color(Integer.parseInt(split[9]), Integer.parseInt(split[10]), Integer.parseInt(split[11]), Integer.parseInt(split[12]));
|
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]));
|
c[2] = new Color(Integer.parseInt(split[13]), Integer.parseInt(split[14]), Integer.parseInt(split[15]), Integer.parseInt(split[16]));
|
||||||
|
|
||||||
colors.put(id, c);
|
colors.put(id, c);
|
||||||
nc += 1;
|
nc += 1;
|
||||||
}
|
}
|
||||||
scanner.close();
|
scanner.close();
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
getDebugger().error("Could not load colors", e);
|
getDebugger().error("Could not load colors", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user