diff --git a/core/src/io/anuke/mindustry/UI.java b/core/src/io/anuke/mindustry/UI.java index b2146f64e8..b714ef867c 100644 --- a/core/src/io/anuke/mindustry/UI.java +++ b/core/src/io/anuke/mindustry/UI.java @@ -23,6 +23,8 @@ import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.Blocks; import io.anuke.mindustry.world.blocks.types.Configurable; import io.anuke.ucore.core.*; +import io.anuke.ucore.entities.Entities; +import io.anuke.ucore.function.StringSupplier; import io.anuke.ucore.function.VisibilityProvider; import io.anuke.ucore.modules.SceneModule; import io.anuke.ucore.scene.Element; @@ -499,7 +501,9 @@ public class UI extends SceneModule{ new table(){{ abottom(); aleft(); - new label("[red]DEBUG MODE").scale(0.5f); + new label((StringSupplier)()->"[purple]entities: " + Entities.amount()).left(); + row(); + new label("[red]DEBUG MODE").scale(0.5f).left(); }}.end(); } diff --git a/core/src/io/anuke/mindustry/entities/BulletType.java b/core/src/io/anuke/mindustry/entities/BulletType.java index 19d9d73fdf..878aa49811 100644 --- a/core/src/io/anuke/mindustry/entities/BulletType.java +++ b/core/src/io/anuke/mindustry/entities/BulletType.java @@ -79,6 +79,7 @@ public abstract class BulletType extends BaseBulletType{ Effects.shake(3f, 3f, b); } }, + //TODO use DamageArea instead shell = new BulletType(1.1f, 85){ { lifetime = 110f; diff --git a/core/src/io/anuke/mindustry/entities/TileEntity.java b/core/src/io/anuke/mindustry/entities/TileEntity.java index d0d74b35ac..f1d82d653b 100644 --- a/core/src/io/anuke/mindustry/entities/TileEntity.java +++ b/core/src/io/anuke/mindustry/entities/TileEntity.java @@ -13,6 +13,7 @@ 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; +import io.anuke.mindustry.world.blocks.types.Wall; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.Entity; @@ -23,15 +24,22 @@ public class TileEntity extends Entity{ public ObjectMap items = new ObjectMap<>(); public int maxhealth, health; public boolean dead = false; + public boolean added; - public TileEntity init(Tile tile){ + /**Sets this tile entity data to this tile, and adds it if necessary.*/ + public TileEntity init(Tile tile, boolean added){ this.tile = tile; + this.added = added; x = tile.worldx(); y = tile.worldy(); maxhealth = tile.block().health; health = maxhealth; + if(added){ + add(); + } + return this; } @@ -78,7 +86,7 @@ public class TileEntity extends Entity{ @Override public void update(){ - if(health != 0 && !tile.block().name().contains("block") && + if(health != 0 && !(tile.block() instanceof Wall) && Mathf.chance(0.009f*Timers.delta()*(1f-(float)health/maxhealth))){ Effects.effect("smoke", x+Mathf.range(4), y+Mathf.range(4)); diff --git a/core/src/io/anuke/mindustry/entities/effect/DamageArea.java b/core/src/io/anuke/mindustry/entities/effect/DamageArea.java new file mode 100644 index 0000000000..ffd229c4bb --- /dev/null +++ b/core/src/io/anuke/mindustry/entities/effect/DamageArea.java @@ -0,0 +1,8 @@ +package io.anuke.mindustry.entities.effect; + +import io.anuke.ucore.entities.Entity; + +//TODO +public class DamageArea extends Entity{ + +} diff --git a/core/src/io/anuke/mindustry/entities/effect/EMP.java b/core/src/io/anuke/mindustry/entities/effect/EMP.java index 0be4a1fbb7..339222a2b1 100644 --- a/core/src/io/anuke/mindustry/entities/effect/EMP.java +++ b/core/src/io/anuke/mindustry/entities/effect/EMP.java @@ -38,7 +38,7 @@ public class EMP extends TimedEntity{ if(Vector2.dst(dx, dy, 0, 0) < radius){ Tile tile = World.tile(worldx + dx, worldy + dy); - if(tile != null && tile.block().update/* && tile.block() instanceof PowerAcceptor*/){ + if(tile != null && tile.block().destructible){ array.add(tile); } } diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index e6462f26b9..f68e834dd1 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -4,6 +4,8 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; +import io.anuke.mindustry.GameState; +import io.anuke.mindustry.GameState.State; import io.anuke.mindustry.Vars; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.resource.Item; @@ -12,28 +14,46 @@ import io.anuke.mindustry.resource.Liquid; import io.anuke.ucore.core.Draw; import io.anuke.ucore.core.Effects; import io.anuke.ucore.util.Tmp; - public class Block{ private static int lastid; private static Array blocks = new Array(); protected static TextureRegion temp = new TextureRegion(); + /**internal name*/ public final String name; - public String formalName; - public String explosionEffect = "explosion"; - public String explosionSound = "break"; - public boolean solid, update, rotate, breakable; - public int health = 40; - public String shadow = "shadow"; - public float breaktime = 30; + /**internal ID*/ public final int id; - //edge fallback, used for ores + /**display name*/ + public String formalName; + /**played on destroy*/ + public String explosionEffect = "explosion"; + /**played on destroy*/ + public String explosionSound = "break"; + /**whether this block has a tile entity that updates*/ + public boolean update; + /**whether this block has health and can be destroyed*/ + public boolean destructible; + /**whether this is solid*/ + public boolean solid; + /**whether this is rotateable*/ + public boolean rotate; + /**whether you can break this with rightblick*/ + public boolean breakable; + /**time it takes to break*/ + public float breaktime = 30; + /**tile entity health*/ + public int health = 40; + /**the shadow drawn under the block*/ + public String shadow = "shadow"; + /**edge fallback, used mainly for ores*/ public String edge = "stone"; - //whether to have 3 variants + /**whether this block has 3 variants*/ public boolean vary = true; - //stuff that drops when broken + /**stuff that drops when broken*/ public ItemStack drops = null; + /**liquids that drop from this block, used for pumps*/ public Liquid liquidDrop = null; + /**multiblock width/height*/ public int width = 1, height = 1; public Block(String name) { @@ -181,6 +201,12 @@ public class Block{ Vector2 offset = getPlaceOffset(); Draw.rect(name(), tile.worldx() + offset.x, tile.worldy() + offset.y); } + + //update the tile entity through the draw method, only if it's an entity without updating + //TODO enable + if(destructible && !update && !GameState.is(State.paused)){ + // tile.entity.update(); + } } /**Offset for placing and drawing multiblocks.*/ diff --git a/core/src/io/anuke/mindustry/world/Generator.java b/core/src/io/anuke/mindustry/world/Generator.java index 7ca292ab83..ffacd1996b 100644 --- a/core/src/io/anuke/mindustry/world/Generator.java +++ b/core/src/io/anuke/mindustry/world/Generator.java @@ -93,6 +93,11 @@ public class Generator{ floor = Blocks.stone; } + //preformance debugging + //if(Vector2.dst(pixmap.getWidth()/2, pixmap.getHeight()/2, x, y) < 40){ + // block = DefenseBlocks.stonewall; + //} + World.tile(x, y).setBlock(block); World.tile(x, y).setFloor(floor); diff --git a/core/src/io/anuke/mindustry/world/Tile.java b/core/src/io/anuke/mindustry/world/Tile.java index 95294743a1..ed6352d53b 100644 --- a/core/src/io/anuke/mindustry/world/Tile.java +++ b/core/src/io/anuke/mindustry/world/Tile.java @@ -105,7 +105,7 @@ public class Tile{ } public boolean passable(){ - return isLinked() || !(floor.solid || (block.solid && !block.update)); + return isLinked() || !(floor.solid || (block.solid && (!block.destructible && !block.update))); } public boolean solid(){ @@ -114,7 +114,7 @@ public class Tile{ public boolean breakable(){ if(link == 0){ - return (block.update || block.breakable); + return (block.destructible || block.breakable); }else{ return getLinked().breakable(); } @@ -163,13 +163,14 @@ public class Tile{ } public void changed(){ - if(entity != null){ + if(entity != null && entity.added){ entity.remove(); entity = null; } - if(block.update) - entity = block.getEntity().init(this).add(); + if(block.destructible || block.update){ + entity = block.getEntity().init(this, block.update); + } } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/Blocks.java b/core/src/io/anuke/mindustry/world/blocks/Blocks.java index 2c7a985d44..db40495857 100644 --- a/core/src/io/anuke/mindustry/world/blocks/Blocks.java +++ b/core/src/io/anuke/mindustry/world/blocks/Blocks.java @@ -10,6 +10,7 @@ import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.types.BlockPart; import io.anuke.mindustry.world.blocks.types.Floor; import io.anuke.ucore.core.Effects; +import io.anuke.ucore.core.Timers; import io.anuke.ucore.util.Mathf; public class Blocks{ @@ -49,11 +50,11 @@ public class Blocks{ @Override public void update(Tile tile){ - if(Mathf.chance(0.001)){ + if(Mathf.chance(0.001 * Timers.delta())){ Effects.effect("lava", tile.worldx() + Mathf.range(5f), tile.worldy() + Mathf.range(5f)); } - if(Mathf.chance(0.003)){ + if(Mathf.chance(0.003 * Timers.delta())){ Effects.effect("lavabubble", tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f)); } } @@ -68,7 +69,7 @@ public class Blocks{ @Override public void update(Tile tile){ - if(Mathf.chance(0.0025)){ + if(Mathf.chance(0.0025 * Timers.delta())){ Effects.effect("oilbubble", tile.worldx() + Mathf.range(2f), tile.worldy() + Mathf.range(2f)); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java b/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java index e9d24e158e..a9249b2662 100644 --- a/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java +++ b/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java @@ -16,7 +16,7 @@ public class ProductionBlocks{ { health = 600; solid = true; - update = true; + destructible = true; width = 3; height = 3; } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/Wall.java b/core/src/io/anuke/mindustry/world/blocks/types/Wall.java index d6eaf1ba0f..e2f2afefc7 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/Wall.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/Wall.java @@ -7,7 +7,7 @@ public class Wall extends Block{ public Wall(String name) { super(name); solid = true; - update = true; + destructible = true; } public boolean canReplace(Block other){ diff --git a/core/src/io/anuke/mindustry/world/blocks/types/defense/ShieldedWallBlock.java b/core/src/io/anuke/mindustry/world/blocks/types/defense/ShieldedWallBlock.java index f0c2dce39a..811cfb75be 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/defense/ShieldedWallBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/defense/ShieldedWallBlock.java @@ -17,6 +17,8 @@ public class ShieldedWallBlock extends PowerBlock{ public ShieldedWallBlock(String name) { super(name); + destructible = true; + update = false; voltage = 0.00001f; } diff --git a/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java b/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java index 9eadf7daa9..a66e2a34a1 100644 --- a/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java +++ b/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java @@ -17,7 +17,7 @@ public class DesktopLauncher { Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); config.setTitle("Mindustry"); config.setMaximized(true); - //config.useVsync(false); + config.useVsync(false); config.setWindowedMode(800, 600); config.setWindowIcon("sprites/icon.png"); diff --git a/html/src/io/anuke/mindustry/client/HtmlLauncher.java b/html/src/io/anuke/mindustry/client/HtmlLauncher.java index 5bbc443c58..930e97b0da 100644 --- a/html/src/io/anuke/mindustry/client/HtmlLauncher.java +++ b/html/src/io/anuke/mindustry/client/HtmlLauncher.java @@ -5,12 +5,14 @@ import java.util.Date; import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.backends.gwt.GwtApplication; import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration; +import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback; +import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState; +import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.*; +import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.i18n.shared.DateTimeFormat; -import com.google.gwt.user.client.ui.HasHorizontalAlignment; -import com.google.gwt.user.client.ui.HasVerticalAlignment; -import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.*; import io.anuke.mindustry.Mindustry; import io.anuke.mindustry.io.Formatter; @@ -19,6 +21,37 @@ public class HtmlLauncher extends GwtApplication { static final int WIDTH = 800; static final int HEIGHT = 600; static HtmlLauncher instance; + + @Override + public PreloaderCallback getPreloaderCallback () { + final Panel preloaderPanel = new VerticalPanel(); + preloaderPanel.setStyleName("gdx-preloader"); + final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png"); + logo.setStyleName("logo"); + preloaderPanel.add(logo); + final Panel meterPanel = new SimplePanel(); + meterPanel.setStyleName("gdx-meter"); + meterPanel.addStyleName("red"); + final InlineHTML meter = new InlineHTML(); + final Style meterStyle = meter.getElement().getStyle(); + meterStyle.setWidth(0, Unit.PCT); + meterPanel.add(meter); + preloaderPanel.add(meterPanel); + getRootPanel().add(preloaderPanel); + return new PreloaderCallback() { + + @Override + public void error (String file) { + System.out.println("error: " + file); + } + + @Override + public void update (PreloaderState state) { + meterStyle.setWidth(100f * state.getProgress(), Unit.PCT); + } + + }; + } @Override public GwtApplicationConfiguration getConfig() { diff --git a/html/webapp/html/logo.png b/html/webapp/html/logo.png new file mode 100644 index 0000000000..d8c6598408 Binary files /dev/null and b/html/webapp/html/logo.png differ