Network, UI, renderer fixes

This commit is contained in:
Anuken
2018-01-11 23:15:53 -05:00
parent e91aa62b4a
commit 1762af5d4c
10 changed files with 56 additions and 28 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.anuke.mindustry" package="io.anuke.mindustry"
android:versionCode="51" android:versionCode="53"
android:versionName="3.3b3" > android:versionName="3.3b5" >
<uses-permission android:name="com.android.vending.BILLING" /> <uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@@ -48,6 +48,11 @@ public class Pathfind{
Tile[] path = Vars.control.getSpawnPoints().get(enemy.lane).pathTiles; Tile[] path = Vars.control.getSpawnPoints().get(enemy.lane).pathTiles;
if(enemy.node >= path.length){
enemy.node = -1;
return vector.set(enemy.x, enemy.y);
}
//if an enemy is idle for a while, it's probably stuck //if an enemy is idle for a while, it's probably stuck
if(enemy.idletime > EnemyType.maxIdle){ if(enemy.idletime > EnemyType.maxIdle){
@@ -133,8 +133,8 @@ public class NetClient extends Module {
if(sync == null){ if(sync == null){
Gdx.app.error("Mindustry", "Unknown entity ID: " + id + " " + (i >= packet.enemyStart ? "(enemy)" : "(player)")); Gdx.app.error("Mindustry", "Unknown entity ID: " + id + " " + (i >= packet.enemyStart ? "(enemy)" : "(player)"));
if(!requests.contains(id)){ if(!requests.contains(id)){
Gdx.app.error("Mindustry", "Sending entity request: " + id);
requests.add(id); requests.add(id);
Gdx.app.error("Mindustry", "Sending entity request: " + id);
EntityRequestPacket req = new EntityRequestPacket(); EntityRequestPacket req = new EntityRequestPacket();
req.id = id; req.id = id;
Net.send(req, SendMode.tcp); Net.send(req, SendMode.tcp);
@@ -174,8 +174,9 @@ public class NetClient extends Module {
}); });
Net.handle(EnemySpawnPacket.class, spawn -> { Net.handle(EnemySpawnPacket.class, spawn -> {
requests.remove(spawn.id);
Gdx.app.postRunnable(() -> { Gdx.app.postRunnable(() -> {
//duplicates.
if(Vars.control.enemyGroup.getByID(spawn.id) != null) return;
Enemy enemy = new Enemy(EnemyType.getByID(spawn.type)); Enemy enemy = new Enemy(EnemyType.getByID(spawn.type));
enemy.set(spawn.x, spawn.y); enemy.set(spawn.x, spawn.y);
enemy.tier = spawn.tier; enemy.tier = spawn.tier;
@@ -260,10 +261,13 @@ public class NetClient extends Module {
}); });
Net.handle(Player.class, player -> { Net.handle(Player.class, player -> {
requests.remove(player.id); Gdx.app.postRunnable(() -> {
player.getInterpolator().last.set(player.x, player.y); //duplicates.
player.getInterpolator().target.set(player.x, player.y); if(Vars.control.enemyGroup.getByID(player.id) != null) return;
player.add(); player.getInterpolator().last.set(player.x, player.y);
player.getInterpolator().target.set(player.x, player.y);
player.add();
});
}); });
Net.handle(ChatPacket.class, packet -> Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.text, Vars.netClient.colorizeName(packet.id, packet.name)))); Net.handle(ChatPacket.class, packet -> Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.text, Vars.netClient.colorizeName(packet.id, packet.name))));
@@ -386,5 +390,9 @@ public class NetClient extends Module {
packet.data = Vars.player.getInterpolator().type.write(Vars.player); packet.data = Vars.player.getInterpolator().type.write(Vars.player);
Net.send(packet, SendMode.udp); Net.send(packet, SendMode.udp);
} }
if(Timers.get("updatePing", 60)){
Net.updatePing();
}
} }
} }
@@ -83,12 +83,14 @@ public class NetServer extends Module{
} }
sendMessage("[accent]"+Bundles.format("text.server.disconnected", player.name)); sendMessage("[accent]"+Bundles.format("text.server.disconnected", player.name));
Gdx.app.postRunnable(player::remove); Gdx.app.postRunnable(() -> {
player.remove();
DisconnectPacket dc = new DisconnectPacket(); DisconnectPacket dc = new DisconnectPacket();
dc.playerid = player.id; dc.playerid = player.id;
Net.send(dc, SendMode.tcp); Net.send(dc, SendMode.tcp);
});
}); });
Net.handleServer(PositionPacket.class, pos -> { Net.handleServer(PositionPacket.class, pos -> {
@@ -185,7 +187,7 @@ public class NetServer extends Module{
Gdx.app.postRunnable(() -> { Gdx.app.postRunnable(() -> {
if(Vars.control.playerGroup.getByID(id) != null){ if(Vars.control.playerGroup.getByID(id) != null){
Net.sendTo(dest, Vars.control.playerGroup.getByID(id), SendMode.tcp); Net.sendTo(dest, Vars.control.playerGroup.getByID(id), SendMode.tcp);
Gdx.app.error("Mindustry", "Replying to entity request: player, " + id); Gdx.app.error("Mindustry", "Replying to entity request ("+Net.getLastConnection()+"): player, " + id);
}else if (Vars.control.enemyGroup.getByID(id) != null){ }else if (Vars.control.enemyGroup.getByID(id) != null){
Enemy enemy = Vars.control.enemyGroup.getByID(id); Enemy enemy = Vars.control.enemyGroup.getByID(id);
EnemySpawnPacket e = new EnemySpawnPacket(); EnemySpawnPacket e = new EnemySpawnPacket();
@@ -196,7 +198,7 @@ public class NetServer extends Module{
e.lane = (byte)enemy.lane; e.lane = (byte)enemy.lane;
e.type = enemy.type.id; e.type = enemy.type.id;
Net.sendTo(dest, e, SendMode.tcp); Net.sendTo(dest, e, SendMode.tcp);
Gdx.app.error("Mindustry", "Replying to entity request: enemy, " + id); Gdx.app.error("Mindustry", "Replying to entity request("+Net.getLastConnection()+"): enemy, " + id);
}else{ }else{
Gdx.app.error("Mindustry", "Entity request target not found!"); Gdx.app.error("Mindustry", "Entity request target not found!");
} }
@@ -103,9 +103,9 @@ public class Renderer extends RendererModule{
//TODO identify the source of this bug //TODO identify the source of this bug
if(control.core == null){ if(control.core == null){
ui.showError("$text.error.crashmessage"); // ui.showError("$text.error.crashmessage");
GameState.set(State.menu); // GameState.set(State.menu);
return; // return;
} }
if(control.core.block() == ProductionBlocks.core){ if(control.core.block() == ProductionBlocks.core){
+3 -7
View File
@@ -1,13 +1,11 @@
package io.anuke.mindustry.core; package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2; 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.ai.Pathfind; import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.io.Maps; import io.anuke.mindustry.io.Maps;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
@@ -109,11 +107,9 @@ public class World extends Module{
} }
public Tile tile(int x, int y){ public Tile tile(int x, int y){
if(tiles == null){ //if(tiles == null){
Gdx.app.postRunnable(() -> Vars.ui.showError("$text.error.crashmessage")); // return null;
GameState.set(State.menu); //}
return null;
}
if(!Mathf.inBounds(x, y, tiles)) return null; if(!Mathf.inBounds(x, y, tiles)) return null;
return tiles[x][y]; return tiles[x][y];
} }
@@ -7,7 +7,7 @@ public enum Difficulty {
normal(2f, 1f), normal(2f, 1f),
hard(1.5f, 0.5f), hard(1.5f, 0.5f),
insane(0.5f, 0.25f), insane(0.5f, 0.25f),
purge(0.4f, 0.01f); purge(0.35f, 0.01f);
/**The scaling of how many waves it takes for one more enemy of a type to appear. /**The scaling of how many waves it takes for one more enemy of a type to appear.
* For example: with enemeyScaling = 2 and the default scaling being 2, it would take 4 waves for * For example: with enemeyScaling = 2 and the default scaling being 2, it would take 4 waves for
+10
View File
@@ -157,6 +157,16 @@ public class Net{
} }
} }
/**Update client ping.*/
public static void updatePing(){
clientProvider.updatePing();
}
/**Get the client ping. Only valid after updatePing().*/
public static int getPing(){
return clientProvider.getPing();
}
/**Returns the last connection that sent a packet to this server.*/ /**Returns the last connection that sent a packet to this server.*/
public static int getLastConnection(){ public static int getLastConnection(){
return lastConnection; return lastConnection;
@@ -95,7 +95,8 @@ 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() : ""): ""));
row(); row();
add(fps).size(-1); add(fps).size(-1);
@@ -122,6 +123,11 @@ public class HudFragment implements Fragment{
new table("white"){{ new table("white"){{
respawntable = get(); respawntable = get();
respawntable.setColor(Color.CLEAR); respawntable.setColor(Color.CLEAR);
update(t -> {
if(GameState.is(State.menu)){
respawntable.setColor(Color.CLEAR);
}
});
}}.end(); }}.end();
//respawn table //respawn table
+3 -2
View File
@@ -86,7 +86,9 @@ public class KryoServer implements ServerProvider {
try{ try{
Net.handleServerReceived(object, connection.getID()); Net.handleServerReceived(object, connection.getID());
}catch (Exception e){ }catch (Exception e){
Gdx.app.postRunnable(() -> {throw new RuntimeException(e);}); //...do absolutely nothing.
e.printStackTrace();
//Gdx.app.postRunnable(() -> {throw new RuntimeException(e);});
} }
} }
}); });
@@ -133,7 +135,6 @@ public class KryoServer implements ServerProvider {
@Override @Override
public void sendStream(int id, Streamable stream) { public void sendStream(int id, Streamable stream) {
Connection connection = getByID(id); Connection connection = getByID(id);
UCore.log("Sending stream: " + stream.getClass().getSimpleName() + " / " + stream.stream.available());
connection.addListener(new InputStreamSender(stream.stream, 512) { connection.addListener(new InputStreamSender(stream.stream, 512) {
int id; int id;