Rewrite of all static initialization code
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.OrderedMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
|
||||
public class ClientDebug {
|
||||
private OrderedMap<Class<?>, Long> last = new OrderedMap<>();
|
||||
private int syncPlayers = 0;
|
||||
private int syncEnemies = 0;
|
||||
|
||||
public void handle(Object packet){
|
||||
last.put(packet.getClass(), TimeUtils.millis());
|
||||
}
|
||||
|
||||
public void setSyncDebug(int players, int enemies){
|
||||
this.syncEnemies = enemies;
|
||||
this.syncPlayers = players;
|
||||
}
|
||||
|
||||
public String getOut(){
|
||||
StringBuilder build = new StringBuilder();
|
||||
for(Class<?> type : last.orderedKeys()){
|
||||
build.append(elapsed(type));
|
||||
build.append("\n");
|
||||
}
|
||||
build.append("sync.players: ");
|
||||
build.append(syncPlayers);
|
||||
build.append("\n");
|
||||
build.append("sync.enemies: ");
|
||||
build.append(syncEnemies);
|
||||
build.append("\n");
|
||||
return build.toString();
|
||||
}
|
||||
|
||||
private String elapsed(Class<?> type){
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,6 @@ public class Net{
|
||||
|
||||
/**Call to handle a packet being recieved for the client.*/
|
||||
public static void handleClientReceived(Object object){
|
||||
if(debugNet) clientDebug.handle(object);
|
||||
|
||||
if(object instanceof StreamBegin) {
|
||||
StreamBegin b = (StreamBegin) object;
|
||||
@@ -198,7 +197,6 @@ 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(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);
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
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 io.anuke.ucore.util.Log;
|
||||
|
||||
import static io.anuke.mindustry.Vars.playerGroup;
|
||||
|
||||
public class ServerDebug {
|
||||
private IntMap<OrderedMap<Class<?>, Long>> last = new IntMap<>();
|
||||
|
||||
public void handle(int connection, Object packet){
|
||||
try {
|
||||
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());
|
||||
}catch (Exception e){
|
||||
Log.err("<An internal debug error has occurred.>");
|
||||
}
|
||||
}
|
||||
|
||||
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(" mech: ");
|
||||
build.append(player.mech);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user