Cleaned up UI, merged atlases, added GLProfiling
This commit is contained in:
@@ -2,6 +2,7 @@ package io.anuke.mindustry;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.badlogic.gdx.graphics.profiling.GLProfiler;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.GameState.State;
|
||||
@@ -31,6 +32,9 @@ public class Mindustry extends ModuleCore {
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
//if(Vars.debug){
|
||||
GLProfiler.enable();
|
||||
//}
|
||||
//always initialize blocks in this order, otherwise there are ID errors
|
||||
Blocks.dirt.getClass();
|
||||
ProductionBlocks.coaldrill.getClass();
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.profiling.GLProfiler;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
@@ -20,6 +21,7 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.World;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.entities.DestructibleEntity;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
@@ -109,6 +111,13 @@ public class Renderer extends RendererModule{
|
||||
}
|
||||
|
||||
drawDefault();
|
||||
|
||||
if(Vars.debug && Timers.get("profile", 30)){
|
||||
UCore.log("shaders: " + GLProfiler.shaderSwitches,
|
||||
"calls: " + GLProfiler.drawCalls,
|
||||
"bindings: " + GLProfiler.textureBindings,
|
||||
"vertices: " + GLProfiler.vertexCount.average);
|
||||
}
|
||||
|
||||
camera.position.set(lastx - deltax, lasty - deltay, 0);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.anuke.mindustry.world.Map;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.function.VisibilityProvider;
|
||||
import io.anuke.ucore.modules.SceneModule;
|
||||
import io.anuke.ucore.scene.Skin;
|
||||
import io.anuke.ucore.scene.actions.Actions;
|
||||
import io.anuke.ucore.scene.builders.*;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
@@ -72,6 +73,10 @@ public class UI extends SceneModule{
|
||||
Colors.put("health", Color.YELLOW);
|
||||
}
|
||||
|
||||
protected void loadSkin(){
|
||||
skin = new Skin(Gdx.files.internal("ui/uiskin.json"), Core.atlas);
|
||||
}
|
||||
|
||||
void drawBackground(){
|
||||
int w = (int)screen.x;
|
||||
int h = (int)screen.y;
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||
@@ -57,7 +58,10 @@ public class TileEntity extends Entity{
|
||||
}
|
||||
|
||||
public void collision(Bullet other){
|
||||
health -= other.getDamage();
|
||||
Block block = tile.block();
|
||||
|
||||
int amount = block.handleDamage(tile, other.getDamage());
|
||||
health -= amount;
|
||||
if(health <= 0) onDeath();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.ShieldBlock;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.entities.BulletEntity;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
|
||||
public class Shield extends Entity{
|
||||
@@ -27,29 +29,39 @@ public class Shield extends Entity{
|
||||
public void update(){
|
||||
if(!(tile.block() instanceof ShieldBlock)){
|
||||
remove();
|
||||
return;
|
||||
}
|
||||
|
||||
ShieldBlock block = (ShieldBlock)tile.block();
|
||||
|
||||
Entities.getNearby(x, y, block.shieldRadius * 2 + 10, entity->{
|
||||
if(entity instanceof BulletEntity){
|
||||
BulletEntity bullet = (BulletEntity)entity;
|
||||
|
||||
float dst = entity.distanceTo(this);
|
||||
|
||||
if(Math.abs(dst - block.shieldRadius) < 2){
|
||||
bullet.velocity.scl(-1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
if(!(tile.block() instanceof ShieldBlock)){
|
||||
return;
|
||||
}
|
||||
|
||||
ShieldBlock block = (ShieldBlock)tile.block();
|
||||
|
||||
Graphics.surface("shield", false);
|
||||
Draw.color(Color.ROYAL);
|
||||
Draw.thick(2f);
|
||||
Draw.rect("circle2", (int)x + 0.5f, (int)y + 0.5f, 102f, 102f);
|
||||
Draw.rect("circle2", x, y, block.shieldRadius*2, block.shieldRadius*2);
|
||||
Draw.reset();
|
||||
Graphics.surface();
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public void drawOver(){
|
||||
Graphics.surface("shield", false);
|
||||
Draw.thick(1f);
|
||||
Draw.color(Color.SKY);
|
||||
Draw.circle(x, y, ((Timers.time() + 50f) % 100f) / 2f);
|
||||
Draw.circle(x, y, (Timers.time() % 100f) / 2f);
|
||||
Draw.reset();
|
||||
Graphics.surface();
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void added(){
|
||||
|
||||
@@ -16,6 +16,7 @@ public enum Recipe{
|
||||
titaniumwall(distribution, Blocks.titaniumwall, stack(Item.titanium, 2)),
|
||||
duriumwall(distribution, Blocks.diriumwall, stack(Item.dirium, 2)),
|
||||
compositewall(distribution, Blocks.compositewall, stack(Item.dirium, 2), stack(Item.titanium, 2), stack(Item.steel, 2), stack(Item.iron, 2)),
|
||||
titaniumshieldwall(distribution, Blocks.titaniumshieldwall, stack(Item.titanium, 2)),
|
||||
conveyor(distribution, ProductionBlocks.conveyor, stack(Item.stone, 1)),
|
||||
fastconveyor(distribution, ProductionBlocks.steelconveyor, stack(Item.steel, 1)),
|
||||
router(distribution, ProductionBlocks.router, stack(Item.stone, 2)),
|
||||
|
||||
@@ -60,6 +60,10 @@ public class Block{
|
||||
public boolean canReplace(Block other){
|
||||
return false;
|
||||
}
|
||||
|
||||
public int handleDamage(Tile tile, int amount){
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void handleItem(Tile tile, Item item, Tile source){
|
||||
tile.entity.addItem(item, 1);
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.mindustry.world.blocks.types.ShieldedWallBlock;
|
||||
import io.anuke.mindustry.world.blocks.types.Wall;
|
||||
|
||||
public class Blocks{
|
||||
@@ -123,5 +124,9 @@ public class Blocks{
|
||||
compositewall = new Wall("compositewall"){{
|
||||
health = 270;
|
||||
formalName = "composite wall";
|
||||
}},
|
||||
titaniumshieldwall = new ShieldedWallBlock("titaniumshieldwall"){{
|
||||
health = 150;
|
||||
formalName = "shielded wall";
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -14,11 +14,16 @@ public class ProductionBlocks{
|
||||
|
||||
core = new Block("core"){
|
||||
{
|
||||
health = Vars.debug ? 999999999 : 300;
|
||||
health = 300;
|
||||
solid = true;
|
||||
update = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int handleDamage(Tile tile, int amount){
|
||||
return Vars.debug ? 0 : amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Tile tile, Item item, Tile source){
|
||||
Vars.control.addItem(item, 1);
|
||||
|
||||
@@ -11,7 +11,7 @@ public class Generator extends PowerBlock{
|
||||
public static final int powerTime = 8;
|
||||
|
||||
public int powerRange = 6;
|
||||
public float powerSpeed = 1f;
|
||||
public float powerSpeed = 0.15f;
|
||||
|
||||
public Generator(String name) {
|
||||
super(name);
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.anuke.mindustry.world.blocks.types;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Shield;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class ShieldBlock extends PowerBlock{
|
||||
public float shieldRadius = 40f;
|
||||
@@ -11,36 +12,34 @@ public class ShieldBlock extends PowerBlock{
|
||||
public ShieldBlock(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
ShieldEntity entity = tile.entity();
|
||||
|
||||
|
||||
if(entity.shield == null){
|
||||
entity.shield = new Shield(tile);
|
||||
entity.shield.add();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
if(entity.power > powerDrain * Timers.delta()){
|
||||
if(!entity.shield.active){
|
||||
entity.shield.add();
|
||||
}
|
||||
|
||||
|
||||
entity.power -= powerDrain * Timers.delta();
|
||||
}else{
|
||||
if(entity.shield.active){
|
||||
entity.shield.remove();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity(){
|
||||
return new ShieldEntity();
|
||||
}
|
||||
|
||||
|
||||
static class ShieldEntity extends PowerEntity{
|
||||
Shield shield;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class ShieldedWallBlock extends PowerBlock{
|
||||
static final float hitTime = 18f;
|
||||
static final Color hitColor = Color.SKY.cpy().mul(1.2f);
|
||||
public float powerToDamage = 0.1f;
|
||||
|
||||
public ShieldedWallBlock(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int handleDamage(Tile tile, int amount){
|
||||
float drain = amount * powerToDamage;
|
||||
ShieldedWallEntity entity = tile.entity();
|
||||
|
||||
if(entity.power > drain){
|
||||
entity.power -= drain;
|
||||
entity.hit = hitTime;
|
||||
return 0;
|
||||
}else if(entity.power > 0){
|
||||
int reduction = (int)(entity.power / powerToDamage);
|
||||
entity.power = 0;
|
||||
|
||||
return amount - reduction;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
ShieldedWallEntity entity = tile.entity();
|
||||
|
||||
if(entity.power > powerToDamage){
|
||||
Graphics.surface("shield", false);
|
||||
Draw.color(Color.ROYAL);
|
||||
Draw.rect("blank", tile.worldx(), tile.worldy(), Vars.tilesize, Vars.tilesize);
|
||||
Graphics.surface();
|
||||
}
|
||||
|
||||
Draw.color(hitColor);
|
||||
Draw.alpha(entity.hit / hitTime * 0.9f);
|
||||
Draw.rect("blank", tile.worldx(), tile.worldy(), Vars.tilesize, Vars.tilesize);
|
||||
Draw.reset();
|
||||
|
||||
entity.hit -= Timers.delta();
|
||||
entity.hit = Math.max(entity.hit, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity(){
|
||||
return new ShieldedWallEntity();
|
||||
}
|
||||
|
||||
static class ShieldedWallEntity extends PowerEntity{
|
||||
public float hit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user