Minor optimizations
This commit is contained in:
@@ -5,17 +5,18 @@ import com.badlogic.gdx.Input.Buttons;
|
|||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.input.DefaultKeybinds;
|
|
||||||
import io.anuke.mindustry.game.EventType.*;
|
import io.anuke.mindustry.game.EventType.*;
|
||||||
import io.anuke.mindustry.game.Tutorial;
|
import io.anuke.mindustry.game.Tutorial;
|
||||||
import io.anuke.mindustry.game.UpgradeInventory;
|
import io.anuke.mindustry.game.UpgradeInventory;
|
||||||
import io.anuke.mindustry.graphics.Fx;
|
import io.anuke.mindustry.graphics.Fx;
|
||||||
import io.anuke.mindustry.input.AndroidInput;
|
import io.anuke.mindustry.input.AndroidInput;
|
||||||
|
import io.anuke.mindustry.input.DefaultKeybinds;
|
||||||
import io.anuke.mindustry.input.DesktopInput;
|
import io.anuke.mindustry.input.DesktopInput;
|
||||||
import io.anuke.mindustry.input.InputHandler;
|
import io.anuke.mindustry.input.InputHandler;
|
||||||
import io.anuke.mindustry.io.Platform;
|
import io.anuke.mindustry.io.Platform;
|
||||||
import io.anuke.mindustry.io.Saves;
|
import io.anuke.mindustry.io.Saves;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.mindustry.resource.Weapon;
|
import io.anuke.mindustry.resource.Weapon;
|
||||||
import io.anuke.mindustry.world.Map;
|
import io.anuke.mindustry.world.Map;
|
||||||
import io.anuke.ucore.UCore;
|
import io.anuke.ucore.UCore;
|
||||||
@@ -91,6 +92,10 @@ public class Control extends Module{
|
|||||||
|
|
||||||
Core.atlas = new Atlas("sprites.atlas");
|
Core.atlas = new Atlas("sprites.atlas");
|
||||||
|
|
||||||
|
for(Item item : Item.getAllItems()){
|
||||||
|
item.init();
|
||||||
|
}
|
||||||
|
|
||||||
Sounds.load("shoot.ogg", "place.ogg", "explosion.ogg", "enemyshoot.ogg",
|
Sounds.load("shoot.ogg", "place.ogg", "explosion.ogg", "enemyshoot.ogg",
|
||||||
"corexplode.ogg", "break.ogg", "spawn.ogg", "flame.ogg", "die.ogg",
|
"corexplode.ogg", "break.ogg", "spawn.ogg", "flame.ogg", "die.ogg",
|
||||||
"respawn.ogg", "purchase.ogg", "flame2.ogg", "bigshot.ogg", "laser.ogg", "lasershot.ogg",
|
"respawn.ogg", "purchase.ogg", "flame2.ogg", "bigshot.ogg", "laser.ogg", "lasershot.ogg",
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package io.anuke.mindustry.resource;
|
package io.anuke.mindustry.resource;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.util.Bundles;
|
import io.anuke.ucore.util.Bundles;
|
||||||
|
|
||||||
public class Item{
|
public class Item{
|
||||||
@@ -20,12 +22,17 @@ public class Item{
|
|||||||
|
|
||||||
public final int id;
|
public final int id;
|
||||||
public final String name;
|
public final String name;
|
||||||
|
public TextureRegion region;
|
||||||
|
|
||||||
public Item(String name) {
|
public Item(String name) {
|
||||||
this.id = items.size;
|
this.id = items.size;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
Item.items.add(this);
|
items.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(){
|
||||||
|
this.region = Draw.region("icon-" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String localizedName(){
|
public String localizedName(){
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ public class BlocksFragment implements Fragment{
|
|||||||
desctable.left();
|
desctable.left();
|
||||||
|
|
||||||
for(ItemStack stack : recipe.requirements){
|
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("");
|
Label reqlabel = new Label("");
|
||||||
|
|
||||||
reqlabel.update(()->{
|
reqlabel.update(()->{
|
||||||
|
|||||||
@@ -89,6 +89,9 @@ public class Block{
|
|||||||
/**list of displayed block status bars. Defaults to health bar.*/
|
/**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));
|
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) {
|
public Block(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.formalName = Bundles.get("block." + name + ".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.v1.set(tilesize, 0).rotate(rotation * 90);
|
||||||
Tmp.v2.set(-tilesize / 2, pos.x*tilesize/2).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.x * tilesize + Tmp.v1.x * pos.y + Tmp.v2.x,
|
||||||
tile.y * tilesize + Tmp.v1.y * pos.y + Tmp.v2.y, itemSize, itemSize);
|
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();
|
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);
|
Tmp.tr1.setRegion(region, 4, 4, 1, 1);
|
||||||
|
|
||||||
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 4f, 4f);
|
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 4f, 4f);
|
||||||
@@ -45,7 +45,7 @@ public class Sorter extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
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);
|
Tile to = getTileTarget(item, tile, source, false);
|
||||||
|
|
||||||
return to != null && to.block().acceptItem(item, to, tile);
|
return to != null && to.block().acceptItem(item, to, tile);
|
||||||
@@ -126,7 +126,7 @@ public class Sorter extends Block{
|
|||||||
entity.sortItem = items.get(f);
|
entity.sortItem = items.get(f);
|
||||||
setConfigure(tile, (byte)f);
|
setConfigure(tile, (byte)f);
|
||||||
}).size(38, 42).padBottom(-5.1f).group(group).get();
|
}).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);
|
button.setChecked(entity.sortItem.id == f);
|
||||||
|
|
||||||
if(i%4 == 3){
|
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.resource.Item;
|
||||||
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.core.Timers;
|
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
public class Splitter extends Block{
|
public class Splitter extends Block{
|
||||||
@@ -14,7 +13,7 @@ public class Splitter extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
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);
|
Tile to = getTileTarget(item, tile, source, false);
|
||||||
|
|
||||||
return to != null && to.block().acceptItem(item, to, tile);
|
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){
|
public void handleItem(Item item, Tile tile, Tile source){
|
||||||
Tile to = getTileTarget(item, tile, source, true);
|
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){
|
Tile getTileTarget(Item item, Tile dest, Tile source, boolean flip){
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.NumberUtils;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
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.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
|
import io.anuke.ucore.util.Bits;
|
||||||
|
|
||||||
public class TunnelConveyor extends Block{
|
public class TunnelConveyor extends Block{
|
||||||
protected int maxdist = 3;
|
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 int capacity = 32;
|
||||||
|
|
||||||
protected TunnelConveyor(String name) {
|
protected TunnelConveyor(String name) {
|
||||||
@@ -41,12 +43,14 @@ public class TunnelConveyor extends Block{
|
|||||||
TunnelEntity entity = tile.entity();
|
TunnelEntity entity = tile.entity();
|
||||||
|
|
||||||
if(entity.index > 0){
|
if(entity.index > 0){
|
||||||
entity.time += Timers.delta();
|
long l = entity.buffer[0];
|
||||||
if(entity.time >= speed){
|
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
|
||||||
if(entity.index > entity.buffer.length) entity.index = entity.buffer.length;
|
|
||||||
int i = entity.buffer[entity.index - 1];
|
|
||||||
|
|
||||||
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);
|
Tile tunnel = getDestTunnel(tile, item);
|
||||||
if(tunnel == null) return;
|
if(tunnel == null) return;
|
||||||
@@ -56,12 +60,9 @@ public class TunnelConveyor extends Block{
|
|||||||
if(!target.block().acceptItem(item, target, tunnel)) return;
|
if(!target.block().acceptItem(item, target, tunnel)) return;
|
||||||
|
|
||||||
target.block().handleItem(item, target, tunnel);
|
target.block().handleItem(item, target, tunnel);
|
||||||
|
System.arraycopy(entity.buffer, 1, entity.buffer, 0, entity.index - 1);
|
||||||
entity.index --;
|
entity.index --;
|
||||||
entity.time = 0f;
|
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
entity.time = 0f;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +104,7 @@ public class TunnelConveyor extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TunnelEntity extends TileEntity {
|
class TunnelEntity extends TileEntity {
|
||||||
int[] buffer = new int[capacity];
|
long[] buffer = new long[capacity];
|
||||||
int index;
|
int index;
|
||||||
float time;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class Omnidrill extends Drill {
|
|||||||
if(tile.floor().drops == null) return;
|
if(tile.floor().drops == null) return;
|
||||||
Item item = tile.floor().drops.item;
|
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);
|
Tmp.tr1.setRegion(region, 4, 4, 1, 1);
|
||||||
|
|
||||||
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 2f, 2f);
|
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 2f, 2f);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class WeaponFactory extends Block{
|
|||||||
for(ItemStack s : requirements){
|
for(ItemStack s : requirements){
|
||||||
|
|
||||||
int amount = Math.min(state.inventory.getAmount(s.item), s.amount);
|
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(
|
reqtable.add(
|
||||||
(amount >= s.amount ? "" : "[RED]")
|
(amount >= s.amount ? "" : "[RED]")
|
||||||
+ amount + " / " +s.amount, 0.5f).left();
|
+ amount + " / " +s.amount, 0.5f).left();
|
||||||
|
|||||||
Reference in New Issue
Block a user