mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-30 17:34:23 +07:00
Fixed glitchy minimap unit rendering
This commit is contained in:
parent
56bb23400a
commit
0c7f6432d8
@ -320,6 +320,13 @@ public class Control extends Module{
|
||||
Platform.instance.updateRPC();
|
||||
}
|
||||
|
||||
/**Called from main logic thread.*/
|
||||
public void runUpdateLogic(){
|
||||
if(!state.is(State.menu)) {
|
||||
renderer.minimap().updateUnitArray();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.game.EventType.GameOverEvent;
|
||||
@ -104,6 +105,10 @@ public class Logic extends Module {
|
||||
public void update(){
|
||||
if(threads.isEnabled() && !threads.isOnThread()) return;
|
||||
|
||||
if(Vars.control != null){
|
||||
control.runUpdateLogic();
|
||||
}
|
||||
|
||||
if(!state.is(State.menu)){
|
||||
|
||||
if(control != null) control.triggerUpdateInput();
|
||||
|
@ -6,7 +6,9 @@ import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
||||
import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent;
|
||||
@ -14,19 +16,24 @@ import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Events;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Pixmaps;
|
||||
import io.anuke.ucore.scene.utils.ScissorStack;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.ThreadArray;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class MinimapRenderer implements Disposable{
|
||||
private static final int baseSize = 16;
|
||||
private final Array<Unit> units = new ThreadArray<>();
|
||||
private Pixmap pixmap;
|
||||
private Texture texture;
|
||||
private TextureRegion region;
|
||||
private Rectangle rect = new Rectangle();
|
||||
private Rectangle clipRect = new Rectangle();
|
||||
private int zoom = 4;
|
||||
|
||||
public MinimapRenderer(){
|
||||
@ -65,15 +72,23 @@ public class MinimapRenderer implements Disposable{
|
||||
dx = Mathf.clamp(dx, sz, world.width()-sz);
|
||||
dy = Mathf.clamp(dy, sz, world.height()-sz);
|
||||
|
||||
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
|
||||
Units.getNearby(rect, unit -> {
|
||||
if(!rect.contains(unit.x, unit.y)) return;
|
||||
synchronized (units){
|
||||
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
|
||||
Graphics.flush();
|
||||
|
||||
float rx = (unit.x - rect.x) / rect.width * w, ry = (unit.y - rect.y)/ rect.width * h;
|
||||
Draw.color(unit.getTeam().color);
|
||||
Draw.rect("white", x + rx, y + ry, w/(sz*2), h/(sz*2));
|
||||
});
|
||||
Draw.color();
|
||||
boolean clip = ScissorStack.pushScissors(clipRect.set(x, y, w, h));
|
||||
|
||||
for(Unit unit : units){
|
||||
float rx = (unit.x - rect.x) / rect.width * w, ry = (unit.y - rect.y) / rect.width * h;
|
||||
Draw.color(unit.getTeam().color);
|
||||
Draw.rect("white", x + rx, y + ry, w / (sz * 2), h / (sz * 2));
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
|
||||
Graphics.flush();
|
||||
if(clip) ScissorStack.popScissors();
|
||||
}
|
||||
}
|
||||
|
||||
public TextureRegion getRegion() {
|
||||
@ -106,6 +121,20 @@ public class MinimapRenderer implements Disposable{
|
||||
Pixmaps.drawPixel(texture, tile.x, pixmap.getHeight() - 1 - tile.y, color);
|
||||
}
|
||||
|
||||
public void updateUnitArray(){
|
||||
int sz = baseSize * zoom;
|
||||
float dx = (Core.camera.position.x / tilesize);
|
||||
float dy = (Core.camera.position.y / tilesize);
|
||||
dx = Mathf.clamp(dx, sz, world.width()-sz);
|
||||
dy = Mathf.clamp(dy, sz, world.height()-sz);
|
||||
|
||||
synchronized (units) {
|
||||
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
|
||||
units.clear();
|
||||
Units.getNearby(rect, units::add);
|
||||
}
|
||||
}
|
||||
|
||||
private int colorFor(Tile tile){
|
||||
int color = tile.breakable() ? tile.target().getTeam().intColor : ColorMapper.getColor(tile.block());
|
||||
if(color == 0) color = ColorMapper.getColor(tile.floor());
|
||||
|
Loading…
Reference in New Issue
Block a user