Fixed minimap update lag

This commit is contained in:
Anuken
2023-04-21 11:44:00 -04:00
parent 7a01be6dba
commit eb1d0b8362

View File

@@ -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<Unit> 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(){