Skip to content

Commit

Permalink
maps: don't spam rerender
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 2, 2021
1 parent ed0c5fb commit 529c46a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
Expand Up @@ -227,6 +227,7 @@ else if (id != null) {
dmr.autoUpdate = true;
}
dmr.addObject(new MapImage(x.asString(), y.asString(), "true", false, image.asString(), wide, high));
dmr.hasChanged = true;
}
}
}
Expand Up @@ -57,6 +57,8 @@ public MapScriptContainer(YamlConfiguration configurationSection, String scriptC
// # Specify an HTTP url or file path within Denizen/images/ for the image. Supports animated .gif!
// image: my_image.png
// # Optionally add width/height numbers.
// width: 128
// height: 128
//
// 2:
// type: text
Expand Down
Expand Up @@ -149,13 +149,14 @@ public static void setMap(MapView map, DenizenMapRenderer denizenMapRenderer) {
}
map.addRenderer(denizenMapRenderer);
mapRenderers.put(map.getId(), denizenMapRenderer);
denizenMapRenderer.hasChanged = true;
}

public static DenizenMapRenderer getDenizenRenderer(MapView map) {
int mapId = map.getId();
DenizenMapRenderer dmr;
if (!mapRenderers.containsKey(mapId)) {
dmr = new DenizenMapRenderer(map.getRenderers(), false, true);
dmr = new DenizenMapRenderer(map.getRenderers(), false, false);
setMap(map, dmr);
}
else {
Expand Down
Expand Up @@ -13,13 +13,17 @@
public class DenizenMapRenderer extends MapRenderer {

public List<MapObject> mapObjects = new ArrayList<>();

private List<MapRenderer> oldMapRenderers;

public boolean autoUpdate;

public boolean displayOriginal = true;

private boolean active;

public boolean hasChanged = true;

public DenizenMapRenderer(List<MapRenderer> oldMapRenderers, boolean autoUpdate, boolean contextual) {
super(contextual);
this.oldMapRenderers = oldMapRenderers;
Expand Down Expand Up @@ -81,6 +85,9 @@ public void render(MapView mapView, MapCanvas mapCanvas, Player player) {
mapView.removeRenderer(this);
return;
}
if (!autoUpdate && !hasChanged) {
return;
}
try {
while (mapCanvas.getCursors().size() > 0) {
mapCanvas.getCursors().removeCursor(mapCanvas.getCursors().getCursor(0));
Expand All @@ -101,6 +108,7 @@ public void render(MapView mapView, MapCanvas mapCanvas, Player player) {
object.render(mapView, mapCanvas, p, uuid);
}
}
hasChanged = false;
}
catch (Exception e) {
Debug.echoError(e);
Expand Down
Expand Up @@ -78,7 +78,7 @@ public void setHints(int hintflags) {

@Override
public void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int off, int scansize) {
// When the internal pixels are updated, the cache is no longer currently.
// When the internal pixels are updated, the cache is no longer current.
cachedImageData = null;
}

Expand Down
Expand Up @@ -429,19 +429,26 @@ public void setMapData(MapCanvas canvas, byte[] bytes, int x, int y, MapImage im
return;
}
try {
boolean anyChanged = false;
byte[] buffer = (byte[]) CANVAS_GET_BUFFER.invoke(canvas);
for (int x2 = x < 0 ? -x : 0; x2 < width; ++x2) {
for (int y2 = y < 0 ? -y : 0; y2 < height; ++y2) {
byte p = bytes[y2 * image.width + x2];
if (p != MapPalette.TRANSPARENT) {
buffer[(y2 + y) * 128 + (x2 + x)] = p;
int index = (y2 + y) * 128 + (x2 + x);
if (buffer[index] != p) {
buffer[index] = p;
anyChanged = true;
}
}
}
}
// Flag the whole image as dirty
MapItemSavedData map = (MapItemSavedData) MAPVIEW_WORLDMAP.get(canvas.getMapView());
map.setColorsDirty(Math.max(x, 0), Math.max(y, 0));
map.setColorsDirty(width + x - 1, height + y - 1);
if (anyChanged) {
// Flag the whole image as dirty
MapItemSavedData map = (MapItemSavedData) MAPVIEW_WORLDMAP.get(canvas.getMapView());
map.setColorsDirty(Math.max(x, 0), Math.max(y, 0));
map.setColorsDirty(width + x - 1, height + y - 1);
}
}
catch (Throwable ex) {
Debug.echoError(ex);
Expand Down

0 comments on commit 529c46a

Please sign in to comment.