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