Minor optimizations
This commit is contained in:
@@ -5,17 +5,18 @@ import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.input.DefaultKeybinds;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.Tutorial;
|
||||
import io.anuke.mindustry.game.UpgradeInventory;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.input.AndroidInput;
|
||||
import io.anuke.mindustry.input.DefaultKeybinds;
|
||||
import io.anuke.mindustry.input.DesktopInput;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
import io.anuke.mindustry.io.Platform;
|
||||
import io.anuke.mindustry.io.Saves;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Map;
|
||||
import io.anuke.ucore.UCore;
|
||||
@@ -90,6 +91,10 @@ public class Control extends Module{
|
||||
Effects.setShakeFalloff(10000f);
|
||||
|
||||
Core.atlas = new Atlas("sprites.atlas");
|
||||
|
||||
for(Item item : Item.getAllItems()){
|
||||
item.init();
|
||||
}
|
||||
|
||||
Sounds.load("shoot.ogg", "place.ogg", "explosion.ogg", "enemyshoot.ogg",
|
||||
"corexplode.ogg", "break.ogg", "spawn.ogg", "flame.ogg", "die.ogg",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.anuke.mindustry.resource;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
public class Item{
|
||||
@@ -20,12 +22,17 @@ public class Item{
|
||||
|
||||
public final int id;
|
||||
public final String name;
|
||||
public TextureRegion region;
|
||||
|
||||
public Item(String name) {
|
||||
this.id = items.size;
|
||||
this.name = name;
|
||||
|
||||
Item.items.add(this);
|
||||
items.add(this);
|
||||
}
|
||||
|
||||
public void init(){
|
||||
this.region = Draw.region("icon-" + name);
|
||||
}
|
||||
|
||||
public String localizedName(){
|
||||
|
||||
@@ -29,7 +29,7 @@ public class BlocksFragment implements Fragment{
|
||||
private Stack stack = new Stack();
|
||||
private Array<String> statlist = new Array<>();
|
||||
private boolean shown = true;
|
||||
|
||||
|
||||
public void build(){
|
||||
InputHandler input = control.input();
|
||||
|
||||
@@ -193,63 +193,63 @@ public class BlocksFragment implements Fragment{
|
||||
blocks.actions(Actions.translateBy(0, -blocks.getTranslation().y, t, ip));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void updateRecipe(){
|
||||
Recipe recipe = control.input().recipe;
|
||||
desctable.clear();
|
||||
desctable.setTouchable(Touchable.enabled);
|
||||
|
||||
|
||||
desctable.defaults().left();
|
||||
desctable.left();
|
||||
desctable.margin(12);
|
||||
|
||||
|
||||
Table header = new Table();
|
||||
|
||||
|
||||
desctable.add(header).left();
|
||||
|
||||
|
||||
desctable.row();
|
||||
|
||||
TextureRegion region = Draw.hasRegion(recipe.result.name() + "-icon") ?
|
||||
|
||||
TextureRegion region = Draw.hasRegion(recipe.result.name() + "-icon") ?
|
||||
Draw.region(recipe.result.name() + "-icon") : Draw.region(recipe.result.name());
|
||||
|
||||
|
||||
header.addImage(region).size(8*5).padTop(4);
|
||||
Label nameLabel = new Label(recipe.result.formalName);
|
||||
nameLabel.setWrap(true);
|
||||
header.add(nameLabel).padLeft(2).width(120f);
|
||||
|
||||
|
||||
//extra info
|
||||
if(recipe.result.fullDescription != null){
|
||||
header.addButton("?", () -> showBlockInfo(recipe.result)).expandX().padLeft(3).top().right().size(40f, 44f).padTop(-2);
|
||||
}
|
||||
|
||||
|
||||
desctable.add().pad(2);
|
||||
|
||||
|
||||
Table requirements = new Table();
|
||||
|
||||
|
||||
desctable.row();
|
||||
|
||||
|
||||
desctable.add(requirements);
|
||||
desctable.left();
|
||||
|
||||
|
||||
for(ItemStack stack : recipe.requirements){
|
||||
requirements.addImage(Draw.region("icon-"+stack.item.name)).size(8*3);
|
||||
requirements.addImage(stack.item.region).size(8*3);
|
||||
Label reqlabel = new Label("");
|
||||
|
||||
|
||||
reqlabel.update(()->{
|
||||
int current = state.inventory.getAmount(stack.item);
|
||||
String text = Mathf.clamp(current, 0, stack.amount) + "/" + stack.amount;
|
||||
|
||||
|
||||
reqlabel.setColor(current < stack.amount ? Colors.get("missingitems") : Color.WHITE);
|
||||
|
||||
|
||||
reqlabel.setText(text);
|
||||
});
|
||||
|
||||
|
||||
requirements.add(reqlabel).left();
|
||||
requirements.row();
|
||||
}
|
||||
|
||||
|
||||
desctable.row();
|
||||
|
||||
|
||||
Label label = new Label("[health]"+ Bundles.get("text.health")+": " + recipe.result.health);
|
||||
label.setWrap(true);
|
||||
desctable.add(label).width(200).padTop(4).padBottom(2);
|
||||
|
||||
@@ -89,6 +89,9 @@ public class Block{
|
||||
/**list of displayed block status bars. Defaults to health bar.*/
|
||||
public Array<BlockBar> bars = Array.with(new BlockBar(Color.RED, false, tile -> tile.entity.health / (float)tile.block().health));
|
||||
|
||||
/**texture info*/
|
||||
TextureRegion[] regions;
|
||||
|
||||
public Block(String name) {
|
||||
this.name = name;
|
||||
this.formalName = Bundles.get("block." + name + ".name", name);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class Conveyor extends Block{
|
||||
Tmp.v1.set(tilesize, 0).rotate(rotation * 90);
|
||||
Tmp.v2.set(-tilesize / 2, pos.x*tilesize/2).rotate(rotation * 90);
|
||||
|
||||
Draw.rect("icon-" + pos.item.name,
|
||||
Draw.rect(pos.item.region,
|
||||
tile.x * tilesize + Tmp.v1.x * pos.y + Tmp.v2.x,
|
||||
tile.y * tilesize + Tmp.v1.y * pos.y + Tmp.v2.y, itemSize, itemSize);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Sorter extends Block{
|
||||
|
||||
SorterEntity entity = tile.entity();
|
||||
|
||||
TextureRegion region = Draw.region("icon-" + entity.sortItem.name);
|
||||
TextureRegion region = entity.sortItem.region;
|
||||
Tmp.tr1.setRegion(region, 4, 4, 1, 1);
|
||||
|
||||
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 4f, 4f);
|
||||
@@ -45,7 +45,7 @@ public class Sorter extends Block{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
if(source.block() instanceof Sorter) return false;
|
||||
if(source.block() instanceof Sorter || source.block() instanceof Splitter) return false;
|
||||
Tile to = getTileTarget(item, tile, source, false);
|
||||
|
||||
return to != null && to.block().acceptItem(item, to, tile);
|
||||
@@ -126,7 +126,7 @@ public class Sorter extends Block{
|
||||
entity.sortItem = items.get(f);
|
||||
setConfigure(tile, (byte)f);
|
||||
}).size(38, 42).padBottom(-5.1f).group(group).get();
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(new TextureRegion(Draw.region("icon-"+items.get(i).name)));
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(new TextureRegion(items.get(i).region));
|
||||
button.setChecked(entity.sortItem.id == f);
|
||||
|
||||
if(i%4 == 3){
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Splitter extends Block{
|
||||
@@ -14,7 +13,7 @@ public class Splitter extends Block{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
if(source.block() instanceof Sorter) return false;
|
||||
if(source.block() instanceof Sorter || source.block() instanceof Splitter) return false;
|
||||
Tile to = getTileTarget(item, tile, source, false);
|
||||
|
||||
return to != null && to.block().acceptItem(item, to, tile);
|
||||
@@ -24,9 +23,7 @@ public class Splitter extends Block{
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
Tile to = getTileTarget(item, tile, source, true);
|
||||
|
||||
Timers.run(15, () -> {
|
||||
to.block().handleItem(item, to, tile);
|
||||
});
|
||||
to.block().handleItem(item, to, tile);
|
||||
}
|
||||
|
||||
Tile getTileTarget(Item item, Tile dest, Tile source, boolean flip){
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import com.badlogic.gdx.utils.NumberUtils;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
|
||||
public class TunnelConveyor extends Block{
|
||||
protected int maxdist = 3;
|
||||
protected float speed = 12; //frames taken to go through this tunnel
|
||||
protected float speed = 50; //frames taken to go through this tunnel
|
||||
protected int capacity = 32;
|
||||
|
||||
protected TunnelConveyor(String name) {
|
||||
@@ -41,12 +43,14 @@ public class TunnelConveyor extends Block{
|
||||
TunnelEntity entity = tile.entity();
|
||||
|
||||
if(entity.index > 0){
|
||||
entity.time += Timers.delta();
|
||||
if(entity.time >= speed){
|
||||
if(entity.index > entity.buffer.length) entity.index = entity.buffer.length;
|
||||
int i = entity.buffer[entity.index - 1];
|
||||
long l = entity.buffer[0];
|
||||
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
|
||||
|
||||
Item item = Item.getByID(i);
|
||||
if(Timers.time() >= time + speed){
|
||||
|
||||
int val = Bits.getRightInt(l);
|
||||
|
||||
Item item = Item.getByID(Bits.getLeftShort(val));
|
||||
|
||||
Tile tunnel = getDestTunnel(tile, item);
|
||||
if(tunnel == null) return;
|
||||
@@ -56,12 +60,9 @@ public class TunnelConveyor extends Block{
|
||||
if(!target.block().acceptItem(item, target, tunnel)) return;
|
||||
|
||||
target.block().handleItem(item, target, tunnel);
|
||||
|
||||
System.arraycopy(entity.buffer, 1, entity.buffer, 0, entity.index - 1);
|
||||
entity.index --;
|
||||
entity.time = 0f;
|
||||
}
|
||||
}else{
|
||||
entity.time = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +104,7 @@ public class TunnelConveyor extends Block{
|
||||
}
|
||||
|
||||
class TunnelEntity extends TileEntity {
|
||||
int[] buffer = new int[capacity];
|
||||
long[] buffer = new long[capacity];
|
||||
int index;
|
||||
float time;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Omnidrill extends Drill {
|
||||
if(tile.floor().drops == null) return;
|
||||
Item item = tile.floor().drops.item;
|
||||
|
||||
TextureRegion region = Draw.region("icon-" + item.name);
|
||||
TextureRegion region = item.region;
|
||||
Tmp.tr1.setRegion(region, 4, 4, 1, 1);
|
||||
|
||||
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 2f, 2f);
|
||||
|
||||
@@ -63,7 +63,7 @@ public class WeaponFactory extends Block{
|
||||
for(ItemStack s : requirements){
|
||||
|
||||
int amount = Math.min(state.inventory.getAmount(s.item), s.amount);
|
||||
reqtable.addImage(Draw.region("icon-" + s.item.name)).padRight(3).size(8*2);
|
||||
reqtable.addImage(s.item.region).padRight(3).size(8*2);
|
||||
reqtable.add(
|
||||
(amount >= s.amount ? "" : "[RED]")
|
||||
+ amount + " / " +s.amount, 0.5f).left();
|
||||
|
||||
Reference in New Issue
Block a user