mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 05:05:16 +01:00
Made zoomed-rendering make use of existing tile-files instead of keeping those tiles in memory.
This commit is contained in:
parent
38ee8657e8
commit
fb1b5df3d0
@ -16,8 +16,8 @@ webserver-bindaddress: 0.0.0.0
|
|||||||
webserver-port: 8123
|
webserver-port: 8123
|
||||||
|
|
||||||
disabledcommands:
|
disabledcommands:
|
||||||
- fullrender
|
# - fullrender
|
||||||
- fullrenderasync
|
# - fullrenderasync
|
||||||
|
|
||||||
# The maptypes Dynmap will use to render.
|
# The maptypes Dynmap will use to render.
|
||||||
maps:
|
maps:
|
||||||
|
@ -79,63 +79,63 @@ public class MapManager extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void renderFullWorld(Location l) {
|
void renderFullWorld(Location l) {
|
||||||
synchronized (lock) {
|
debugger.debug("Full render starting...");
|
||||||
debugger.debug("Full render starting...");
|
for (MapType map : maps) {
|
||||||
for (MapType map : maps) {
|
int requiredChunkCount = 200;
|
||||||
HashSet<MapTile> found = new HashSet<MapTile>();
|
HashSet<MapTile> found = new HashSet<MapTile>();
|
||||||
HashSet<MapTile> rendered = new HashSet<MapTile>();
|
HashSet<MapTile> rendered = new HashSet<MapTile>();
|
||||||
LinkedList<MapTile> renderQueue = new LinkedList<MapTile>();
|
LinkedList<MapTile> renderQueue = new LinkedList<MapTile>();
|
||||||
LinkedList<DynmapChunk> loadedChunks = new LinkedList<DynmapChunk>();
|
LinkedList<DynmapChunk> loadedChunks = new LinkedList<DynmapChunk>();
|
||||||
|
|
||||||
for (MapTile tile : map.getTiles(l)) {
|
for (MapTile tile : map.getTiles(l)) {
|
||||||
if (!found.contains(tile)) {
|
if (!found.contains(tile)) {
|
||||||
found.add(tile);
|
found.add(tile);
|
||||||
renderQueue.add(tile);
|
renderQueue.add(tile);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (!renderQueue.isEmpty()) {
|
}
|
||||||
MapTile tile = renderQueue.pollFirst();
|
while (!renderQueue.isEmpty()) {
|
||||||
|
MapTile tile = renderQueue.pollFirst();
|
||||||
DynmapChunk[] requiredChunks = tile.getMap().getRequiredChunks(tile);
|
|
||||||
|
DynmapChunk[] requiredChunks = tile.getMap().getRequiredChunks(tile);
|
||||||
// Unload old chunks.
|
|
||||||
while (loadedChunks.size() >= Math.max(0, 200 - requiredChunks.length)) {
|
if (requiredChunks.length > requiredChunkCount)
|
||||||
DynmapChunk c = loadedChunks.pollFirst();
|
requiredChunkCount = requiredChunks.length;
|
||||||
world.unloadChunk(c.x, c.y, false, true);
|
// Unload old chunks.
|
||||||
}
|
while (loadedChunks.size() >= requiredChunkCount - requiredChunks.length) {
|
||||||
|
|
||||||
// Load the required chunks.
|
|
||||||
for (DynmapChunk chunk : requiredChunks) {
|
|
||||||
boolean wasLoaded = world.isChunkLoaded(chunk.x, chunk.y);
|
|
||||||
world.loadChunk(chunk.x, chunk.y, false);
|
|
||||||
if (!wasLoaded)
|
|
||||||
loadedChunks.add(chunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
debugger.debug("renderQueue: " + renderQueue.size() + "/" + found.size());
|
|
||||||
if (map.render(tile)) {
|
|
||||||
found.remove(tile);
|
|
||||||
rendered.add(tile);
|
|
||||||
updateQueue.pushUpdate(new Client.Tile(tile.getName()));
|
|
||||||
for (MapTile adjTile : map.getAdjecentTiles(tile)) {
|
|
||||||
if (!(found.contains(adjTile) || rendered.contains(adjTile))) {
|
|
||||||
found.add(adjTile);
|
|
||||||
renderQueue.add(adjTile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
found.remove(tile);
|
|
||||||
System.gc();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unload remaining chunks to clean-up.
|
|
||||||
while (!loadedChunks.isEmpty()) {
|
|
||||||
DynmapChunk c = loadedChunks.pollFirst();
|
DynmapChunk c = loadedChunks.pollFirst();
|
||||||
world.unloadChunk(c.x, c.y, false, true);
|
world.unloadChunk(c.x, c.y, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load the required chunks.
|
||||||
|
for (DynmapChunk chunk : requiredChunks) {
|
||||||
|
boolean wasLoaded = world.isChunkLoaded(chunk.x, chunk.y);
|
||||||
|
world.loadChunk(chunk.x, chunk.y, false);
|
||||||
|
if (!wasLoaded)
|
||||||
|
loadedChunks.add(chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.render(tile)) {
|
||||||
|
found.remove(tile);
|
||||||
|
rendered.add(tile);
|
||||||
|
updateQueue.pushUpdate(new Client.Tile(tile.getName()));
|
||||||
|
for (MapTile adjTile : map.getAdjecentTiles(tile)) {
|
||||||
|
if (!found.contains(adjTile) && !rendered.contains(adjTile)) {
|
||||||
|
found.add(adjTile);
|
||||||
|
renderQueue.add(adjTile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
found.remove(tile);
|
||||||
|
System.gc();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unload remaining chunks to clean-up.
|
||||||
|
while (!loadedChunks.isEmpty()) {
|
||||||
|
DynmapChunk c = loadedChunks.pollFirst();
|
||||||
|
world.unloadChunk(c.x, c.y, false, true);
|
||||||
}
|
}
|
||||||
debugger.debug("Full render finished.");
|
|
||||||
}
|
}
|
||||||
|
debugger.debug("Full render finished.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private MapType[] loadMapTypes(ConfigurationNode configuration) {
|
private MapType[] loadMapTypes(ConfigurationNode configuration) {
|
||||||
|
@ -93,8 +93,8 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||||||
|
|
||||||
/* save the generated tile */
|
/* save the generated tile */
|
||||||
saveTile(tile, im, path);
|
saveTile(tile, im, path);
|
||||||
|
im.flush();
|
||||||
((KzedMap) tile.getMap()).invalidateTile(new KzedZoomedMapTile((KzedMap) tile.getMap(), im, tile));
|
((KzedMap) tile.getMap()).invalidateTile(new KzedZoomedMapTile((KzedMap) tile.getMap(), tile));
|
||||||
|
|
||||||
return !isempty;
|
return !isempty;
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,10 @@ public class KzedZoomedMapTile extends MapTile {
|
|||||||
return "z" + originalTile.renderer.getName() + "_" + getTileX() + "_" + getTileY();
|
return "z" + originalTile.renderer.getName() + "_" + getTileX() + "_" + getTileY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage unzoomedImage;
|
|
||||||
public KzedMapTile originalTile;
|
public KzedMapTile originalTile;
|
||||||
|
|
||||||
public KzedZoomedMapTile(KzedMap map, BufferedImage unzoomedImage, KzedMapTile original) {
|
public KzedZoomedMapTile(KzedMap map, KzedMapTile original) {
|
||||||
super(map);
|
super(map);
|
||||||
this.unzoomedImage = unzoomedImage;
|
|
||||||
this.originalTile = original;
|
this.originalTile = original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,26 +19,38 @@ public class ZoomedTileRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render(KzedZoomedMapTile zt, String outputPath) {
|
public void render(KzedZoomedMapTile zt, String outputPath) {
|
||||||
KzedMapTile t = zt.originalTile;
|
KzedMapTile originalTile = zt.originalTile;
|
||||||
String zoomPath = new File(new File(outputPath), zt.getName() + ".png").getPath();
|
int px = originalTile.px;
|
||||||
render(t.px, t.py, zt.getTileX(), zt.getTileY(), zt.unzoomedImage, zoomPath);
|
int py = originalTile.py;
|
||||||
}
|
int zpx = zt.getTileX();
|
||||||
|
int zpy = zt.getTileY();
|
||||||
public void render(int px, int py, int zpx, int zpy, BufferedImage image, String zoomPath) {
|
|
||||||
BufferedImage zIm = null;
|
BufferedImage image = null;
|
||||||
debugger.debug("Trying to load zoom-out tile: " + zoomPath);
|
|
||||||
try {
|
try {
|
||||||
File file = new File(zoomPath);
|
image = ImageIO.read(new File(new File(outputPath), originalTile.getName() + ".png"));
|
||||||
zIm = ImageIO.read(file);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (image == null) {
|
||||||
|
debugger.debug("Could not load original tile, won't render zoom-out tile.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedImage zIm = null;
|
||||||
|
File zoomFile = new File(new File(outputPath), zt.getName() + ".png");
|
||||||
|
try {
|
||||||
|
zIm = ImageIO.read(zoomFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zIm == null) {
|
if (zIm == null) {
|
||||||
/* create new one */
|
/* create new one */
|
||||||
zIm = new BufferedImage(KzedMap.tileWidth, KzedMap.tileHeight, BufferedImage.TYPE_INT_RGB);
|
zIm = new BufferedImage(KzedMap.tileWidth, KzedMap.tileHeight, BufferedImage.TYPE_INT_RGB);
|
||||||
debugger.debug("New zoom-out tile created " + zoomPath);
|
debugger.debug("New zoom-out tile created " + zt.getName());
|
||||||
} else {
|
} else {
|
||||||
debugger.debug("Loaded zoom-out tile from " + zoomPath);
|
debugger.debug("Loaded zoom-out tile from " + zt.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update zoom-out tile */
|
/* update zoom-out tile */
|
||||||
@ -66,13 +78,12 @@ public class ZoomedTileRenderer {
|
|||||||
|
|
||||||
/* save zoom-out tile */
|
/* save zoom-out tile */
|
||||||
try {
|
try {
|
||||||
File file = new File(zoomPath);
|
ImageIO.write(zIm, "png", zoomFile);
|
||||||
ImageIO.write(zIm, "png", file);
|
debugger.debug("Saved zoom-out tile at " + zoomFile.getName());
|
||||||
debugger.debug("Saved zoom-out tile at " + zoomPath);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
debugger.error("Failed to save zoom-out tile: " + zoomPath, e);
|
debugger.error("Failed to save zoom-out tile: " + zoomFile.getName(), e);
|
||||||
} catch (java.lang.NullPointerException e) {
|
} catch (java.lang.NullPointerException e) {
|
||||||
debugger.error("Failed to save zoom-out tile (NullPointerException): " + zoomPath, e);
|
debugger.error("Failed to save zoom-out tile (NullPointerException): " + zoomFile.getName(), e);
|
||||||
}
|
}
|
||||||
zIm.flush();
|
zIm.flush();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user