Added better block debugging
This commit is contained in:
@@ -24,7 +24,7 @@ allprojects {
|
|||||||
appName = 'Mindustry'
|
appName = 'Mindustry'
|
||||||
gdxVersion = '1.9.8'
|
gdxVersion = '1.9.8'
|
||||||
aiVersion = '1.8.1'
|
aiVersion = '1.8.1'
|
||||||
uCoreVersion = '4c049ea'
|
uCoreVersion = 'd66ebb6'
|
||||||
|
|
||||||
getVersionString = {
|
getVersionString = {
|
||||||
String buildVersion = getBuildVersion()
|
String buildVersion = getBuildVersion()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#Autogenerated file. Do not modify.
|
#Autogenerated file. Do not modify.
|
||||||
#Mon Feb 19 12:47:29 EST 2018
|
#Mon Feb 19 14:31:15 EST 2018
|
||||||
version=beta
|
version=beta
|
||||||
androidBuildCode=243
|
androidBuildCode=245
|
||||||
name=Mindustry
|
name=Mindustry
|
||||||
code=3.3
|
code=3.3
|
||||||
build=custom build
|
build=custom build
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ public class Vars{
|
|||||||
public static boolean showPlayer = true;
|
public static boolean showPlayer = true;
|
||||||
//whether to hide ui, only on debug
|
//whether to hide ui, only on debug
|
||||||
public static boolean showUI = true;
|
public static boolean showUI = true;
|
||||||
|
//whether to show block debug
|
||||||
|
public static boolean showBlockDebug = false;
|
||||||
|
|
||||||
public static boolean headless = false;
|
public static boolean headless = false;
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,7 @@ import io.anuke.ucore.core.*;
|
|||||||
import io.anuke.ucore.entities.EffectEntity;
|
import io.anuke.ucore.entities.EffectEntity;
|
||||||
import io.anuke.ucore.entities.Entities;
|
import io.anuke.ucore.entities.Entities;
|
||||||
import io.anuke.ucore.function.Callable;
|
import io.anuke.ucore.function.Callable;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.*;
|
||||||
import io.anuke.ucore.graphics.Hue;
|
|
||||||
import io.anuke.ucore.graphics.Lines;
|
|
||||||
import io.anuke.ucore.graphics.Surface;
|
|
||||||
import io.anuke.ucore.modules.RendererModule;
|
import io.anuke.ucore.modules.RendererModule;
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
import io.anuke.ucore.util.Angles;
|
import io.anuke.ucore.util.Angles;
|
||||||
@@ -439,6 +436,31 @@ public class Renderer extends RendererModule{
|
|||||||
if(tile.isLinked())
|
if(tile.isLinked())
|
||||||
target = tile.getLinked();
|
target = tile.getLinked();
|
||||||
|
|
||||||
|
if(showBlockDebug && target.entity != null){
|
||||||
|
Draw.color(Color.RED);
|
||||||
|
Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
|
||||||
|
Vector2 v = new Vector2();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Draw.tcolor(Color.YELLOW);
|
||||||
|
Draw.tscl(0.25f);
|
||||||
|
Array<Object> arr = target.block().getDebugInfo(target);
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for(int i = 0; i < arr.size/2; i ++){
|
||||||
|
result.append(arr.get(i*2));
|
||||||
|
result.append(": ");
|
||||||
|
result.append(arr.get(i*2 + 1));
|
||||||
|
result.append("\n");
|
||||||
|
}
|
||||||
|
Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
|
||||||
|
Draw.color(0f, 0f, 0f, 0.5f);
|
||||||
|
Fill.rect(target.drawx(), target.drawy(), v.x, v.y);
|
||||||
|
Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
|
||||||
|
Draw.tscl(fontscale);
|
||||||
|
Draw.reset();
|
||||||
|
}
|
||||||
|
|
||||||
if(Inputs.keyDown("block_info") && target.block().fullDescription != null){
|
if(Inputs.keyDown("block_info") && target.block().fullDescription != null){
|
||||||
Draw.color(Colors.get("accent"));
|
Draw.color(Colors.get("accent"));
|
||||||
Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
|
Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ public class DebugFragment implements Fragment {
|
|||||||
row();
|
row();
|
||||||
new button("hideplayer", "toggle", () -> showPlayer = !showPlayer);
|
new button("hideplayer", "toggle", () -> showPlayer = !showPlayer);
|
||||||
row();
|
row();
|
||||||
|
new button("blocks", "toggle", () -> showBlockDebug = !showBlockDebug);
|
||||||
|
row();
|
||||||
new button("paths", "toggle", () -> showPaths = !showPaths);
|
new button("paths", "toggle", () -> showPaths = !showPaths);
|
||||||
row();
|
row();
|
||||||
new button("infammo", "toggle", () -> infiniteAmmo = !infiniteAmmo);
|
new button("infammo", "toggle", () -> infiniteAmmo = !infiniteAmmo);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|||||||
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 com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
|
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.graphics.Fx;
|
import io.anuke.mindustry.graphics.Fx;
|
||||||
@@ -20,9 +21,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
|||||||
import io.anuke.ucore.util.Bundles;
|
import io.anuke.ucore.util.Bundles;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.state;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
import static io.anuke.mindustry.Vars.syncBlockState;
|
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
|
||||||
|
|
||||||
public class Block{
|
public class Block{
|
||||||
private static int lastid;
|
private static int lastid;
|
||||||
@@ -301,6 +300,20 @@ public class Block{
|
|||||||
return blocks.get(id);
|
return blocks.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Array<Object> getDebugInfo(Tile tile){
|
||||||
|
return Array.with(
|
||||||
|
"block", tile.block().name,
|
||||||
|
"floor", tile.floor().name,
|
||||||
|
"x", tile.x,
|
||||||
|
"y", tile.y,
|
||||||
|
"entity.name", ClassReflection.getSimpleName(tile.entity.getClass()),
|
||||||
|
"entity.x", tile.entity.x,
|
||||||
|
"entity.y", tile.entity.y,
|
||||||
|
"entity.id", tile.entity.id,
|
||||||
|
"entity.items.total", tile.entity.totalItems()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return name;
|
return name;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.world;
|
|||||||
|
|
||||||
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 com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.world.blocks.Blocks;
|
import io.anuke.mindustry.world.blocks.Blocks;
|
||||||
import io.anuke.ucore.util.Bits;
|
import io.anuke.ucore.util.Bits;
|
||||||
@@ -285,7 +286,7 @@ public class Tile{
|
|||||||
Block block = block();
|
Block block = block();
|
||||||
Block floor = floor();
|
Block floor = floor();
|
||||||
|
|
||||||
return floor.name() + ":" + block.name() + "[" + x + "," + y + "] " + "entity=" + entity +
|
return floor.name() + ":" + block.name() + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : ClassReflection.getSimpleName(entity.getClass())) +
|
||||||
(link != 0 ? " link=[" + (Bits.getLeftByte(link) - 8) + ", " + (Bits.getRightByte(link) - 8) + "]" : "");
|
(link != 0 ? " link=[" + (Bits.getLeftByte(link) - 8) + ", " + (Bits.getRightByte(link) - 8) + "]" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.NumberUtils;
|
import com.badlogic.gdx.utils.NumberUtils;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
|
import io.anuke.ucore.function.Consumer;
|
||||||
import io.anuke.ucore.util.Bits;
|
import io.anuke.ucore.util.Bits;
|
||||||
|
|
||||||
public class Junction extends Block{
|
public class Junction extends Block{
|
||||||
@@ -82,6 +84,36 @@ public class Junction extends Block{
|
|||||||
return new JunctionEntity();
|
return new JunctionEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Array<Object> getDebugInfo(Tile tile){
|
||||||
|
JunctionEntity entity = tile.entity();
|
||||||
|
Array<Object> arr = super.getDebugInfo(tile);
|
||||||
|
for(int i = 0; i < 4; i ++){
|
||||||
|
arr.add("nearby." + i);
|
||||||
|
arr.add(tile.getNearby(i));
|
||||||
|
}
|
||||||
|
Consumer<Buffer> write = b -> {
|
||||||
|
for(int i = 0; i < b.index; i++){
|
||||||
|
long l = b.items[i];
|
||||||
|
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
|
||||||
|
int val = Bits.getRightInt(l);
|
||||||
|
Item item = Item.getByID(Bits.getLeftShort(val));
|
||||||
|
int direction = Bits.getRightShort(val);
|
||||||
|
Tile dest = tile.getNearby(direction);
|
||||||
|
arr.add(" bufferx.item");
|
||||||
|
arr.add(time + " | " + item.name + " | " + dest.block() + ":" + dest.floor());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
arr.add("buffer.bx");
|
||||||
|
arr.add(entity.bx.index);
|
||||||
|
write.accept(entity.bx);
|
||||||
|
arr.add("buffer.by");
|
||||||
|
arr.add(entity.bx.index);
|
||||||
|
write.accept(entity.by);
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
class JunctionEntity extends TileEntity{
|
class JunctionEntity extends TileEntity{
|
||||||
Buffer bx = new Buffer();
|
Buffer bx = new Buffer();
|
||||||
Buffer by = new Buffer();
|
Buffer by = new Buffer();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import io.anuke.mindustry.net.Packets.ChatPacket;
|
|||||||
import io.anuke.mindustry.net.Packets.KickReason;
|
import io.anuke.mindustry.net.Packets.KickReason;
|
||||||
import io.anuke.mindustry.ui.fragments.DebugFragment;
|
import io.anuke.mindustry.ui.fragments.DebugFragment;
|
||||||
import io.anuke.mindustry.world.Map;
|
import io.anuke.mindustry.world.Map;
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.*;
|
import io.anuke.ucore.core.*;
|
||||||
import io.anuke.ucore.modules.Module;
|
import io.anuke.ucore.modules.Module;
|
||||||
import io.anuke.ucore.util.CommandHandler;
|
import io.anuke.ucore.util.CommandHandler;
|
||||||
@@ -315,6 +316,33 @@ public class ServerControl extends Module {
|
|||||||
handler.register("info", "Print debug info", arg -> {
|
handler.register("info", "Print debug info", arg -> {
|
||||||
info(DebugFragment.debugInfo());
|
info(DebugFragment.debugInfo());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
handler.register("trace", "<x> <y>", "Prints debug info about a block", arg -> {
|
||||||
|
try{
|
||||||
|
int x = Integer.parseInt(arg[0]);
|
||||||
|
int y = Integer.parseInt(arg[1]);
|
||||||
|
Tile tile = world.tile(x, y);
|
||||||
|
if(tile != null){
|
||||||
|
if(tile.entity != null){
|
||||||
|
Array<Object> arr = tile.block().getDebugInfo(tile);
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for(int i = 0; i < arr.size/2; i ++){
|
||||||
|
result.append(arr.get(i*2));
|
||||||
|
result.append(": ");
|
||||||
|
result.append(arr.get(i*2 + 1));
|
||||||
|
result.append("\n");
|
||||||
|
}
|
||||||
|
Log.info("&ly{0}", result);
|
||||||
|
}else{
|
||||||
|
Log.info("No tile entity for that block.");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
Log.info("No tile at that location.");
|
||||||
|
}
|
||||||
|
}catch (NumberFormatException e){
|
||||||
|
Log.err("Invalid coordinates passed.");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readCommands(){
|
private void readCommands(){
|
||||||
|
|||||||
Reference in New Issue
Block a user