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

View File

@@ -48,6 +48,11 @@ public class Pathfind{
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(enemy.idletime > EnemyType.maxIdle){

View File

@@ -133,8 +133,8 @@ public class NetClient extends Module {
if(sync == null){
Gdx.app.error("Mindustry", "Unknown entity ID: " + id + " " + (i >= packet.enemyStart ? "(enemy)" : "(player)"));
if(!requests.contains(id)){
Gdx.app.error("Mindustry", "Sending entity request: " + id);
requests.add(id);
Gdx.app.error("Mindustry", "Sending entity request: " + id);
EntityRequestPacket req = new EntityRequestPacket();
req.id = id;
Net.send(req, SendMode.tcp);
@@ -174,8 +174,9 @@ public class NetClient extends Module {
});
Net.handle(EnemySpawnPacket.class, spawn -> {
requests.remove(spawn.id);
Gdx.app.postRunnable(() -> {
//duplicates.
if(Vars.control.enemyGroup.getByID(spawn.id) != null) return;
Enemy enemy = new Enemy(EnemyType.getByID(spawn.type));
enemy.set(spawn.x, spawn.y);
enemy.tier = spawn.tier;
@@ -260,10 +261,13 @@ public class NetClient extends Module {
});
Net.handle(Player.class, player -> {
requests.remove(player.id);
player.getInterpolator().last.set(player.x, player.y);
player.getInterpolator().target.set(player.x, player.y);
player.add();
Gdx.app.postRunnable(() -> {
//duplicates.
if(Vars.control.enemyGroup.getByID(player.id) != null) return;
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))));
@@ -386,5 +390,9 @@ public class NetClient extends Module {
packet.data = Vars.player.getInterpolator().type.write(Vars.player);
Net.send(packet, SendMode.udp);
}
if(Timers.get("updatePing", 60)){
Net.updatePing();
}
}
}

View File

@@ -83,12 +83,14 @@ public class NetServer extends Module{
}
sendMessage("[accent]"+Bundles.format("text.server.disconnected", player.name));
Gdx.app.postRunnable(player::remove);
Gdx.app.postRunnable(() -> {
player.remove();
DisconnectPacket dc = new DisconnectPacket();
dc.playerid = player.id;
DisconnectPacket dc = new DisconnectPacket();
dc.playerid = player.id;
Net.send(dc, SendMode.tcp);
Net.send(dc, SendMode.tcp);
});
});
Net.handleServer(PositionPacket.class, pos -> {
@@ -185,7 +187,7 @@ public class NetServer extends Module{
Gdx.app.postRunnable(() -> {
if(Vars.control.playerGroup.getByID(id) != null){
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){
Enemy enemy = Vars.control.enemyGroup.getByID(id);
EnemySpawnPacket e = new EnemySpawnPacket();
@@ -196,7 +198,7 @@ public class NetServer extends Module{
e.lane = (byte)enemy.lane;
e.type = enemy.type.id;
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{
Gdx.app.error("Mindustry", "Entity request target not found!");
}

View File

@@ -103,9 +103,9 @@ public class Renderer extends RendererModule{
//TODO identify the source of this bug
if(control.core == null){
ui.showError("$text.error.crashmessage");
GameState.set(State.menu);
return;
// ui.showError("$text.error.crashmessage");
// GameState.set(State.menu);
// return;
}
if(control.core.block() == ProductionBlocks.core){

View File

@@ -1,13 +1,11 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.GridPoint2;
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.ai.Pathfind;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.io.Maps;
import io.anuke.mindustry.net.Net;
@@ -109,11 +107,9 @@ public class World extends Module{
}
public Tile tile(int x, int y){
if(tiles == null){
Gdx.app.postRunnable(() -> Vars.ui.showError("$text.error.crashmessage"));
GameState.set(State.menu);
return null;
}
//if(tiles == null){
// return null;
//}
if(!Mathf.inBounds(x, y, tiles)) return null;
return tiles[x][y];
}

View File

@@ -7,7 +7,7 @@ public enum Difficulty {
normal(2f, 1f),
hard(1.5f, 0.5f),
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.
* For example: with enemeyScaling = 2 and the default scaling being 2, it would take 4 waves for

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.*/
public static int getLastConnection(){
return lastConnection;

View File

@@ -95,7 +95,8 @@ public class HudFragment implements Fragment{
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();
add(fps).size(-1);
@@ -122,6 +123,11 @@ public class HudFragment implements Fragment{
new table("white"){{
respawntable = get();
respawntable.setColor(Color.CLEAR);
update(t -> {
if(GameState.is(State.menu)){
respawntable.setColor(Color.CLEAR);
}
});
}}.end();
//respawn table