Debug renderer for unit hitboxes
This commit is contained in:
@@ -1393,6 +1393,7 @@ keybind.chat_scroll.name = Chat Scroll
|
|||||||
keybind.chat_mode.name = Change Chat Mode
|
keybind.chat_mode.name = Change Chat Mode
|
||||||
keybind.drop_unit.name = Drop Unit
|
keybind.drop_unit.name = Drop Unit
|
||||||
keybind.zoom_minimap.name = Zoom Minimap
|
keybind.zoom_minimap.name = Zoom Minimap
|
||||||
|
keybind.detach_camera.name = Toggle Free Camera
|
||||||
mode.help.title = Description of modes
|
mode.help.title = Description of modes
|
||||||
mode.survival.name = Survival
|
mode.survival.name = Survival
|
||||||
mode.survival.description = The normal mode. Limited resources and automatic incoming waves.\n[gray]Requires enemy spawns in the map to play.
|
mode.survival.description = The normal mode. Limited resources and automatic incoming waves.\n[gray]Requires enemy spawns in the map to play.
|
||||||
|
|||||||
@@ -202,6 +202,8 @@ public class Vars implements Loadable{
|
|||||||
/** Whether to draw shadows of blocks at map edges and static blocks.
|
/** Whether to draw shadows of blocks at map edges and static blocks.
|
||||||
* Do not change unless you know exactly what you are doing.*/
|
* Do not change unless you know exactly what you are doing.*/
|
||||||
public static boolean enableDarkness = true;
|
public static boolean enableDarkness = true;
|
||||||
|
/** Whether to draw debug lines for collisions. */
|
||||||
|
public static boolean drawCollisionDebug = false;
|
||||||
/** application data directory, equivalent to {@link Settings#getDataDirectory()} */
|
/** application data directory, equivalent to {@link Settings#getDataDirectory()} */
|
||||||
public static Fi dataDirectory;
|
public static Fi dataDirectory;
|
||||||
/** data subdirectory used for screenshots */
|
/** data subdirectory used for screenshots */
|
||||||
|
|||||||
@@ -415,6 +415,10 @@ public class Renderer implements ApplicationListener{
|
|||||||
|
|
||||||
Groups.draw.draw(Drawc::draw);
|
Groups.draw.draw(Drawc::draw);
|
||||||
|
|
||||||
|
if(drawCollisionDebug){
|
||||||
|
DebugCollisionRenderer.draw();
|
||||||
|
}
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
Draw.flush();
|
Draw.flush();
|
||||||
Draw.sort(false);
|
Draw.sort(false);
|
||||||
|
|||||||
71
core/src/mindustry/graphics/DebugCollisionRenderer.java
Normal file
71
core/src/mindustry/graphics/DebugCollisionRenderer.java
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package mindustry.graphics;
|
||||||
|
|
||||||
|
import arc.*;
|
||||||
|
import arc.graphics.*;
|
||||||
|
import arc.graphics.g2d.*;
|
||||||
|
import arc.math.*;
|
||||||
|
import arc.math.geom.*;
|
||||||
|
import arc.util.*;
|
||||||
|
import mindustry.core.*;
|
||||||
|
import mindustry.gen.*;
|
||||||
|
import mindustry.world.*;
|
||||||
|
|
||||||
|
import static arc.Core.*;
|
||||||
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
|
public class DebugCollisionRenderer{
|
||||||
|
|
||||||
|
public static void draw(){
|
||||||
|
Rect rect = camera.bounds(new Rect());
|
||||||
|
Draw.draw(Layer.overlayUI, () -> {
|
||||||
|
//hitboxes
|
||||||
|
Draw.color(Color.green, 0.3f);
|
||||||
|
Groups.draw.each(d -> {
|
||||||
|
if(d instanceof Hitboxc h && rect.overlaps(Tmp.r1.setCentered(d.x(), d.y(), d.clipSize()))){
|
||||||
|
Fill.square(d.x(), d.y(), h.hitSize()/2f);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//tile hitboxes for units
|
||||||
|
Lines.stroke(0.3f, Color.magenta);
|
||||||
|
|
||||||
|
int rx = Mathf.clamp((int)(Core.camera.width / tilesize / 2) + 1, 0, world.width()/2);
|
||||||
|
int ry = Mathf.clamp((int)(Core.camera.height / tilesize / 2) + 1, 0, world.height()/2);
|
||||||
|
|
||||||
|
for(int x = -rx; x <= rx; x++){
|
||||||
|
for(int y = -ry; y <= ry; y++){
|
||||||
|
int wx = World.toTile(Core.camera.position.x) + x;
|
||||||
|
int wy = World.toTile(Core.camera.position.y) + y;
|
||||||
|
Tile tile = world.tile(wx, wy);
|
||||||
|
if(tile != null && tile.solid()){
|
||||||
|
Draw.color(tile.legSolid() ? Color.pink : Color.magenta);
|
||||||
|
Lines.rect(wx * tilesize - tilesize/2f, wy * tilesize - tilesize/2f, tilesize, tilesize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Groups.draw.each(d -> {
|
||||||
|
if(d instanceof Unit u && rect.overlaps(Tmp.r1.setCentered(u.x, u.y, d.clipSize()))){
|
||||||
|
u.hitboxTile(Tmp.r1);
|
||||||
|
|
||||||
|
Lines.rect(Tmp.r1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Lines.stroke(0.5f);
|
||||||
|
//physics
|
||||||
|
Draw.color(Color.red, 0.5f);
|
||||||
|
Groups.draw.each(d -> {
|
||||||
|
if(d instanceof Unit u && rect.overlaps(Tmp.r1.setCentered(u.x, u.y, u.clipSize()))){
|
||||||
|
Lines.circle(u.x, u.y, u.hitSize * unitCollisionRadiusScale);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Draw.reset();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Draw.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user