From eb1d0b83625b7216ce4d2fb093449ba25080349e Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 21 Apr 2023 11:44:00 -0400 Subject: [PATCH] Fixed minimap update lag --- .../mindustry/graphics/MinimapRenderer.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/core/src/mindustry/graphics/MinimapRenderer.java b/core/src/mindustry/graphics/MinimapRenderer.java index 6fddddf503..970eb390fa 100644 --- a/core/src/mindustry/graphics/MinimapRenderer.java +++ b/core/src/mindustry/graphics/MinimapRenderer.java @@ -21,7 +21,8 @@ import mindustry.world.*; import static mindustry.Vars.*; public class MinimapRenderer{ - private static final float baseSize = 16f; + private static final float baseSize = 16f, updateInterval = 2f; + private final Seq units = new Seq<>(); private Pixmap pixmap; private Texture texture; @@ -31,6 +32,8 @@ public class MinimapRenderer{ private float lastX, lastY, lastW, lastH, lastScl; private boolean worldSpace; + private IntSet updates = new IntSet(); + private float updateCounter = 0f; public MinimapRenderer(){ Events.on(WorldLoadEvent.class, event -> { @@ -65,6 +68,26 @@ public class MinimapRenderer{ }); Events.on(BuildTeamChangeEvent.class, event -> update(event.build.tile)); + + Events.run(Trigger.update, () -> { + //updates are batched to occur every 2 frames + if((updateCounter += Time.delta) >= updateInterval){ + updateCounter %= updateInterval; + + updates.each(pos -> { + Tile tile = world.tile(pos); + if(tile == null) return; + + int color = colorFor(tile); + pixmap.set(tile.x, pixmap.height - 1 - tile.y, color); + + //yes, this calls glTexSubImage2D every time, with a 1x1 region + Pixmaps.drawPixel(texture, tile.x, pixmap.height - 1 - tile.y, color); + }); + + updates.clear(); + } + }); } public Pixmap getPixmap(){ @@ -89,6 +112,7 @@ public class MinimapRenderer{ } public void reset(){ + updates.clear(); if(pixmap != null){ pixmap.dispose(); texture.dispose(); @@ -319,10 +343,7 @@ public class MinimapRenderer{ } void updatePixel(Tile tile){ - int color = colorFor(tile); - pixmap.set(tile.x, pixmap.height - 1 - tile.y, color); - - Pixmaps.drawPixel(texture, tile.x, pixmap.height - 1 - tile.y, color); + updates.add(tile.pos()); } public void updateUnitArray(){