Skip to content

Commit

Permalink
Set timestamps when rendering starts
Browse files Browse the repository at this point in the history
- Currently only implemented for FileTreeMapStorage
  • Loading branch information
BrainStone committed Jul 20, 2021
1 parent 40fb487 commit 476aa0c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion DynmapCore/src/main/java/org/dynmap/DynmapWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void activateZoomOutFreshen() {
private static final int[] stepseq = { 3, 1, 2, 0 };

private void processZoomFile(MapTypeState mts, MapStorageTile tile, boolean firstVariant) {
final long startTimestamp = System.currentTimeMillis();
int step = 1 << tile.zoom;
MapStorageTile ztile = tile.getZoomOutTile();
int width = 128, height = 128;
Expand Down Expand Up @@ -238,7 +239,7 @@ private void processZoomFile(MapTypeState mts, MapStorageTile tile, boolean firs
}
}
else /* if (!ztile.matchesHashCode(crc)) */ {
ztile.write(crc, zIm);
ztile.write(crc, zIm, startTimestamp);
MapManager.mapman.pushUpdate(this, new Client.Tile(ztile.getURI()));
enqueueZoomOutUpdate(ztile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ public List<DynmapChunk> getRequiredChunks(MapTile tile) {

@Override
public boolean render(MapChunkCache cache, HDMapTile tile, String mapname) {
final long startTimestamp = System.currentTimeMillis();
Color rslt = new Color();
MapIterator mapiter = cache.getIterator(0, 0, 0);
DynmapWorld world = tile.getDynmapWorld();
Expand Down Expand Up @@ -1305,7 +1306,7 @@ public boolean render(MapChunkCache cache, HDMapTile tile, String mapname) {
if(mtile.matchesHashCode(crc) == false) {
/* Wrap buffer as buffered image */
if(rendered[i]) {
mtile.write(crc, im[i].buf_img);
mtile.write(crc, im[i].buf_img, startTimestamp);
}
else {
mtile.delete();
Expand Down Expand Up @@ -1336,7 +1337,7 @@ public boolean render(MapChunkCache cache, HDMapTile tile, String mapname) {
if(mtile.matchesHashCode(crc) == false) {
/* Wrap buffer as buffered image */
if(rendered[i]) {
mtile.write(crc, dayim[i].buf_img);
mtile.write(crc, dayim[i].buf_img, startTimestamp);
}
else {
mtile.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ protected MapStorageTile(DynmapWorld world, MapType map, int x, int y, int zoom,
* @param encImage - output stream for encoded image
* @return true if write succeeded
*/
public abstract boolean write(long hash, BufferOutputStream encImage);
public abstract boolean write(long hash, BufferOutputStream encImage, long timestamp);
/**
* Write tile from image
*
* @param hash - hash code of uncompressed image
* @param image - image to be encoded
* @return true if write succeeded
*/
public boolean write(long hash, BufferedImage image) {
public boolean write(long hash, BufferedImage image, long timestamp) {
BufferOutputStream bos = ImageIOManager.imageIOEncode(image, map.getImageFormat());
if (bos != null) {
return write(hash, bos);
return write(hash, bos, timestamp);
}
return false;
}
Expand All @@ -78,7 +78,7 @@ public boolean write(long hash, BufferedImage image) {
* @return true if write succeeded
*/
public boolean delete() {
return write(-1, (BufferOutputStream) null);
return write(-1, (BufferOutputStream) null, -1);
}
/**
* Get write lock on tile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public TileRead read() {
}

@Override
public boolean write(long hash, BufferOutputStream encImage) {
public boolean write(long hash, BufferOutputStream encImage, long timestamp) {
File ff = getTileFile(map.getImageFormat().getEncoding());
List<File> ffalt = getTileFilesAltFormats();
File ffpar = ff.getParentFile();
Expand All @@ -158,7 +158,7 @@ public boolean write(long hash, BufferOutputStream encImage) {
if (ffpar.exists() == false) {
ffpar.mkdirs();
}
if (replaceFile(ff, encImage.buf, encImage.len) == false) {
if (replaceFile(ff, encImage.buf, encImage.len, timestamp) == false) {
return false;
}
hashmap.updateHashCode(world.getName() + "." + map.getPrefix(), x, y, hash);
Expand Down Expand Up @@ -627,8 +627,12 @@ public String getMarkersURI(boolean login_enabled) {
public String getTilesURI(boolean login_enabled) {
return login_enabled?"standalone/tiles.php?tile=":"tiles/";
}

private boolean replaceFile(File f, byte[] b, int len) {
return replaceFile(f, b, len, System.currentTimeMillis());
}

private boolean replaceFile(File f, byte[] b, int len, long timestamp) {
boolean done = false;
File fold = new File(f.getPath() + ".old");
File fnew = new File(f.getPath() + ".new");
Expand All @@ -649,6 +653,8 @@ private boolean replaceFile(File f, byte[] b, int len) {
else {
fnew.renameTo(f);
}
// Use the supplied timestamp
f.setLastModified(timestamp);
done = true;
} catch (IOException iox) {
if (raf != null) { try { raf.close(); } catch (IOException x) {} }
Expand Down

0 comments on commit 476aa0c

Please sign in to comment.