From fb5111a4147c8da1f8c9d649f4da091eb35271e8 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 11 Nov 2017 13:03:38 -0500 Subject: [PATCH] Performance improvements for wall blocks --- core/src/io/anuke/mindustry/UI.java | 6 ++- .../anuke/mindustry/entities/BulletType.java | 1 + .../anuke/mindustry/entities/TileEntity.java | 12 ++++- .../mindustry/entities/effect/DamageArea.java | 8 +++ .../anuke/mindustry/entities/effect/EMP.java | 2 +- core/src/io/anuke/mindustry/world/Block.java | 48 ++++++++++++++---- .../io/anuke/mindustry/world/Generator.java | 5 ++ core/src/io/anuke/mindustry/world/Tile.java | 11 ++-- .../anuke/mindustry/world/blocks/Blocks.java | 7 +-- .../world/blocks/ProductionBlocks.java | 2 +- .../mindustry/world/blocks/types/Wall.java | 2 +- .../types/defense/ShieldedWallBlock.java | 2 + .../mindustry/desktop/DesktopLauncher.java | 2 +- .../anuke/mindustry/client/HtmlLauncher.java | 39 ++++++++++++-- html/webapp/html/logo.png | Bin 0 -> 2416 bytes 15 files changed, 118 insertions(+), 29 deletions(-) create mode 100644 core/src/io/anuke/mindustry/entities/effect/DamageArea.java create mode 100644 html/webapp/html/logo.png 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 0000000000000000000000000000000000000000..d8c65984088157e29b1986a1775afda6845caa99 GIT binary patch literal 2416 zcma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