Fixed many network-related bugs
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.entities.enemies.EnemyTypes;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.scene.builders.button;
|
||||
import io.anuke.ucore.scene.builders.label;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Log.LogHandler;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class DebugFragment implements Fragment {
|
||||
private static StringBuilder log = new StringBuilder();
|
||||
|
||||
static{
|
||||
Log.setLogger(new LogHandler(){
|
||||
@Override
|
||||
public void print(String text, Object... args){
|
||||
super.print(text, args);
|
||||
log.append(Log.format(text, args));
|
||||
log.append("\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(){
|
||||
new table(){{
|
||||
visible(() -> debug);
|
||||
|
||||
atop().aright();
|
||||
|
||||
new table("pane"){{
|
||||
defaults().fillX();
|
||||
|
||||
new label("Debug");
|
||||
row();
|
||||
new button("noclip", "toggle", () -> noclip = !noclip);
|
||||
row();
|
||||
new button("paths", "toggle", () -> showPaths = !showPaths);
|
||||
row();
|
||||
new button("infammo", "toggle", () -> infiniteAmmo = !infiniteAmmo);
|
||||
row();
|
||||
new button("wave", () -> logic.runWave());
|
||||
row();
|
||||
new button("clear", () -> {
|
||||
enemyGroup.clear();
|
||||
state.enemies = 0;
|
||||
netClient.clearRecieved();
|
||||
});
|
||||
row();
|
||||
new button("spawn", () -> new Enemy(EnemyTypes.standard).set(player.x, player.y).add());
|
||||
row();
|
||||
}}.end();
|
||||
|
||||
row();
|
||||
|
||||
}}.end();
|
||||
|
||||
|
||||
new table(){{
|
||||
visible(() -> console);
|
||||
|
||||
atop().aleft();
|
||||
|
||||
new table("pane") {{
|
||||
defaults().fillX();
|
||||
|
||||
new label(DebugFragment::debugInfo);
|
||||
row();
|
||||
new button("dump", () -> {
|
||||
try{
|
||||
Gdx.files.local("packet-dump.txt").writeString(debugInfo(), false);
|
||||
}catch (Exception e){
|
||||
ui.showError("Error dumping log.");
|
||||
}
|
||||
});
|
||||
}}.end();
|
||||
}}.end();
|
||||
|
||||
new table(){{
|
||||
visible(() -> console);
|
||||
|
||||
atop();
|
||||
|
||||
Table table = new Table("pane");
|
||||
table.label(() -> log.toString());
|
||||
|
||||
ScrollPane pane = new ScrollPane(table, "clear");
|
||||
|
||||
get().add(pane);
|
||||
}}.end();
|
||||
}
|
||||
|
||||
public static String debugInfo(){
|
||||
return join(
|
||||
"net.active: " + Net.active(),
|
||||
"net.server: " + Net.server(),
|
||||
"players: " + playerGroup.size(),
|
||||
"enemies: " + enemyGroup.size(),
|
||||
"tiles: " + tileGroup.size(),
|
||||
"",
|
||||
clientDebug.getOut()
|
||||
);
|
||||
}
|
||||
|
||||
private static String join(String... strings){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String string : strings) {
|
||||
builder.append(string);
|
||||
builder.append("\n");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.actions.Actions;
|
||||
import io.anuke.ucore.scene.builders.imagebutton;
|
||||
import io.anuke.ucore.scene.builders.label;
|
||||
@@ -148,26 +147,6 @@ public class HudFragment implements Fragment{
|
||||
}}.end();
|
||||
}}.end();
|
||||
|
||||
//profiling table
|
||||
if(debug){
|
||||
new table(){{
|
||||
atop();
|
||||
new label("[green]density: " + Gdx.graphics.getDensity()).left();
|
||||
row();
|
||||
new label(() -> "[blue]requests: " + renderer.getBlocks().getRequests()).left();
|
||||
row();
|
||||
new label(() -> "[purple]tiles: " + tileGroup.size()).left();
|
||||
row();
|
||||
new label(() -> "[purple]enemies: " + enemyGroup.size()).left();
|
||||
row();
|
||||
new label(() -> "[orange]noclip: " + noclip).left();
|
||||
row();
|
||||
new label(() -> "[purple]time: " + (int)(Timers.time() / 10f) % 50).left();
|
||||
row();
|
||||
new label("[red]DEBUG MODE").scale(0.5f).left();
|
||||
}}.end();
|
||||
}
|
||||
|
||||
new table(){{
|
||||
abottom();
|
||||
visible(() -> !state.is(State.menu) && control.getSaves().isSaving());
|
||||
@@ -176,14 +155,6 @@ public class HudFragment implements Fragment{
|
||||
|
||||
}}.end();
|
||||
|
||||
if(debugNet) {
|
||||
new table() {{
|
||||
new label(() -> "players: " + playerGroup.size());
|
||||
row();
|
||||
new label(() -> "" + playerGroup.all());
|
||||
}}.end();
|
||||
}
|
||||
|
||||
blockfrag.build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user