Fixed overly long startup time, added more debug info

This commit is contained in:
Anuken
2018-01-29 10:36:57 -05:00
parent a776898dd5
commit 6083db5bd6
7 changed files with 73 additions and 18 deletions

View File

@@ -171,7 +171,7 @@ public class Net{
/**Call to handle a packet being recieved for the server.*/
public static void handleServerReceived(int connection, Object object){
if(debugNet) serverDebug.handle(object);
if(debugNet) serverDebug.handle(connection, object);
if(serverListeners.get(object.getClass()) != null || listeners.get(object.getClass()) != null){
if(serverListeners.get(object.getClass()) != null) serverListeners.get(object.getClass()).accept(connection, object);

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.net;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.enemies.Enemy;
@@ -27,8 +26,6 @@ public class NetEvents {
public static void handleGameOver(){
Net.send(new GameOverPacket(), SendMode.tcp);
state.gameOver = true;
state.set(State.menu);
}
public static void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){

View File

@@ -1,8 +1,58 @@
package io.anuke.mindustry.net;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.OrderedMap;
import com.badlogic.gdx.utils.TimeUtils;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.net.Packets.Disconnect;
import static io.anuke.mindustry.Vars.playerGroup;
public class ServerDebug {
private IntMap<OrderedMap<Class<?>, Long>> last = new IntMap<>();
public void handle(Object packet){
public void handle(int connection, Object packet){
if(!last.containsKey(connection))
last.put(connection, new OrderedMap<>());
if(packet instanceof Disconnect)
last.remove(connection);
else
last.get(connection).put(packet.getClass(), TimeUtils.millis());
}
public String getOut(){
StringBuilder build = new StringBuilder();
for(Player player : playerGroup.all()){
OrderedMap<Class<?>, Long> map = last.get(player.clientid, new OrderedMap<>());
build.append("connection ");
build.append(player.clientid);
build.append(" / player '");
build.append(player.name);
build.append("'\n");
for(Class<?> type : map.orderedKeys()){
build.append(" ");
build.append(elapsed(type, map));
build.append("\n");
}
}
return build.toString();
}
private String elapsed(Class<?> type, OrderedMap<Class<?>, Long> last) {
long t = last.get(type, -1L);
if (t == -1) {
return ClassReflection.getSimpleName(type) + ": <never>";
} else {
float el = TimeUtils.timeSinceMillis(t) / 1000f;
String tu;
if (el > 1f) {
tu = (int) el + "s";
} else {
tu = (int) (el * 60) + "f";
}
return ClassReflection.getSimpleName(type) + ": " + tu;
}
}
}