Fixed minimap update lag
This commit is contained in:
@@ -21,7 +21,8 @@ import mindustry.world.*;
|
|||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class MinimapRenderer{
|
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 final Seq<Unit> units = new Seq<>();
|
||||||
private Pixmap pixmap;
|
private Pixmap pixmap;
|
||||||
private Texture texture;
|
private Texture texture;
|
||||||
@@ -31,6 +32,8 @@ public class MinimapRenderer{
|
|||||||
|
|
||||||
private float lastX, lastY, lastW, lastH, lastScl;
|
private float lastX, lastY, lastW, lastH, lastScl;
|
||||||
private boolean worldSpace;
|
private boolean worldSpace;
|
||||||
|
private IntSet updates = new IntSet();
|
||||||
|
private float updateCounter = 0f;
|
||||||
|
|
||||||
public MinimapRenderer(){
|
public MinimapRenderer(){
|
||||||
Events.on(WorldLoadEvent.class, event -> {
|
Events.on(WorldLoadEvent.class, event -> {
|
||||||
@@ -65,6 +68,26 @@ public class MinimapRenderer{
|
|||||||
});
|
});
|
||||||
|
|
||||||
Events.on(BuildTeamChangeEvent.class, event -> update(event.build.tile));
|
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(){
|
public Pixmap getPixmap(){
|
||||||
@@ -89,6 +112,7 @@ public class MinimapRenderer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reset(){
|
public void reset(){
|
||||||
|
updates.clear();
|
||||||
if(pixmap != null){
|
if(pixmap != null){
|
||||||
pixmap.dispose();
|
pixmap.dispose();
|
||||||
texture.dispose();
|
texture.dispose();
|
||||||
@@ -319,10 +343,7 @@ public class MinimapRenderer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updatePixel(Tile tile){
|
void updatePixel(Tile tile){
|
||||||
int color = colorFor(tile);
|
updates.add(tile.pos());
|
||||||
pixmap.set(tile.x, pixmap.height - 1 - tile.y, color);
|
|
||||||
|
|
||||||
Pixmaps.drawPixel(texture, tile.x, pixmap.height - 1 - tile.y, color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateUnitArray(){
|
public void updateUnitArray(){
|
||||||
|
|||||||
Reference in New Issue
Block a user