Add alternate directory structure to better support huge worlds

This commit is contained in:
Mike Primm 2011-06-13 21:43:02 -05:00
parent b19d8f8745
commit 0cf7b4be9b
16 changed files with 118 additions and 51 deletions

View File

@ -121,6 +121,8 @@ templates:
# Template for normal world
normal:
enabled: true
# If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true
center:
x: 0
y: 64
@ -184,6 +186,8 @@ templates:
# Nether world template
nether:
enabled: true
# If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true
center:
x: 0
y: 64
@ -209,6 +213,8 @@ templates:
# Skylands world template
skylands:
enabled: true
# If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true
center:
x: 0
y: 64
@ -267,6 +273,8 @@ worlds:
# x: 0
# y: 64
# z: 0
# # If bigworld set to true, use alternate directory layout better suited to large worlds
# # bigworld: true
# maps:
# - class: org.dynmap.flat.FlatMap
# name: flat

View File

@ -1,7 +1,6 @@
package org.dynmap;
import static org.dynmap.JSONUtils.a;
import static org.dynmap.JSONUtils.l;
import static org.dynmap.JSONUtils.s;
import org.dynmap.Event.Listener;
@ -33,6 +32,7 @@ public class ClientConfigurationComponent extends Component {
s(wo, "center/x", wn.getFloat("center/x", 0.0f));
s(wo, "center/y", wn.getFloat("center/y", 64.0f));
s(wo, "center/z", wn.getFloat("center/z", 0.0f));
s(wo, "bigworld", world.bigworld);
a(t, "worlds", wo);
for(MapType mt : world.maps) {

View File

@ -15,4 +15,5 @@ public class DynmapWorld {
public int servertime;
public boolean sendposition;
public boolean sendhealth;
public boolean bigworld; /* If true, deeper directory hierarchy */
}

View File

@ -3,7 +3,6 @@ package org.dynmap;
import org.dynmap.Event.Listener;
import org.dynmap.web.handlers.ClientUpdateHandler;
import org.dynmap.web.handlers.SendMessageHandler;
import org.dynmap.web.handlers.SendMessageHandler.Message;
import org.json.simple.JSONObject;
import static org.dynmap.JSONUtils.*;

View File

@ -3,7 +3,6 @@ package org.dynmap;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.Reader;
@ -13,9 +12,7 @@ import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.dynmap.web.Json;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

View File

@ -2,7 +2,6 @@ package org.dynmap;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.util.LinkedList;
import org.bukkit.World;
import org.bukkit.Chunk;
import org.bukkit.entity.Entity;
@ -11,7 +10,6 @@ import org.bukkit.entity.Entity;
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
*/
public class MapChunkCache {
private World w;
private static Method getchunkdata = null;
private static Method gethandle = null;
private static Method poppreservedchunk = null;
@ -164,7 +162,6 @@ public class MapChunkCache {
}
x_dim = x_max - x_min + 1;
}
this.w = w;
if(!initialized) {
try {

View File

@ -297,6 +297,7 @@ public class MapManager {
dynmapWorld.servertime = (int)(w.getTime() % 24000);
dynmapWorld.sendposition = worldConfiguration.getBoolean("sendposition", true);
dynmapWorld.sendhealth = worldConfiguration.getBoolean("sendhealth", true);
dynmapWorld.bigworld = worldConfiguration.getBoolean("bigworld", false);
if(loclist != null) {
for(ConfigurationNode loc : loclist) {
Location lx = new Location(w, loc.getDouble("x", 0), loc.getDouble("y", 64), loc.getDouble("z", 0));

View File

@ -3,10 +3,14 @@ package org.dynmap;
import org.bukkit.World;
public abstract class MapTile {
private World world;
protected DynmapWorld world;
private MapType map;
public World getWorld() {
return world.world;
}
public DynmapWorld getDynmapWorld() {
return world;
}
@ -18,7 +22,7 @@ public abstract class MapTile {
public abstract String getDayFilename();
public MapTile(World world, MapType map) {
public MapTile(DynmapWorld world, MapType map) {
this.world = world;
this.map = map;
}
@ -38,6 +42,6 @@ public abstract class MapTile {
}
public String getKey() {
return world.getName() + "." + map.getName();
return world.world.getName() + "." + map.getName();
}
}

View File

@ -1,5 +1,6 @@
package org.dynmap.flat;
import org.dynmap.DynmapWorld;
import static org.dynmap.JSONUtils.a;
import static org.dynmap.JSONUtils.s;
import java.awt.image.DataBufferInt;
@ -75,13 +76,14 @@ public class FlatMap extends MapType {
@Override
public MapTile[] getTiles(Location l) {
return new MapTile[] { new FlatMapTile(l.getWorld(), this, (int) Math.floor(l.getBlockX() / 128.0), (int) Math.floor(l.getBlockZ() / 128.0), 128) };
DynmapWorld w = MapManager.mapman.getWorld(l.getWorld().getName());
return new MapTile[] { new FlatMapTile(w, this, (int) Math.floor(l.getBlockX() / 128.0), (int) Math.floor(l.getBlockZ() / 128.0), 128) };
}
@Override
public MapTile[] getAdjecentTiles(MapTile tile) {
FlatMapTile t = (FlatMapTile) tile;
World w = t.getWorld();
DynmapWorld w = t.getDynmapWorld();
int x = t.x;
int y = t.y;
int s = t.size;
@ -257,6 +259,8 @@ public class FlatMap extends MapType {
if((!outputFile.exists()) || (crc != hashman.getImageHashCode(tile.getKey(), null, t.x, t.y))) {
/* Wrap buffer as buffered image */
Debug.debug("saving image " + outputFile.getPath());
if(!outputFile.getParentFile().exists())
outputFile.getParentFile().mkdirs();
try {
ImageIO.write(im.buf_img, "png", outputFile);
} catch (IOException e) {
@ -282,6 +286,8 @@ public class FlatMap extends MapType {
crc = hashman.calculateTileHash(argb_buf_day);
if((!dayfile.exists()) || (crc != hashman.getImageHashCode(tile.getKey(), "day", t.x, t.y))) {
Debug.debug("saving image " + dayfile.getPath());
if(!dayfile.getParentFile().exists())
dayfile.getParentFile().mkdirs();
try {
ImageIO.write(im_day.buf_img, "png", dayfile);
} catch (IOException e) {
@ -387,8 +393,10 @@ public class FlatMap extends MapType {
public int x;
public int y;
public int size;
private String fname;
private String fname_day;
public FlatMapTile(World world, FlatMap map, int x, int y, int size) {
public FlatMapTile(DynmapWorld world, FlatMap map, int x, int y, int size) {
super(world, map);
this.map = map;
this.x = x;
@ -398,11 +406,23 @@ public class FlatMap extends MapType {
@Override
public String getFilename() {
return map.prefix + "_" + size + "_" + -(y+1) + "_" + x + ".png";
if(fname == null) {
if(world.bigworld)
fname = map.prefix + "/" + ((-(y+1))>>5) + "_" + (x>>5) + "/" + size + "_" + -(y+1) + "_" + x + ".png";
else
fname = map.prefix + "_" + size + "_" + -(y+1) + "_" + x + ".png";
}
return fname;
}
@Override
public String getDayFilename() {
return map.prefix + "_day_" + size + "_" + -(y+1) + "_" + x + ".png";
if(fname_day == null) {
if(world.bigworld)
fname_day = map.prefix + "_day/" + ((-(y+1))>>5) + "_" + (x>>5) + "/" + size + "_" + -(y+1) + "_" + x + ".png";
else
fname_day = map.prefix + "_day_" + size + "_" + -(y+1) + "_" + x + ".png";
}
return fname_day;
}
public String toString() {
return getWorld().getName() + ":" + getFilename();

View File

@ -188,7 +188,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
}
/* Hand encoding and writing file off to MapManager */
KzedZoomedMapTile zmtile = new KzedZoomedMapTile(tile.getWorld(),
KzedZoomedMapTile zmtile = new KzedZoomedMapTile(tile.getDynmapWorld(),
(KzedMap) tile.getMap(), tile);
File zoomFile = MapManager.mapman.getTileFile(zmtile);
@ -239,6 +239,8 @@ public class DefaultTileRenderer implements MapTileRenderer {
int ty = mtile.py/KzedMap.tileHeight;
if((!fname.exists()) || (crc != hashman.getImageHashCode(mtile.getKey(), null, tx, ty))) {
Debug.debug("saving image " + fname.getPath());
if(!fname.getParentFile().exists())
fname.getParentFile().mkdirs();
try {
ImageIO.write(img.buf_img, "png", fname);
} catch (IOException e) {
@ -263,6 +265,8 @@ public class DefaultTileRenderer implements MapTileRenderer {
crc = hashman.calculateTileHash(img.argb_buf);
if((!dfname.exists()) || (crc != hashman.getImageHashCode(mtile.getKey(), "day", tx, ty))) {
Debug.debug("saving image " + dfname.getPath());
if(!dfname.getParentFile().exists())
dfname.getParentFile().mkdirs();
try {
ImageIO.write(img_day.buf_img, "png", dfname);
} catch (IOException e) {
@ -334,6 +338,8 @@ public class DefaultTileRenderer implements MapTileRenderer {
zIm.setRGB(ox, oy, KzedMap.tileWidth/2, KzedMap.tileHeight/2, zimg.argb_buf, 0, KzedMap.tileWidth/2);
/* save zoom-out tile */
if(!zoomFile.getParentFile().exists())
zoomFile.getParentFile().mkdirs();
try {
ImageIO.write(zIm, "png", zoomFile);

View File

@ -1,5 +1,6 @@
package org.dynmap.kzedmap;
import org.dynmap.DynmapWorld;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
@ -14,6 +15,7 @@ import org.bukkit.World;
import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapChunk;
import org.dynmap.Log;
import org.dynmap.MapManager;
import org.dynmap.MapTile;
import org.dynmap.MapType;
import org.dynmap.MapChunkCache;
@ -45,7 +47,6 @@ public class KzedMap extends MapType {
public static final int anchorz = 0;
MapTileRenderer[] renderers;
ZoomedTileRenderer zoomrenderer;
/* BufferedImage with direct access to its ARGB-formatted data buffer */
public static class KzedBufferedImage {
@ -67,13 +68,11 @@ public class KzedMap extends MapType {
this.renderers = new MapTileRenderer[renderers.size()];
renderers.toArray(this.renderers);
Log.info("Loaded " + renderers.size() + " renderers for map '" + getClass().toString() + "'.");
zoomrenderer = new ZoomedTileRenderer(configuration);
}
@Override
public MapTile[] getTiles(Location l) {
World world = l.getWorld();
DynmapWorld world = MapManager.mapman.getWorld(l.getWorld().getName());
int x = l.getBlockX();
int y = l.getBlockY();
@ -124,7 +123,7 @@ public class KzedMap extends MapType {
public MapTile[] getAdjecentTiles(MapTile tile) {
if (tile instanceof KzedMapTile) {
KzedMapTile t = (KzedMapTile) tile;
World world = tile.getWorld();
DynmapWorld world = tile.getDynmapWorld();
MapTileRenderer renderer = t.renderer;
return new MapTile[] {
new KzedMapTile(world, this, renderer, t.px - tileWidth, t.py),
@ -135,7 +134,7 @@ public class KzedMap extends MapType {
return new MapTile[0];
}
public void addTile(ArrayList<MapTile> tiles, World world, int px, int py) {
public void addTile(ArrayList<MapTile> tiles, DynmapWorld world, int px, int py) {
for (int i = 0; i < renderers.length; i++) {
tiles.add(new KzedMapTile(world, this, renderers[i], px, py));
}
@ -229,10 +228,7 @@ public class KzedMap extends MapType {
@Override
public boolean render(MapChunkCache cache, MapTile tile, File outputFile) {
if (tile instanceof KzedZoomedMapTile) {
zoomrenderer.render(cache, (KzedZoomedMapTile) tile, outputFile);
return true;
} else if (tile instanceof KzedMapTile) {
if (tile instanceof KzedMapTile) {
return ((KzedMapTile) tile).renderer.render(cache, (KzedMapTile) tile, outputFile);
}
return false;

View File

@ -1,5 +1,6 @@
package org.dynmap.kzedmap;
import org.dynmap.DynmapWorld;
import java.io.File;
import org.bukkit.World;
@ -9,11 +10,13 @@ public class KzedMapTile extends MapTile {
public KzedMap map;
public MapTileRenderer renderer;
public int px, py;
private String fname;
private String fname_day;
// Hack.
public File file = null;
public KzedMapTile(World world, KzedMap map, MapTileRenderer renderer, int px, int py) {
public KzedMapTile(DynmapWorld world, KzedMap map, MapTileRenderer renderer, int px, int py) {
super(world, map);
this.map = map;
this.renderer = renderer;
@ -23,12 +26,24 @@ public class KzedMapTile extends MapTile {
@Override
public String getFilename() {
return renderer.getName() + "_" + px + "_" + py + ".png";
if(fname == null) {
if(world.bigworld)
fname = renderer.getName() + "/" + (px >> 12) + '_' + (py >> 12) + '/' + px + "_" + py + ".png";
else
fname = renderer.getName() + "_" + px + "_" + py + ".png";
}
return fname;
}
@Override
public String getDayFilename() {
return renderer.getName() + "_day_" + px + "_" + py + ".png";
if(fname_day == null) {
if(world.bigworld)
fname_day = renderer.getName() + "_day/" + (px >> 12) + '_' + (py >> 12) + '/' + px + "_" + py + ".png";
else
fname_day = renderer.getName() + "_day_" + px + "_" + py + ".png";
}
return fname_day;
}
@Override

View File

@ -1,22 +1,40 @@
package org.dynmap.kzedmap;
import org.dynmap.DynmapWorld;
import org.bukkit.World;
import org.dynmap.MapTile;
public class KzedZoomedMapTile extends MapTile {
private String fname;
private String fname_day;
@Override
public String getFilename() {
return "z" + originalTile.renderer.getName() + "_" + getTileX() + "_" + getTileY() + ".png";
if(fname == null) {
if(world.bigworld)
fname = "z" + originalTile.renderer.getName() + "/" + (getTileX()>>12) + '_' +
(getTileY() >> 12) + '/' + getTileX() + "_" + getTileY() + ".png";
else
fname = "z" + originalTile.renderer.getName() + "_" + getTileX() + "_" + getTileY() + ".png";
}
return fname;
}
@Override
public String getDayFilename() {
return "z" + originalTile.renderer.getName() + "_day_" + getTileX() + "_" + getTileY() + ".png";
if(fname_day == null) {
if(world.bigworld)
fname_day = "z" + originalTile.renderer.getName() + "_day/" + (getTileX()>>12) + '_' +
(getTileY() >> 12) + '/' + getTileX() + "_" + getTileY() + ".png";
else
fname_day = "z" + originalTile.renderer.getName() + "_day_" + getTileX() + "_" + getTileY() + ".png";
}
return fname_day;
}
public KzedMapTile originalTile;
public KzedZoomedMapTile(World world, KzedMap map, KzedMapTile original) {
public KzedZoomedMapTile(DynmapWorld world, KzedMap map, KzedMapTile original) {
super(world, map);
this.originalTile = original;
}

View File

@ -1,13 +0,0 @@
package org.dynmap.kzedmap;
import java.io.File;
import java.util.Map;
import org.dynmap.MapChunkCache;
public class ZoomedTileRenderer {
public ZoomedTileRenderer(Map<String, Object> configuration) {
}
public void render(MapChunkCache cache, final KzedZoomedMapTile zt, final File outputPath) {
return; /* Doing this in Default render, since image already loaded */
}
}

View File

@ -28,8 +28,12 @@ FlatMapType.prototype = $.extend(new DynMapType(), {
var dnprefix = '';
if(this.dynmap.map.mapTypes[this.dynmap.map.mapTypeId].nightandday && this.dynmap.serverday)
dnprefix = '_day';
tileName = this.prefix + dnprefix + '_128_' + coord.x + '_' + coord.y + '.png';
if(this.dynmap.world.bigworld)
tileName = this.prefix + dnprefix + '/' + (coord.x >> 5) + '_' + (coord.y >> 5) +
'/128_' + coord.x + '_' + coord.y + '.png';
else
tileName = this.prefix + dnprefix + '_128_' + coord.x + '_' + coord.y + '.png';
imgSize = Math.pow(2, 7+zoom);
var tile = $('<div/>')
.addClass('tile')

View File

@ -50,14 +50,28 @@ KzedMapType.prototype = $.extend(new DynMapType(), {
if (zoom == 0) {
// Most zoomed out tiles.
tileSize = 128;
imgSize = tileSize;
tileName = 'z' + this.prefix + dnprefix + '_' + (-coord.x * tileSize*2) + '_' + (coord.y * tileSize*2) + '.png';
imgSize = tileSize;
if (this.dynmap.world.bigworld) {
tileName = 'z' + this.prefix + dnprefix + '/' + ((-coord.x * tileSize*2)>>12) +
'_' + ((coord.y * tileSize*2) >> 12) + '/' +
(-coord.x * tileSize*2) + '_' + (coord.y * tileSize*2) + '.png';
}
else {
tileName = 'z' + this.prefix + dnprefix + '_' + (-coord.x * tileSize*2) + '_' + (coord.y * tileSize*2) + '.png';
}
} else {
// Other zoom levels.
tileSize = 128;
imgSize = Math.pow(2, 6+zoom);
tileName = this.prefix + dnprefix + '_' + (-coord.x*tileSize) + '_' + (coord.y*tileSize) + '.png';
if(this.dynmap.world.bigworld) {
tileName = this.prefix + dnprefix + '/' + ((-coord.x*tileSize) >> 12) + '_' +
((coord.y*tileSize)>>12) + '/' +
(-coord.x*tileSize) + '_' + (coord.y*tileSize) + '.png';
}
else {
tileName = this.prefix + dnprefix + '_' + (-coord.x*tileSize) + '_' + (coord.y*tileSize) + '.png';
}
}
var img;
var tile = $('<div/>')