mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-05 15:58:14 +07:00
Performance improvements for wall blocks
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
Effects.shake(3f, 3f, b);
|
||||
}
|
||||
},
|
||||
//TODO use DamageArea instead
|
||||
shell = new BulletType(1.1f, 85){
|
||||
{
|
||||
lifetime = 110f;
|
||||
|
@ -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<Item, Integer> 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));
|
||||
|
@ -0,0 +1,8 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
|
||||
//TODO
|
||||
public class DamageArea extends Entity{
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<Block> blocks = new Array<Block>();
|
||||
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.*/
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class ProductionBlocks{
|
||||
{
|
||||
health = 600;
|
||||
solid = true;
|
||||
update = true;
|
||||
destructible = true;
|
||||
width = 3;
|
||||
height = 3;
|
||||
}
|
||||
|
@ -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){
|
||||
|
@ -17,6 +17,8 @@ public class ShieldedWallBlock extends PowerBlock{
|
||||
|
||||
public ShieldedWallBlock(String name) {
|
||||
super(name);
|
||||
destructible = true;
|
||||
update = false;
|
||||
voltage = 0.00001f;
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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;
|
||||
@ -20,6 +22,37 @@ public class HtmlLauncher extends GwtApplication {
|
||||
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() {
|
||||
GwtApplicationConfiguration config = new GwtApplicationConfiguration(WIDTH, HEIGHT);
|
||||
|
BIN
html/webapp/html/logo.png
Normal file
BIN
html/webapp/html/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
Reference in New Issue
Block a user