diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index 3727a9044a..593598b99e 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -338,7 +338,7 @@ public class Renderer extends RendererModule{ Tile tile = ui.configfrag.getSelectedTile(); Draw.color(Colors.get("accent")); Lines.stroke(1f); - Lines.square(tile.worldx() + tile.block().getPlaceOffset().x, tile.worldy() + tile.block().getPlaceOffset().y, + Lines.square(tile.drawx(), tile.drawy(), tile.block().width * Vars.tilesize / 2f + 1f); Draw.reset(); } @@ -390,10 +390,8 @@ public class Renderer extends RendererModule{ if(tile.isLinked()) target = tile.getLinked(); - Vector2 offset = target.block().getPlaceOffset(); - if(target.entity != null) - drawHealth(target.entity.x + offset.x, target.entity.y - 3f - target.block().height / 2f * Vars.tilesize + offset.y, target.entity.health, target.entity.maxhealth); + drawHealth(target.drawx(), target.drawy() - 3f - target.block().height / 2f * Vars.tilesize, target.entity.health, target.entity.maxhealth); target.block().drawSelect(target); } diff --git a/core/src/io/anuke/mindustry/input/PlaceMode.java b/core/src/io/anuke/mindustry/input/PlaceMode.java index 5f8ad129b3..a7806eff7e 100644 --- a/core/src/io/anuke/mindustry/input/PlaceMode.java +++ b/core/src/io/anuke/mindustry/input/PlaceMode.java @@ -92,12 +92,11 @@ public enum PlaceMode{ if(tile != null && control.getInput().validBreak(tilex, tiley)){ if(tile.isLinked()) tile = tile.getLinked(); - Vector2 offset = tile.block().getPlaceOffset(); float fract = control.getInput().breaktime / tile.getBreakTime(); if(android && control.getInput().breaktime > 0){ Draw.color(Colors.get("breakStart"), Colors.get("break"), fract); - Lines.poly(tile.worldx() + offset.x, tile.worldy() + offset.y, 25, 4 + (1f - fract) * 26); + Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fract) * 26); } Draw.reset(); } @@ -157,8 +156,7 @@ public enum PlaceMode{ if(tile != null && tile.getLinked() != null) tile = tile.getLinked(); if(tile != null && control.getInput().validBreak(tile.x, tile.y)){ - Vector2 offset = tile.block().getPlaceOffset(); - Lines.crect(tile.worldx() + offset.x, tile.worldy() + offset.y, + Lines.crect(tile.drawx(), tile.drawy(), tile.block().width * t, tile.block().height * t); } } diff --git a/core/src/io/anuke/mindustry/net/Net.java b/core/src/io/anuke/mindustry/net/Net.java index f7f663c910..4dc73ae8e5 100644 --- a/core/src/io/anuke/mindustry/net/Net.java +++ b/core/src/io/anuke/mindustry/net/Net.java @@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.IntMap; import com.badlogic.gdx.utils.ObjectMap; -import com.badlogic.gdx.utils.async.AsyncExecutor; import io.anuke.mindustry.Mindustry; import io.anuke.mindustry.net.Packet.ImportantPacket; import io.anuke.mindustry.net.Packets.KickReason; @@ -30,7 +29,6 @@ public class Net{ private static ServerProvider serverProvider; private static IntMap streams = new IntMap<>(); - private static AsyncExecutor executor = new AsyncExecutor(4); /**Sets the client loaded status, or whether it will recieve normal packets from the server.*/ public static void setClientLoaded(boolean loaded){ @@ -71,13 +69,7 @@ public class Net{ /**Starts discovering servers on a different thread. Does not work with GWT. * Callback is run on the main libGDX thread.*/ public static void discoverServers(Consumer> cons){ - executor.submit(() -> { - Array arr = clientProvider.discover(); - Gdx.app.postRunnable(() -> { - cons.accept(arr); - }); - return false; - }); + clientProvider.discover(cons); } /**Kick a specified connection from the server.*/ @@ -203,13 +195,8 @@ public class Net{ public static void dispose(){ if(clientProvider != null) clientProvider.dispose(); if(serverProvider != null) serverProvider.dispose(); - executor.dispose(); - } - - /**Register classes that will be sent. Must be done for all classes.*/ - public static void registerClasses(Class... classes){ - clientProvider.register(classes); - serverProvider.register(classes); + clientProvider = null; + serverProvider = null; } /**Client implementation.*/ @@ -224,12 +211,11 @@ public class Net{ int getPing(); /**Disconnect from the server.*/ void disconnect(); - /**Discover servers. This should block for a certain amount of time, and will most likely be run in a different thread.*/ - Array discover(); + /**Discover servers. This should run the callback regardless of whether any servers are found. Should not block. + * Callback should be run on libGDX main thread.*/ + void discover(Consumer> callback); /**Ping a host. If an error occured, failed() should be called with the exception. */ void pingHost(String address, int port, Consumer valid, Consumer failed); - /**Register classes to be sent.*/ - void register(Class... types); /**Close all connections.*/ void dispose(); } @@ -254,8 +240,6 @@ public class Net{ void kick(int connection, KickReason reason); /**Returns the ping for a certain connection.*/ int getPingFor(NetConnection connection); - /**Register classes to be sent.*/ - void register(Class... types); /**Close all connections.*/ void dispose(); } diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlockConfigFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlockConfigFragment.java index 76c0ca49ab..d9e76f04a3 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BlockConfigFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BlockConfigFragment.java @@ -42,7 +42,7 @@ public class BlockConfigFragment implements Fragment { table.update(()->{ table.setOrigin(Align.center); - Vector2 pos = Graphics.screen(tile.worldx() + tile.block().getPlaceOffset().x, tile.worldy() + tile.block().getPlaceOffset().y); + Vector2 pos = Graphics.screen(tile.drawx(), tile.drawy()); table.setPosition(pos.x, pos.y, Align.center); if(configTile == null || configTile.block() == Blocks.air){ hideConfig(); diff --git a/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java b/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java index 5381ce95f1..140b088f63 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java @@ -95,7 +95,7 @@ public class HudFragment implements Fragment{ visible(() -> !GameState.is(State.menu)); Label fps = new Label(() -> (Settings.getBool("fps") ? (Gdx.graphics.getFramesPerSecond() + " FPS") + - (Net.active() ? " / Ping: " + Net.getPing() : "") : "")); + (Net.active() && !Vars.gwt ? " / Ping: " + Net.getPing() : "") : "")); row(); add(fps).size(-1); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index cd3988893d..893622b187 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -245,9 +245,7 @@ public class Block{ tile.worldx(), tile.worldy(), rotate ? tile.getRotation() * 90 : 0); }else{ //if multiblock, make sure to draw even block sizes offset, since the core block is at the BOTTOM LEFT - Vector2 offset = getPlaceOffset(); - - Draw.rect(name(), tile.worldx() + offset.x, tile.worldy() + offset.y); + Draw.rect(name(), tile.drawx(), tile.drawy()); } //update the tile entity through the draw method, only if it's an entity without updating diff --git a/core/src/io/anuke/mindustry/world/Tile.java b/core/src/io/anuke/mindustry/world/Tile.java index 89326ca590..1bf628b514 100644 --- a/core/src/io/anuke/mindustry/world/Tile.java +++ b/core/src/io/anuke/mindustry/world/Tile.java @@ -96,6 +96,14 @@ public class Tile{ public float worldy(){ return y * tilesize; } + + public float drawx(){ + return block().getPlaceOffset().x + worldx(); + } + + public float drawy(){ + return block().getPlaceOffset().y + worldy(); + } public Block floor(){ return Block.getByID(getFloorID()); diff --git a/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java b/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java index c65c074ea0..4361571f87 100644 --- a/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java +++ b/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java @@ -1,8 +1,6 @@ package io.anuke.mindustry.world.blocks; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.math.Vector2; - import io.anuke.mindustry.Vars; import io.anuke.mindustry.entities.BulletType; import io.anuke.mindustry.entities.effect.TeslaOrb; @@ -177,7 +175,6 @@ public class WeaponBlocks{ @Override protected void shoot(Tile tile){ TurretEntity entity = tile.entity(); - Vector2 offset = getPlaceOffset(); float len = 8; float space = 3.5f; @@ -185,8 +182,8 @@ public class WeaponBlocks{ for(int i = -1; i < 1; i ++){ Angles.vector.set(len, Mathf.sign(i) * space).rotate(entity.rotation); bullet(tile, entity.rotation); - Effects.effect(shootEffect, tile.worldx() + Angles.x() + offset.x, - tile.worldy()+ Angles.y() + offset.y, entity.rotation); + Effects.effect(shootEffect, tile.drawx() + Angles.x(), + tile.drawy()+ Angles.y(), entity.rotation); } Effects.shake(1f, 1f, tile.worldx(), tile.worldy()); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/PowerBlock.java b/core/src/io/anuke/mindustry/world/blocks/types/PowerBlock.java index 3ab9e0d569..558cde9c3a 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/PowerBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/PowerBlock.java @@ -1,19 +1,17 @@ package io.anuke.mindustry.world.blocks.types; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; - import io.anuke.mindustry.Vars; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.ucore.util.Mathf; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + public abstract class PowerBlock extends Block implements PowerAcceptor{ public float powerCapacity = 10f; public float voltage = 0.001f; @@ -38,10 +36,8 @@ public abstract class PowerBlock extends Block implements PowerAcceptor{ if(fract > 0) fract = Mathf.clamp(fract + 0.2f, 0.24f, 1f); - Vector2 offset = getPlaceOffset(); - - Vars.renderer.drawBar(Color.YELLOW, tile.worldx() + offset.x, - tile.worldy() + Vars.tilesize * height/2f + 2 + offset.y, fract); + Vars.renderer.drawBar(Color.YELLOW, tile.drawx(), + tile.drawy() + Vars.tilesize * height/2f + 2, fract); } /**Tries adding all the power with no remainder, returns success.*/ diff --git a/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java b/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java index eef852e446..4d370c8240 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java @@ -1,18 +1,17 @@ package io.anuke.mindustry.world.blocks.types.defense; import com.badlogic.gdx.math.Rectangle; -import com.badlogic.gdx.math.Vector2; import io.anuke.mindustry.Vars; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.types.Wall; -import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects.Effect; import io.anuke.ucore.entities.Entities; import io.anuke.ucore.entities.SolidEntity; +import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.util.Tmp; import java.io.DataInputStream; @@ -36,12 +35,10 @@ public class Door extends Wall{ public void draw(Tile tile){ DoorEntity entity = tile.entity(); - Vector2 offset = getPlaceOffset(); - if(!entity.open){ - Draw.rect(name, tile.worldx() + offset.x, tile.worldy() + offset.y); + Draw.rect(name, tile.drawx(), tile.drawy()); }else{ - Draw.rect(name + "-open", tile.worldx() + offset.x, tile.worldy() + offset.y); + Draw.rect(name + "-open", tile.drawx(), tile.drawy()); } } @@ -59,13 +56,11 @@ public class Door extends Wall{ return; } - Vector2 offset = getPlaceOffset(); - entity.open = !entity.open; if(!entity.open){ - Effects.effect(closefx, tile.worldx() + offset.x, tile.worldy() + offset.y); + Effects.effect(closefx, tile.drawx(), tile.drawy()); }else{ - Effects.effect(openfx, tile.worldx() + offset.x, tile.worldy() + offset.y); + Effects.effect(openfx, tile.drawx(), tile.drawy()); } } @@ -73,8 +68,7 @@ public class Door extends Wall{ int x = tile.x, y = tile.y; Block type = tile.block(); Tmp.r2.setSize(type.width * Vars.tilesize, type.height * Vars.tilesize); - Vector2 offset = type.getPlaceOffset(); - Tmp.r2.setCenter(offset.x + x * Vars.tilesize, offset.y + y * Vars.tilesize); + Tmp.r2.setCenter(tile.drawx(), tile.drawy()); for(SolidEntity e : Entities.getNearby(Vars.control.enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){ Rectangle rect = e.hitbox.getRect(e.x, e.y); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/defense/PowerTurret.java b/core/src/io/anuke/mindustry/world/blocks/types/defense/PowerTurret.java index c36a22e2e0..213fbff4f9 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/defense/PowerTurret.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/defense/PowerTurret.java @@ -1,13 +1,7 @@ package io.anuke.mindustry.world.blocks.types.defense; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; - import io.anuke.mindustry.Vars; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.resource.Item; @@ -18,6 +12,10 @@ import io.anuke.ucore.graphics.Lines; import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Strings; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + public class PowerTurret extends Turret implements PowerAcceptor{ public float powerCapacity = 20f; public float powerUsed = 0.5f; @@ -36,25 +34,21 @@ public class PowerTurret extends Turret implements PowerAcceptor{ @Override public void drawSelect(Tile tile){ - Vector2 offset = getPlaceOffset(); - Draw.color(Color.GREEN); - Lines.dashCircle(tile.worldx() + offset.x, tile.worldy() + offset.y, range); + Lines.dashCircle(tile.drawx(), tile.drawy(), range); Draw.reset(); drawPowerBar(tile); } public void drawPowerBar(Tile tile){ - Vector2 offset = getPlaceOffset(); - PowerTurretEntity entity = tile.entity(); float fract = (float)entity.power / powerCapacity; if(fract > 0) fract = Mathf.clamp(fract, 0.24f, 1f); - Vars.renderer.drawBar(Color.YELLOW, tile.worldx() + offset.x, tile.worldy() + 6 + offset.y, fract); + Vars.renderer.drawBar(Color.YELLOW, tile.drawx(), tile.drawy() + 6, fract); } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/types/defense/RepairTurret.java b/core/src/io/anuke/mindustry/world/blocks/types/defense/RepairTurret.java index a371757bac..9d53c01476 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/defense/RepairTurret.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/defense/RepairTurret.java @@ -2,14 +2,12 @@ package io.anuke.mindustry.world.blocks.types.defense; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.MathUtils; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; - import io.anuke.mindustry.Vars; import io.anuke.mindustry.world.Layer; import io.anuke.mindustry.world.Tile; -import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.core.Timers; +import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Hue; import io.anuke.ucore.graphics.Lines; import io.anuke.ucore.util.Angles; @@ -83,10 +81,9 @@ public class RepairTurret extends PowerTurret{ if(entity.power >= powerUsed && entity.blockTarget != null && Angles.angleDist(entity.angleTo(entity.blockTarget), entity.rotation) < 10){ Tile targetTile = entity.blockTarget.tile; - Vector2 offset = targetTile.block().getPlaceOffset(); Angles.translation(entity.rotation, 4f); - float x = tile.worldx() + Angles.x(), y = tile.worldy() + Angles.y(); - float x2 = entity.blockTarget.x + offset.x, y2 = entity.blockTarget.y + offset.y; + float x = tile.drawx() + Angles.x(), y = tile.drawy() + Angles.y(); + float x2 = targetTile.drawx(), y2 = targetTile.drawy(); Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f)); Draw.alpha(0.3f); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/defense/Turret.java b/core/src/io/anuke/mindustry/world/blocks/types/defense/Turret.java index 2cfa534af9..66a16112e2 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/defense/Turret.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/defense/Turret.java @@ -1,7 +1,6 @@ package io.anuke.mindustry.world.blocks.types.defense; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.Vars; import io.anuke.mindustry.entities.Bullet; @@ -13,11 +12,11 @@ import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Layer; import io.anuke.mindustry.world.Tile; -import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects.Effect; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.Entities; +import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Lines; import io.anuke.ucore.util.Angles; import io.anuke.ucore.util.Mathf; @@ -78,21 +77,18 @@ public class Turret extends Block{ @Override public void draw(Tile tile){ - Vector2 offset = getPlaceOffset(); - if(isMultiblock()){ - Draw.rect("block-" + width + "x" + height, tile.worldx() + offset.x, tile.worldy() + offset.y); + Draw.rect("block-" + width + "x" + height, tile.drawx(), tile.drawy()); }else{ - Draw.rect("block", tile.worldx() + offset.x, tile.worldy() + offset.y); + Draw.rect("block", tile.drawx(), tile.drawy()); } } @Override public void drawLayer(Tile tile){ TurretEntity entity = tile.entity(); - Vector2 offset = getPlaceOffset(); - - Draw.rect(name(), tile.worldx() + offset.x, tile.worldy() + offset.y, entity.rotation - 90); + + Draw.rect(name(), tile.drawx(), tile.drawy(), entity.rotation - 90); if(Vars.debug && drawDebug){ drawTargeting(tile); @@ -101,10 +97,8 @@ public class Turret extends Block{ @Override public void drawSelect(Tile tile){ - Vector2 offset = getPlaceOffset(); - Draw.color(Color.GREEN); - Lines.dashCircle(tile.worldx() + offset.x, tile.worldy() + offset.y, range); + Lines.dashCircle(tile.drawx(), tile.drawy(), range); Draw.reset(); TurretEntity entity = tile.entity(); @@ -113,7 +107,7 @@ public class Turret extends Block{ if(fract > 0) fract = Mathf.clamp(fract, 0.24f, 1f); - Vars.renderer.drawBar(Color.GREEN, tile.worldx() + offset.x, 2 + tile.worldy() + height/2f*Vars.tilesize + offset.y, fract); + Vars.renderer.drawBar(Color.GREEN, tile.drawx(), 2 + tile.drawy() + height/2f*Vars.tilesize, fract); } @Override @@ -221,7 +215,7 @@ public class Turret extends Block{ protected void shoot(Tile tile){ TurretEntity entity = tile.entity(); - Vector2 offset = getPlaceOffset(); + Angles.translation(entity.rotation, width * Vars.tilesize / 2f); @@ -238,8 +232,8 @@ public class Turret extends Block{ } if(shootEffect != null){ - Effects.effect(shootEffect, tile.worldx() + Angles.x() + offset.x, - tile.worldy()+ Angles.y() + offset.y, entity.rotation); + Effects.effect(shootEffect, tile.drawx() + Angles.x(), + tile.drawy()+ Angles.y(), entity.rotation); } if(shootShake > 0){ @@ -248,8 +242,7 @@ public class Turret extends Block{ } protected void bullet(Tile tile, float angle){ - Vector2 offset = getPlaceOffset(); - Bullet out = new Bullet(bullet, tile.entity, tile.worldx() + Angles.x() + offset.x, tile.worldy() + Angles.y() + offset.y, angle).add(); + Bullet out = new Bullet(bullet, tile.entity, tile.drawx() + Angles.x(), tile.drawy() + Angles.y(), angle).add(); out.damage = (int)(bullet.damage*Vars.multiplier); } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/production/LiquidCrafter.java b/core/src/io/anuke/mindustry/world/blocks/types/production/LiquidCrafter.java index c0226c1cd8..4fe4464599 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/production/LiquidCrafter.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/production/LiquidCrafter.java @@ -1,7 +1,6 @@ package io.anuke.mindustry.world.blocks.types.production; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.Vars; import io.anuke.mindustry.entities.TileEntity; @@ -50,16 +49,14 @@ public class LiquidCrafter extends LiquidBlock{ @Override public void draw(Tile tile){ - Vector2 v = getPlaceOffset(); - LiquidEntity entity = tile.entity(); - Draw.rect(name(), tile.worldx() + v.x, tile.worldy() + v.y); + Draw.rect(name(), tile.drawx(), tile.drawy()); if(entity.liquid == null) return; Draw.color(entity.liquid.color); Draw.alpha(entity.liquidAmount / liquidCapacity); - Draw.rect("blank", tile.worldx() + v.x, tile.worldy() + v.y, 2, 2); + Draw.rect("blank", tile.drawx(), tile.drawy(), 2, 2); Draw.color(); } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/production/LiquidPowerGenerator.java b/core/src/io/anuke/mindustry/world/blocks/types/production/LiquidPowerGenerator.java index e5e64697b1..4aec48b2f4 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/production/LiquidPowerGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/production/LiquidPowerGenerator.java @@ -1,24 +1,22 @@ package io.anuke.mindustry.world.blocks.types.production; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; - import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.resource.Liquid; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.types.LiquidAcceptor; -import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects.Effect; import io.anuke.ucore.core.Timers; +import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Strings; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{ public int generateTime = 15; public Liquid generateLiquid; @@ -57,8 +55,7 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{ } public void drawLiquidCenter(Tile tile){ - Vector2 offset = getPlaceOffset(); - Draw.rect("blank", tile.worldx() + offset.x, tile.worldy() + offset.y, 2, 2); + Draw.rect("blank", tile.drawx(), tile.drawy(), 2, 2); } @Override @@ -73,8 +70,8 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{ entity.power += used * powerPerLiquid; if(used > 0.001f && Mathf.chance(0.05 * Timers.delta())){ - Vector2 offset = getPlaceOffset(); - Effects.effect(generateEffect, tile.worldx() + offset.x + Mathf.range(3f), tile.worldy() + offset.y + Mathf.range(3f)); + + Effects.effect(generateEffect, tile.drawx() + Mathf.range(3f), tile.drawy() + Mathf.range(3f)); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/production/NuclearReactor.java b/core/src/io/anuke/mindustry/world/blocks/types/production/NuclearReactor.java index 222f3fa646..2ad3dfcd7b 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/production/NuclearReactor.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/production/NuclearReactor.java @@ -1,7 +1,6 @@ package io.anuke.mindustry.world.blocks.types.production; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.Vars; import io.anuke.mindustry.entities.TileEntity; @@ -10,9 +9,9 @@ import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.resource.Liquid; import io.anuke.mindustry.world.Tile; -import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Timers; +import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Strings; import io.anuke.ucore.util.Tmp; @@ -99,8 +98,7 @@ public class NuclearReactor extends LiquidPowerGenerator{ @Override public void drawLiquidCenter(Tile tile){ - Vector2 offset = getPlaceOffset(); - Draw.rect(name + "-center", tile.worldx() + offset.x, tile.worldy() + offset.y); + Draw.rect(name + "-center", tile.drawx(), tile.drawy()); } @Override @@ -154,18 +152,17 @@ public class NuclearReactor extends LiquidPowerGenerator{ super.drawSelect(tile); NuclearReactorEntity entity = tile.entity(); - Vector2 offset = getPlaceOffset(); - Vars.renderer.drawBar(Color.GREEN, tile.worldx() + offset.x, tile.worldy() + 6 + - offset.y + height*Vars.tilesize/2f, (float)entity.getItem(generateItem) / itemCapacity); + Vars.renderer.drawBar(Color.GREEN, tile.drawx(), tile.drawy() + 6 + + height*Vars.tilesize/2f, (float)entity.getItem(generateItem) / itemCapacity); Draw.reset(); float fract = entity.heat; if(fract > 0) fract = Mathf.clamp(fract + 0.2f, 0.24f, 1f); - Vars.renderer.drawBar(Color.ORANGE, tile.worldx() + offset.x, - tile.worldy() + Vars.tilesize * height/2f + 10 + offset.y, fract); + Vars.renderer.drawBar(Color.ORANGE, tile.drawx(), + tile.drawy() + Vars.tilesize * height/2f + 10, fract); } @Override @@ -178,17 +175,16 @@ public class NuclearReactor extends LiquidPowerGenerator{ super.draw(tile); NuclearReactorEntity entity = tile.entity(); - Vector2 offset = getPlaceOffset(); Draw.color(coolColor, hotColor, entity.heat); - Draw.rect("white", tile.worldx() + offset.x, tile.worldy() + offset.y, width * Vars.tilesize, height * Vars.tilesize); + Draw.rect("white", tile.drawx(), tile.drawy(), width * Vars.tilesize, height * Vars.tilesize); if(entity.heat > flashThreshold){ float flash = 1f + ((entity.heat - flashThreshold) / (1f - flashThreshold)) * 5.4f; entity.flash += flash * Timers.delta(); Draw.color(Color.RED, Color.YELLOW, Mathf.absin(entity.flash, 9f, 1f)); Draw.alpha(0.6f); - Draw.rect(name + "-lights", tile.worldx() + offset.x, tile.worldy() + offset.y); + Draw.rect(name + "-lights", tile.drawx(), tile.drawy()); } Draw.reset(); diff --git a/html/src/io/anuke/mindustry/client/WebsocketClient.java b/html/src/io/anuke/mindustry/client/WebsocketClient.java index 9c865ead8b..9e4e2013df 100644 --- a/html/src/io/anuke/mindustry/client/WebsocketClient.java +++ b/html/src/io/anuke/mindustry/client/WebsocketClient.java @@ -28,16 +28,14 @@ public class WebsocketClient implements ClientProvider { ByteBuffer buffer = ByteBuffer.allocate(1024); @Override - public void connect(String ip, int port) throws IOException { + public void connect(String ip, int port){ socket = new Websocket("ws://" + ip + ":" + Vars.webPort); socket.addListener(new WebsocketListener() { public void onMessage(byte[] bytes) { try { ByteBuffer buffer = ByteBuffer.wrap(bytes); byte id = buffer.get(); - if(id == -2){ - //this is a framework message... do nothing yet? - }else { + if(id != -2){ //ignore framework messages Class type = Registrator.getByID(id); Packet packet = (Packet) ClassReflection.newInstance(type); packet.read(buffer); @@ -99,8 +97,8 @@ public class WebsocketClient implements ClientProvider { } @Override - public Array discover() { - return new Array<>(); + public void discover(Consumer> callback){ + callback.accept(new Array<>()); } @Override @@ -141,9 +139,6 @@ public class WebsocketClient implements ClientProvider { } } - @Override - public void register(Class... types) { } - @Override public void dispose() { socket.close(); diff --git a/kryonet/src/io/anuke/kryonet/JavaWebsocketClient.java b/kryonet/src/io/anuke/kryonet/JavaWebsocketClient.java index b053cdf144..eb4693c1b4 100644 --- a/kryonet/src/io/anuke/kryonet/JavaWebsocketClient.java +++ b/kryonet/src/io/anuke/kryonet/JavaWebsocketClient.java @@ -125,8 +125,8 @@ public class JavaWebsocketClient implements ClientProvider { } @Override - public Array discover() { - return new Array<>(); + public void discover(Consumer> callback){ + callback.accept(new Array<>()); } @Override @@ -134,9 +134,6 @@ public class JavaWebsocketClient implements ClientProvider { failed.accept(new IOException()); } - @Override - public void register(Class... types) { } - @Override public void dispose() { if(socket != null) socket.close(); diff --git a/kryonet/src/io/anuke/kryonet/KryoClient.java b/kryonet/src/io/anuke/kryonet/KryoClient.java index ad5a5a0a35..cfc77ecc8c 100644 --- a/kryonet/src/io/anuke/kryonet/KryoClient.java +++ b/kryonet/src/io/anuke/kryonet/KryoClient.java @@ -13,7 +13,6 @@ import io.anuke.mindustry.net.Net.ClientProvider; import io.anuke.mindustry.net.Net.SendMode; import io.anuke.mindustry.net.Packets.Connect; import io.anuke.mindustry.net.Packets.Disconnect; -import io.anuke.mindustry.net.Registrator; import io.anuke.ucore.UCore; import io.anuke.ucore.function.Consumer; @@ -95,8 +94,6 @@ public class KryoClient implements ClientProvider{ }else{ client.addListener(listener); } - - register(Registrator.getClasses()); } @Override @@ -143,7 +140,7 @@ public class KryoClient implements ClientProvider{ @Override public void pingHost(String address, int port, Consumer valid, Consumer invalid){ - Thread thread = new Thread(() -> { + runAsync(() -> { try { DatagramSocket socket = new DatagramSocket(); socket.send(new DatagramPacket(new byte[]{-2, 1}, 2, InetAddress.getByName(address), Vars.port)); @@ -168,33 +165,29 @@ public class KryoClient implements ClientProvider{ Gdx.app.postRunnable(() -> invalid.accept(e)); } }); - - thread.setDaemon(true); - thread.start(); } @Override - public Array discover(){ - addresses.clear(); - List list = client.discoverHosts(Vars.port, 3000); - ObjectSet hostnames = new ObjectSet<>(); - Array result = new Array<>(); + public void discover(Consumer> callback){ + runAsync(() -> { + addresses.clear(); + List list = client.discoverHosts(Vars.port, 3000); + ObjectSet hostnames = new ObjectSet<>(); + Array result = new Array<>(); - for(InetAddress a : list){ - if(!hostnames.contains(a.getHostName())) { - Host address = addresses.get(a); - if(address != null) result.add(address); + for(InetAddress a : list){ + if(!hostnames.contains(a.getHostName())) { + Host address = addresses.get(a); + if(address != null) result.add(address); + } + hostnames.add(a.getHostName()); } - hostnames.add(a.getHostName()); - } - return result; + Gdx.app.postRunnable(() -> callback.accept(result)); + }); } - @Override - public void register(Class... types) { } - @Override public void dispose(){ try { @@ -204,6 +197,12 @@ public class KryoClient implements ClientProvider{ } } + private void runAsync(Runnable run){ + Thread thread = new Thread(run, "Client Async Run"); + thread.setDaemon(true); + thread.start(); + } + private void handleException(Exception e){ e.printStackTrace(); if(e instanceof KryoNetException){ diff --git a/kryonet/src/io/anuke/kryonet/KryoServer.java b/kryonet/src/io/anuke/kryonet/KryoServer.java index 8b74b8c645..ff705d8763 100644 --- a/kryonet/src/io/anuke/kryonet/KryoServer.java +++ b/kryonet/src/io/anuke/kryonet/KryoServer.java @@ -103,8 +103,6 @@ public class KryoServer implements ServerProvider { }else{ server.addListener(listener); } - - register(Registrator.getClasses()); } @Override @@ -253,9 +251,6 @@ public class KryoServer implements ServerProvider { return k.connection == null ? 0 : k.connection.getReturnTripTime(); } - @Override - public void register(Class... types) { } - @Override public void dispose(){ try { @@ -386,7 +381,6 @@ public class KryoServer implements ServerProvider { public SocketServer(int port) { super(new InetSocketAddress(port)); - //setWebSocketFactory(factory); } @Override