Many various bugfixes, more aggressive memory optimization

This commit is contained in:
Anuken
2018-06-26 11:15:23 -04:00
parent 8ec9d95cd2
commit 7a049d64d8
39 changed files with 189 additions and 87 deletions

View File

@@ -27,7 +27,7 @@ allprojects {
gdxVersion = '1.9.8' gdxVersion = '1.9.8'
roboVMVersion = '2.3.0' roboVMVersion = '2.3.0'
aiVersion = '1.8.1' aiVersion = '1.8.1'
uCoreVersion = '19fbbd3b3a' uCoreVersion = 'da40998ac6'
getVersionString = { getVersionString = {
String buildVersion = getBuildVersion() String buildVersion = getBuildVersion()

View File

@@ -29,6 +29,7 @@ text.addplayers=Add/Remove Players
text.newgame=New Game text.newgame=New Game
text.quit=Quit text.quit=Quit
text.maps=Maps text.maps=Maps
text.maps.none=[LIGHT_GRAY]No maps found!
text.about.button=About text.about.button=About
text.name=Name: text.name=Name:
text.unlocked=New Block Unlocked! text.unlocked=New Block Unlocked!
@@ -219,6 +220,9 @@ text.menu=Menu
text.play=Play text.play=Play
text.load=Load text.load=Load
text.save=Save text.save=Save
text.fps=FPS: {0}
text.tps=TPS: {0}
text.ping=Ping: {0}ms
text.language.restart=Please restart your game for the language settings to take effect. text.language.restart=Please restart your game for the language settings to take effect.
text.settings.language=Language text.settings.language=Language
text.settings=Settings text.settings=Settings

View File

@@ -154,11 +154,11 @@ public class Vars{
puddleGroup = Entities.addGroup(Puddle.class, false).enableMapping(); puddleGroup = Entities.addGroup(Puddle.class, false).enableMapping();
itemGroup = Entities.addGroup(ItemDrop.class).enableMapping(); itemGroup = Entities.addGroup(ItemDrop.class).enableMapping();
fireGroup = Entities.addGroup(Fire.class, false).enableMapping(); fireGroup = Entities.addGroup(Fire.class, false).enableMapping();
unitGroups = new EntityGroup[Team.values().length]; unitGroups = new EntityGroup[Team.all.length];
threads = new ThreadHandler(Platform.instance.getThreadProvider()); threads = new ThreadHandler(Platform.instance.getThreadProvider());
for(Team team : Team.values()){ for(Team team : Team.all){
unitGroups[team.ordinal()] = Entities.addGroup(BaseUnit.class).enableMapping(); unitGroups[team.ordinal()] = Entities.addGroup(BaseUnit.class).enableMapping();
} }

View File

@@ -73,8 +73,8 @@ public class BlockIndexer {
ores = null; ores = null;
//create bitset for each team type that contains each quadrant //create bitset for each team type that contains each quadrant
structQuadrants = new Bits[Team.values().length]; structQuadrants = new Bits[Team.all.length];
for(int i = 0; i < Team.values().length; i ++){ for(int i = 0; i < Team.all.length; i ++){
structQuadrants[i] = new Bits(Mathf.ceil(world.width() / (float)structQuadrantSize) * Mathf.ceil(world.height() / (float)structQuadrantSize)); structQuadrants[i] = new Bits(Mathf.ceil(world.width() / (float)structQuadrantSize) * Mathf.ceil(world.height() / (float)structQuadrantSize));
} }

View File

@@ -116,7 +116,7 @@ public class Pathfinder {
private void createFor(Team team){ private void createFor(Team team){
PathData path = new PathData(); PathData path = new PathData();
path.search ++; path.search ++;
path.frontier.ensureCapacity(world.width() * world.height() / 2); path.frontier.ensureCapacity((world.width() + world.height()) * 3);
paths[team.ordinal()] = path; paths[team.ordinal()] = path;
@@ -167,7 +167,7 @@ public class Pathfinder {
private void clear(){ private void clear(){
Timers.mark(); Timers.mark();
paths = new PathData[Team.values().length]; paths = new PathData[Team.all.length];
blocked.clear(); blocked.clear();
for(TeamData data : state.teams.getTeams()){ for(TeamData data : state.teams.getTeams()){

View File

@@ -15,7 +15,7 @@ public class Items implements ContentList{
public void load() { public void load() {
stone = new Item("stone", Color.valueOf("777777")) {{ stone = new Item("stone", Color.valueOf("777777")) {{
hardness = 2; hardness = 3;
}}; }};
tungsten = new Item("tungsten", Color.valueOf("a0b0c8")) {{ tungsten = new Item("tungsten", Color.valueOf("a0b0c8")) {{

View File

@@ -241,6 +241,10 @@ public class NetClient extends Module {
//get data input for reading from the stream //get data input for reading from the stream
DataInputStream input = netClient.dataStream; DataInputStream input = netClient.dataStream;
//read wave info
state.wavetime = input.readFloat();
state.wave = input.readInt();
byte cores = input.readByte(); byte cores = input.readByte();
for (int i = 0; i < cores; i++) { for (int i = 0; i < cores; i++) {

View File

@@ -328,11 +328,9 @@ public class NetServer extends Module{
//reset stream to begin writing //reset stream to begin writing
syncStream.reset(); syncStream.reset();
int totalGroups = 0; //write wave data
dataStream.writeFloat(state.wavetime);
for (EntityGroup<?> group : Entities.getAllGroups()) { dataStream.writeInt(state.wave);
if (!group.isEmpty() && (group.all().get(0) instanceof SyncTrait)) totalGroups ++;
}
Array<Tile> cores = state.teams.get(player.getTeam()).cores; Array<Tile> cores = state.teams.get(player.getTeam()).cores;
@@ -347,6 +345,12 @@ public class NetServer extends Module{
//write timestamp //write timestamp
dataStream.writeLong(TimeUtils.millis()); dataStream.writeLong(TimeUtils.millis());
int totalGroups = 0;
for (EntityGroup<?> group : Entities.getAllGroups()) {
if (!group.isEmpty() && (group.all().get(0) instanceof SyncTrait)) totalGroups ++;
}
//write total amount of serializable groups //write total amount of serializable groups
dataStream.writeByte(totalGroups); dataStream.writeByte(totalGroups);

View File

@@ -252,7 +252,7 @@ public class Renderer extends RendererModule{
} }
private void drawAllTeams(boolean flying){ private void drawAllTeams(boolean flying){
for(Team team : Team.values()){ for(Team team : Team.all){
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()]; EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
if(group.count(p -> p.isFlying() == flying) + if(group.count(p -> p.isFlying() == flying) +

View File

@@ -61,7 +61,7 @@ public class ThreadHandler {
} }
} }
public int getFPS(){ public int getTPS(){
return (int)(60/delta); return (int)(60/delta);
} }
@@ -112,7 +112,7 @@ public class ThreadHandler {
} }
public boolean doInterpolate(){ public boolean doInterpolate(){
return enabled && Math.abs(Gdx.graphics.getFramesPerSecond() - getFPS()) > 15; return enabled && Math.abs(Gdx.graphics.getFramesPerSecond() - getTPS()) > 15;
} }
public boolean isOnThread(){ public boolean isOnThread(){

View File

@@ -457,7 +457,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
int i = 0; int i = 0;
for(Team team : Team.values()){ for(Team team : Team.all){
ImageButton button = new ImageButton("white", "toggle"); ImageButton button = new ImageButton("white", "toggle");
button.margin(4f, 4f, 10f, 4f); button.margin(4f, 4f, 10f, 4f);
button.getImageCell().grow(); button.getImageCell().grow();

View File

@@ -3,9 +3,11 @@ package io.anuke.mindustry.editor;
import io.anuke.mindustry.io.Map; import io.anuke.mindustry.io.Map;
import io.anuke.mindustry.ui.BorderImage; import io.anuke.mindustry.ui.BorderImage;
import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.function.Consumer; import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.scene.ui.ButtonGroup; import io.anuke.ucore.scene.ui.ButtonGroup;
import io.anuke.ucore.scene.ui.ScrollPane; import io.anuke.ucore.scene.ui.ScrollPane;
import io.anuke.ucore.scene.ui.ScrollPane.ScrollPaneStyle;
import io.anuke.ucore.scene.ui.TextButton; import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.scene.ui.layout.Table;
@@ -65,7 +67,13 @@ public class MapLoadDialog extends FloatingDialog{
if (++i % maxcol == 0) table.row(); if (++i % maxcol == 0) table.row();
} }
content().add("$text.editor.loadmap"); if(world.maps().all().size == 0){
pane.setStyle(Core.skin.get("clear", ScrollPaneStyle.class));
table.add("$text.maps.none").center();
}else {
content().add("$text.editor.loadmap");
}
content().row(); content().row();
content().add(pane); content().add(pane);
} }

View File

@@ -106,7 +106,7 @@ public class MapRenderer implements Disposable{
byte btr = editor.getMap().read(wx, wy, DataPosition.rotationTeam); byte btr = editor.getMap().read(wx, wy, DataPosition.rotationTeam);
byte elev = editor.getMap().read(wx, wy, DataPosition.elevation); byte elev = editor.getMap().read(wx, wy, DataPosition.elevation);
byte rotation = Bits.getLeftByte(btr); byte rotation = Bits.getLeftByte(btr);
Team team = Team.values()[Bits.getRightByte(btr)]; Team team = Team.all[Bits.getRightByte(btr)];
Block floor = Block.getByID(bf); Block floor = Block.getByID(bf);
Block wall = Block.getByID(bw); Block wall = Block.getByID(bw);

View File

@@ -502,7 +502,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
movement.setZero(); movement.setZero();
String section = "player_" + (playerIndex + 1); String section = control.input(playerIndex).section;
float xa = Inputs.getAxis(section, "move_x"); float xa = Inputs.getAxis(section, "move_x");
float ya = Inputs.getAxis(section, "move_y"); float ya = Inputs.getAxis(section, "move_y");

View File

@@ -136,7 +136,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
this.status.readSave(stream); this.status.readSave(stream);
this.inventory.readSave(stream); this.inventory.readSave(stream);
this.team = Team.values()[team]; this.team = Team.all[team];
this.health = health; this.health = health;
this.x = x; this.x = x;
this.y = y; this.y = y;

View File

@@ -220,7 +220,7 @@ public class Units {
/**Iterates over all units in a rectangle.*/ /**Iterates over all units in a rectangle.*/
public static void getNearby(Rectangle rect, Consumer<Unit> cons){ public static void getNearby(Rectangle rect, Consumer<Unit> cons){
for(Team team : Team.values()){ for(Team team : Team.all){
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()]; EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
if(!group.isEmpty()){ if(!group.isEmpty()){
EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit)entity)); EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit)entity));
@@ -253,7 +253,7 @@ public class Units {
/**Iterates over all units.*/ /**Iterates over all units.*/
public static void getAllUnits(Consumer<Unit> cons){ public static void getAllUnits(Consumer<Unit> cons){
for(Team team : Team.values()){ for(Team team : Team.all){
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()]; EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
for(Unit unit : group.all()){ for(Unit unit : group.all()){
cons.accept(unit); cons.accept(unit);

View File

@@ -145,7 +145,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
y = data.readFloat(); y = data.readFloat();
velocity.x = data.readFloat(); velocity.x = data.readFloat();
velocity.y = data.readFloat(); velocity.y = data.readFloat();
team = Team.values()[data.readByte()]; team = Team.all[data.readByte()];
type = BulletType.getByID(data.readByte()); type = BulletType.getByID(data.readByte());
} }

View File

@@ -39,7 +39,7 @@ import static io.anuke.mindustry.Vars.world;
public interface BuilderTrait { public interface BuilderTrait {
//these are not instance variables! //these are not instance variables!
Translator[] tmptr = {new Translator(), new Translator(), new Translator(), new Translator()}; Translator[] tmptr = {new Translator(), new Translator(), new Translator(), new Translator()};
float placeDistance = 200f; float placeDistance = 140f;
float mineDistance = 70f; float mineDistance = 70f;
/**Returns the queue for storing build requests.*/ /**Returns the queue for storing build requests.*/
@@ -118,7 +118,8 @@ public interface BuilderTrait {
Tile tile = world.tile(current.x, current.y); Tile tile = world.tile(current.x, current.y);
if(unit.distanceTo(tile) > placeDistance) { //out of range, skip it. if(unit.distanceTo(tile) > placeDistance || //out of range, skip it
(current.lastEntity != null && current.lastEntity.isDead())) { //build/destroy request has died, skip it
getPlaceQueue().removeFirst(); getPlaceQueue().removeFirst();
}else if(current.remove){ }else if(current.remove){
@@ -144,6 +145,7 @@ public interface BuilderTrait {
//otherwise, update it. //otherwise, update it.
BreakEntity entity = tile.entity(); BreakEntity entity = tile.entity();
current.lastEntity = entity;
entity.addProgress(core, unit, 1f / entity.breakTime * Timers.delta() * getBuildPower(tile)); entity.addProgress(core, unit, 1f / entity.breakTime * Timers.delta() * getBuildPower(tile));
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(entity), 0.4f); unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(entity), 0.4f);
@@ -174,6 +176,7 @@ public interface BuilderTrait {
//otherwise, update it. //otherwise, update it.
BuildEntity entity = tile.entity(); BuildEntity entity = tile.entity();
current.lastEntity = entity;
entity.addProgress(core.items, 1f / entity.recipe.cost * Timers.delta() * getBuildPower(tile)); entity.addProgress(core.items, 1f / entity.recipe.cost * Timers.delta() * getBuildPower(tile));
if(unit instanceof Player){ if(unit instanceof Player){
@@ -288,7 +291,9 @@ public interface BuilderTrait {
public final int x, y, rotation; public final int x, y, rotation;
public final Recipe recipe; public final Recipe recipe;
public final boolean remove; public final boolean remove;
public boolean requested; public boolean requested;
public TileEntity lastEntity;
public float progress; public float progress;

View File

@@ -14,7 +14,7 @@ public interface SyncTrait extends Entity, TypeTrait {
/**Whether smoothing of entities is enabled when using multithreading; not yet implemented.*/ /**Whether smoothing of entities is enabled when using multithreading; not yet implemented.*/
static boolean isSmoothing(){ static boolean isSmoothing(){
return threads.isEnabled() && threads.getFPS() <= Gdx.graphics.getFramesPerSecond() / 2f; return threads.isEnabled() && threads.getTPS() <= Gdx.graphics.getFramesPerSecond() / 2f;
} }
/**Sets the position of this entity and updated the interpolator.*/ /**Sets the position of this entity and updated the interpolator.*/

View File

@@ -18,6 +18,8 @@ public enum Difficulty {
/**Scaling of max time between waves. Default time is 4 minutes.*/ /**Scaling of max time between waves. Default time is 4 minutes.*/
public final float maxTimeScaling; public final float maxTimeScaling;
private String value;
Difficulty(float enemyScaling, float timeScaling, float maxTimeScaling){ Difficulty(float enemyScaling, float timeScaling, float maxTimeScaling){
this.enemyScaling = enemyScaling; this.enemyScaling = enemyScaling;
this.timeScaling = timeScaling; this.timeScaling = timeScaling;
@@ -26,6 +28,9 @@ public enum Difficulty {
@Override @Override
public String toString() { public String toString() {
return Bundles.get("setting.difficulty." + name()); if(value == null){
value = Bundles.get("setting.difficulty." + name());
}
return value;
} }
} }

View File

@@ -13,6 +13,8 @@ public enum Team {
public final Color color; public final Color color;
public final int intColor; public final int intColor;
public final static Team[] all = values();
Team(Color color){ Team(Color color){
this.color = color; this.color = color;
intColor = Color.rgba8888(color); intColor = Color.rgba8888(color);

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.graphics; package io.anuke.mindustry.graphics;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Sort;
import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
@@ -10,8 +11,6 @@ import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
import static io.anuke.ucore.core.Core.camera; import static io.anuke.ucore.core.Core.camera;
@@ -106,8 +105,8 @@ public class BlockRenderer{
floorRenderer.drawLayer(CacheLayer.walls); floorRenderer.drawLayer(CacheLayer.walls);
floorRenderer.endDraw(); floorRenderer.endDraw();
Graphics.begin(); Graphics.begin();
Arrays.sort(requests.items, 0, requestidx); Sort.instance().sort(requests.items, 0, requestidx);
iterateidx = 0; iterateidx = 0;
} }

View File

@@ -42,6 +42,7 @@ public abstract class InputHandler extends InputAdapter{
final static float backTrns = 3f; final static float backTrns = 3f;
public final Player player; public final Player player;
public final String section;
public final OverlayFragment frag = new OverlayFragment(this); public final OverlayFragment frag = new OverlayFragment(this);
public Recipe recipe; public Recipe recipe;
@@ -50,6 +51,7 @@ public abstract class InputHandler extends InputAdapter{
public InputHandler(Player player){ public InputHandler(Player player){
this.player = player; this.player = player;
this.section = "player_" + (player.playerIndex + 1);
Timers.run(1f, () -> frag.build(Core.scene.getRoot())); Timers.run(1f, () -> frag.build(Core.scene.getRoot()));
} }

View File

@@ -42,7 +42,7 @@ public class MapIO {
Block floor = Block.getByID(marker.floor); Block floor = Block.getByID(marker.floor);
Block wall = Block.getByID(marker.wall); Block wall = Block.getByID(marker.wall);
int wallc = ColorMapper.getBlockColor(wall); int wallc = ColorMapper.getBlockColor(wall);
if(wallc == 0 && (wall.update || wall.solid || wall.breakable)) wallc = Team.values()[marker.team].intColor; if(wallc == 0 && (wall.update || wall.solid || wall.breakable)) wallc = Team.all[marker.team].intColor;
wallc = wallc == 0 ? ColorMapper.getBlockColor(floor) : wallc; wallc = wallc == 0 ? ColorMapper.getBlockColor(floor) : wallc;
if(marker.elevation > 0){ if(marker.elevation > 0){
float scaling = 1f + marker.elevation/8f; float scaling = 1f + marker.elevation/8f;

View File

@@ -141,7 +141,7 @@ public class TypeIO {
@ReadClass(Team.class) @ReadClass(Team.class)
public static Team readTeam(ByteBuffer buffer){ public static Team readTeam(ByteBuffer buffer){
return Team.values()[buffer.get()]; return Team.all[buffer.get()];
} }
@WriteClass(AdminAction.class) @WriteClass(AdminAction.class)

View File

@@ -115,9 +115,9 @@ public class Save16 extends SaveFileVersion {
byte team = Bits.getLeftByte(tr); byte team = Bits.getLeftByte(tr);
byte rotation = Bits.getRightByte(tr); byte rotation = Bits.getRightByte(tr);
Team t = Team.values()[team]; Team t = Team.all[team];
tile.setTeam(Team.values()[team]); tile.setTeam(Team.all[team]);
tile.entity.health = health; tile.entity.health = health;
tile.setRotation(rotation); tile.setRotation(rotation);

View File

@@ -176,7 +176,7 @@ public class NetworkIO {
byte tr = stream.readByte(); byte tr = stream.readByte();
short health = stream.readShort(); short health = stream.readShort();
tile.setTeam(Team.values()[Bits.getLeftByte(tr)]); tile.setTeam(Team.all[Bits.getLeftByte(tr)]);
tile.setRotation(Bits.getRightByte(tr)); tile.setRotation(Bits.getRightByte(tr));
tile.entity.health = health; tile.entity.health = health;
@@ -197,7 +197,7 @@ public class NetworkIO {
byte teams = stream.readByte(); byte teams = stream.readByte();
for (int i = 0; i < teams; i++) { for (int i = 0; i < teams; i++) {
Team team = Team.values()[stream.readByte()]; Team team = Team.all[stream.readByte()];
boolean ally = stream.readBoolean(); boolean ally = stream.readBoolean();
short cores = stream.readShort(); short cores = stream.readShort();
state.teams.add(team, ally); state.teams.add(team, ally);

View File

@@ -0,0 +1,23 @@
package io.anuke.mindustry.ui;
import io.anuke.ucore.util.Bundles;
/**A low-garbage way to format bundle strings.*/
public class IntFormat {
private final StringBuilder builder = new StringBuilder();
private final String text;
private int lastValue = Integer.MIN_VALUE;
public IntFormat(String text) {
this.text = text;
}
public CharSequence get(int value){
if(lastValue != value){
builder.setLength(0);
builder.append(Bundles.format(text, value));
}
lastValue = value;
return builder;
}
}

View File

@@ -11,7 +11,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
public class ItemImage extends Stack { public class ItemImage extends Stack {
private Image image; private Image image;
public ItemImage(TextureRegion region, Supplier<String> text, Color color) { public ItemImage(TextureRegion region, Supplier<CharSequence> text, Color color) {
Table t = new Table().left().bottom(); Table t = new Table().left().bottom();
t.label(text).get().setFontScale(0.5f); t.label(text).get().setFontScale(0.5f);

View File

@@ -93,6 +93,10 @@ public class MapsDialog extends FloatingDialog {
i ++; i ++;
} }
if(world.maps().all().size == 0){
maps.add("$text.maps.none");
}
content().add(pane).uniformX(); content().add(pane).uniformX();
} }

View File

@@ -9,10 +9,10 @@ import com.badlogic.gdx.utils.Scaling;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.ui.IntFormat;
import io.anuke.mindustry.ui.Minimap; import io.anuke.mindustry.ui.Minimap;
import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Inputs; import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.scene.Element; import io.anuke.ucore.scene.Element;
import io.anuke.ucore.scene.Group; import io.anuke.ucore.scene.Group;
import io.anuke.ucore.scene.actions.Actions; import io.anuke.ucore.scene.actions.Actions;
@@ -35,10 +35,10 @@ public class HudFragment implements Fragment{
private ImageButton menu, flip; private ImageButton menu, flip;
private Table respawntable; private Table respawntable;
private Table wavetable; private Table wavetable;
private Label infolabel; private Table infolabel;
private Table lastUnlockTable; private Table lastUnlockTable;
private Table lastUnlockLayout; private Table lastUnlockLayout;
private boolean shown = true, done = true; private boolean shown = true;
private float dsize = 58; private float dsize = 58;
private float isize = 40; private float isize = 40;
@@ -109,16 +109,20 @@ public class HudFragment implements Fragment{
row(); row();
visible(() -> !state.is(State.menu)); visible(() -> !state.is(State.menu));
infolabel = new Label(() -> (Settings.getBool("fps") ? (Gdx.graphics.getFramesPerSecond() + " FPS") +
(threads.isEnabled() ? " / " + threads.getFPS() + " TPS" : "") + (Net.client() && !gwt ? "\nPing: " + Net.getPing() : "") : ""));
row(); row();
add(infolabel).size(-1); new table(){{
IntFormat fps = new IntFormat("text.fps");
IntFormat tps = new IntFormat("text.tps");
IntFormat ping = new IntFormat("text.ping");
new label(() -> fps.get(Gdx.graphics.getFramesPerSecond())).padRight(10);
new label(() -> tps.get(threads.getTPS())).visible(() -> threads.isEnabled());
row();
new label(() -> ping.get(Net.getPing())).visible(() -> Net.client() && !gwt).colspan(2);
infolabel = get();
}}.size(-1).end();
}}.end(); }}.end();
}}.end(); }}.end();
new table(){{ new table(){{
@@ -285,25 +289,30 @@ public class HudFragment implements Fragment{
private String getEnemiesRemaining() { private String getEnemiesRemaining() {
if(state.enemies == 1) { if(state.enemies == 1) {
return Bundles.format("text.enemies.single", state.enemies); return Bundles.format("text.enemies.single", state.enemies);
} else return Bundles.format("text.enemies", state.enemies); } else {
return Bundles.format("text.enemies", state.enemies);
}
} }
private void addWaveTable(){ private void addWaveTable(){
float uheight = 66f; float uheight = 66f;
IntFormat wavef = new IntFormat("text.wave");
IntFormat timef = new IntFormat("text.wave.waiting");
wavetable = new table("button"){{ wavetable = new table("button"){{
aleft(); aleft();
new table(){{ new table(){{
aleft(); aleft();
new label(() -> Bundles.format("text.wave", state.wave)).scale(fontScale *1.5f).left().padLeft(-6); new label(() -> wavef.get(state.wave)).scale(fontScale *1.5f).left().padLeft(-6);
row(); row();
new label(()-> state.enemies > 0 ? new label(() -> state.enemies > 0 ?
getEnemiesRemaining() : getEnemiesRemaining() :
(state.mode.disableWaveTimer) ? "$text.waiting" (state.mode.disableWaveTimer) ? "$text.waiting"
: Bundles.format("text.wave.waiting", (int) (state.wavetime / 60f))) : timef.get((int) (state.wavetime / 60f)))
.minWidth(126).padLeft(-6).left(); .minWidth(126).padLeft(-6).left();
margin(10f); margin(10f);

View File

@@ -137,7 +137,7 @@ public class Tile implements PosTrait, TargetTrait {
} }
public Team getTeam(){ public Team getTeam(){
return Team.values()[team]; return Team.all[team];
} }
public byte getTeamID(){ public byte getTeamID(){

View File

@@ -17,7 +17,6 @@ import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Geometry; import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world; import static io.anuke.mindustry.Vars.world;
public class Floor extends Block{ public class Floor extends Block{
@@ -31,6 +30,7 @@ public class Floor extends Block{
protected TextureRegion edgeRegion; protected TextureRegion edgeRegion;
protected TextureRegion[] edgeRegions; protected TextureRegion[] edgeRegions;
protected TextureRegion[] cliffRegions; protected TextureRegion[] cliffRegions;
protected TextureRegion[] variantRegions;
protected Vector2[] offsets; protected Vector2[] offsets;
protected Predicate<Floor> blends = block -> block != this && !block.blendOverride(this); protected Predicate<Floor> blends = block -> block != this && !block.blendOverride(this);
protected boolean blend = true; protected boolean blend = true;
@@ -72,6 +72,7 @@ public class Floor extends Block{
@Override @Override
public void load() { public void load() {
super.load(); super.load();
if(blend) { if(blend) {
edgeRegion = Draw.hasRegion(name + "edge") ? Draw.region(name + "edge") : Draw.region(edge + "edge"); edgeRegion = Draw.hasRegion(name + "edge") ? Draw.region(name + "edge") : Draw.region(edge + "edge");
edgeRegions = new TextureRegion[8]; edgeRegions = new TextureRegion[8];
@@ -97,19 +98,23 @@ public class Floor extends Block{
offsets[i] = new Vector2(-4 + rx, -4 + ry); offsets[i] = new Vector2(-4 + rx, -4 + ry);
} }
if(Draw.hasRegion(name + "-cliff")){ cliffRegions = new TextureRegion[4];
cliffRegions = new TextureRegion[8]; cliffRegions[0] = Draw.region(name + "-cliff-edge-2");
TextureRegion base = Draw.region(name + "-cliff"); cliffRegions[1] = Draw.region(name + "-cliff-edge");
cliffRegions[2] = Draw.region(name + "-cliff-edge-1");
cliffRegions[3] = Draw.region(name + "-cliff-side");
}
for(int i = 0; i < 8; i ++){ //load variant regions for drawing
int dx = Geometry.d8[i].x, dy = Geometry.d8[i].y; if(variants > 0){
variantRegions = new TextureRegion[variants];
TextureRegion region = new TextureRegion(); for (int i = 0; i < variants; i++) {
region.setTexture(base.getTexture()); variantRegions[i] = Draw.region(name + (i + 1));
region.setRegion(base.getRegionX() + tilesize + tilesize*dx, base.getRegionY() + tilesize - tilesize*dy, tilesize, tilesize);
cliffRegions[i] = region;
}
} }
}else{
variantRegions = new TextureRegion[1];
variantRegions[0] = Draw.region(name);
} }
} }
@@ -133,9 +138,9 @@ public class Floor extends Block{
public void draw(Tile tile){ public void draw(Tile tile){
MathUtils.random.setSeed(tile.id()); MathUtils.random.setSeed(tile.id());
Draw.rect(variants > 0 ? (name() + MathUtils.random(1, variants)) : name(), tile.worldx(), tile.worldy()); Draw.rect(variantRegions[Mathf.randomSeed(tile.id(), 0, Math.max(0, variantRegions.length-1))], tile.worldx(), tile.worldy());
if(Draw.hasRegion(name + "-cliff-side") && tile.cliffs != 0){ if(tile.cliffs != 0){
for(int i = 0; i < 4; i ++){ for(int i = 0; i < 4; i ++){
if((tile.cliffs & (1 << i*2)) != 0) { if((tile.cliffs & (1 << i*2)) != 0) {
Draw.colorl(i > 1 ? 0.6f : 1f); Draw.colorl(i > 1 ? 0.6f : 1f);
@@ -143,13 +148,13 @@ public class Floor extends Block{
boolean above = (tile.cliffs & (1 << ((i+1)%4)*2)) != 0, below = (tile.cliffs & (1 << (Mathf.mod(i-1, 4))*2)) != 0; boolean above = (tile.cliffs & (1 << ((i+1)%4)*2)) != 0, below = (tile.cliffs & (1 << (Mathf.mod(i-1, 4))*2)) != 0;
if(above && below){ if(above && below){
Draw.rect(name + "-cliff-edge-2", tile.worldx(), tile.worldy(), i * 90); Draw.rect(cliffRegions[0], tile.worldx(), tile.worldy(), i * 90);
}else if(above){ }else if(above){
Draw.rect(name + "-cliff-edge", tile.worldx(), tile.worldy(), i * 90); Draw.rect(cliffRegions[1], tile.worldx(), tile.worldy(), i * 90);
}else if(below){ }else if(below){
Draw.rect(name + "-cliff-edge-1", tile.worldx(), tile.worldy(), i * 90); Draw.rect(cliffRegions[2], tile.worldx(), tile.worldy(), i * 90);
}else{ }else{
Draw.rect(name + "-cliff-side", tile.worldx(), tile.worldy(), i * 90); Draw.rect(cliffRegions[3], tile.worldx(), tile.worldy(), i * 90);
} }
} }
} }

View File

@@ -6,6 +6,7 @@ import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
public class OreBlock extends Floor { public class OreBlock extends Floor {
public Floor base; public Floor base;
@@ -22,15 +23,7 @@ public class OreBlock extends Floor {
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
Draw.rect(variantRegions[Mathf.randomSeed(tile.id(), 0, Math.max(0, variantRegions.length-1))], tile.worldx(), tile.worldy());
//Draw.rect(base.variants > 0 ? (base.name + MathUtils.random(1, base.variants)) : base.name, tile.worldx(), tile.worldy());
int rand = variants > 0 ? MathUtils.random(1, variants) : 0;
// Draw.color(0f, 0f, 0f, 0.2f);
//Draw.rect(variants > 0 ? (drops.item.name + rand) : name, tile.worldx(), tile.worldy() - 1);
//Draw.color();
Draw.rect(name + rand, tile.worldx(), tile.worldy());
drawEdges(tile, false); drawEdges(tile, false);
} }

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.defense; package io.anuke.mindustry.world.blocks.defense;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import io.anuke.mindustry.content.fx.BlockFx; import io.anuke.mindustry.content.fx.BlockFx;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
@@ -22,13 +23,21 @@ public class Door extends Wall{
protected Effect openfx = BlockFx.dooropen; protected Effect openfx = BlockFx.dooropen;
protected Effect closefx = BlockFx.doorclose; protected Effect closefx = BlockFx.doorclose;
protected TextureRegion openRegion;
public Door(String name) { public Door(String name) {
super(name); super(name);
solid = false; solid = false;
solidifes = true; solidifes = true;
consumesTap = true; consumesTap = true;
} }
@Override
public void load() {
super.load();
openRegion = Draw.region(name + "-open");
}
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
DoorEntity entity = tile.entity(); DoorEntity entity = tile.entity();
@@ -36,7 +45,7 @@ public class Door extends Wall{
if(!entity.open){ if(!entity.open){
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(name, tile.drawx(), tile.drawy());
}else{ }else{
Draw.rect(name + "-open", tile.drawx(), tile.drawy()); Draw.rect(openRegion, tile.drawx(), tile.drawy());
} }
} }

View File

@@ -30,6 +30,8 @@ import static io.anuke.mindustry.Vars.tilesize;
public class MechFactory extends Block{ public class MechFactory extends Block{
protected Mech mech; protected Mech mech;
protected TextureRegion openRegion;
public MechFactory(String name){ public MechFactory(String name){
super(name); super(name);
update = true; update = true;
@@ -51,11 +53,17 @@ public class MechFactory extends Block{
} }
} }
@Override
public void load() {
super.load();
openRegion = Draw.region(name + "-open");
}
@Override @Override
public void draw(Tile tile) { public void draw(Tile tile) {
MechFactoryEntity entity = tile.entity(); MechFactoryEntity entity = tile.entity();
Draw.rect(entity.open ? name + "-open" : name, tile.drawx(), tile.drawy()); Draw.rect(entity.open ? openRegion : Draw.region(name), tile.drawx(), tile.drawy());
if(entity.player != null) { if(entity.player != null) {
TextureRegion region = mech.iconRegion; TextureRegion region = mech.iconRegion;

View File

@@ -47,6 +47,9 @@ public class CoreBlock extends StorageBlock {
protected float droneRespawnDuration = 60*6; protected float droneRespawnDuration = 60*6;
protected UnitType droneType = UnitTypes.drone; protected UnitType droneType = UnitTypes.drone;
protected TextureRegion openRegion;
protected TextureRegion topRegion;
public CoreBlock(String name) { public CoreBlock(String name) {
super(name); super(name);
@@ -61,6 +64,14 @@ public class CoreBlock extends StorageBlock {
flags = EnumSet.of(BlockFlag.resupplyPoint, BlockFlag.target); flags = EnumSet.of(BlockFlag.resupplyPoint, BlockFlag.target);
} }
@Override
public void load() {
super.load();
openRegion = Draw.region(name + "-open");
topRegion = Draw.region(name + "-top");
}
@Override @Override
public float handleDamage(Tile tile, float amount) { public float handleDamage(Tile tile, float amount) {
return debug ? 0 : amount; return debug ? 0 : amount;
@@ -70,10 +81,10 @@ public class CoreBlock extends StorageBlock {
public void draw(Tile tile) { public void draw(Tile tile) {
CoreEntity entity = tile.entity(); CoreEntity entity = tile.entity();
Draw.rect(entity.solid ? name : name + "-open", tile.drawx(), tile.drawy()); Draw.rect(entity.solid ? Draw.region(name) : openRegion, tile.drawx(), tile.drawy());
Draw.alpha(entity.heat); Draw.alpha(entity.heat);
Draw.rect(name + "-top", tile.drawx(), tile.drawy()); Draw.rect(topRegion, tile.drawx(), tile.drawy());
Draw.color(); Draw.color();
if(entity.currentUnit != null) { if(entity.currentUnit != null) {

View File

@@ -33,6 +33,7 @@ public class Reconstructor extends Block{
protected float arriveTime = 40f; protected float arriveTime = 40f;
protected float powerPerTeleport = 5f; protected float powerPerTeleport = 5f;
protected Effect arriveEffect = Fx.spawn; protected Effect arriveEffect = Fx.spawn;
protected TextureRegion openRegion;
public Reconstructor(String name) { public Reconstructor(String name) {
super(name); super(name);
@@ -42,6 +43,12 @@ public class Reconstructor extends Block{
configurable = true; configurable = true;
} }
@Override
public void load() {
super.load();
openRegion = Draw.region(name + "-open");
}
@Override @Override
public boolean isSolidFor(Tile tile) { public boolean isSolidFor(Tile tile) {
ReconstructorEntity entity = tile.entity(); ReconstructorEntity entity = tile.entity();
@@ -104,7 +111,7 @@ public class Reconstructor extends Block{
if(entity.solid){ if(entity.solid){
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(name, tile.drawx(), tile.drawy());
}else{ }else{
Draw.rect(name + "-open", tile.drawx(), tile.drawy()); Draw.rect(openRegion, tile.drawx(), tile.drawy());
} }
if(entity.current != null){ if(entity.current != null){

View File

@@ -53,7 +53,7 @@ public class WorldGenerator {
Tile tile = new Tile(x, y, marker.floor, marker.wall == Blocks.blockpart.id ? 0 : marker.wall, marker.rotation, marker.team, marker.elevation); Tile tile = new Tile(x, y, marker.floor, marker.wall == Blocks.blockpart.id ? 0 : marker.wall, marker.rotation, marker.team, marker.elevation);
Team team = Team.values()[marker.team]; Team team = Team.all[marker.team];
if(tile.block().isMultiblock()){ if(tile.block().isMultiblock()){
multiblocks.add(tile.packedPosition()); multiblocks.add(tile.packedPosition());