1 /** provides runtime debugging functionality in an overlay */ 2 3 module re.ng.diag.debugger; 4 5 import std.format; 6 7 import re.core; 8 import re.ecs; 9 import re.input.input; 10 import re.math; 11 import re.gfx; 12 import re.gfx.render_ext; 13 import re.ng.diag.console; 14 import re.ng.diag.inspector; 15 static import raylib; 16 static import raygui; 17 18 /// a robust overlay debugging tool 19 debug class Debugger { 20 public enum screen_padding = 12; 21 public Rectangle ui_bounds; 22 private enum bg_col = Color(180, 180, 180, 180); 23 private RenderTarget _render_target; 24 private enum _render_col = Color(255, 255, 255, 160); 25 26 /// inspector panel 27 public static Inspector inspector; 28 29 /// debug console 30 public static Console console; 31 32 /// sets up debugger 33 this() { 34 inspector = new Inspector(); 35 console = new Console(); 36 if (!Core.headless) { 37 ui_bounds = Rectangle(0, 0, Core.window.width, Core.window.height); 38 _render_target = RenderExt.create_render_target(cast(int) ui_bounds.width, cast(int) ui_bounds 39 .height); 40 Core.log.info(format("debugger info: ui bounds %s, resolution %s, window (%s,%s)", 41 ui_bounds, Core.default_resolution, Core.window.width, Core.window.height)); 42 } 43 } 44 45 public void update() { 46 if (!Core.headless) { 47 // auto-resize inspector 48 inspector.width = cast(int)(ui_bounds.width * 0.7); 49 } 50 51 if (Input.is_key_pressed(console.key)) { 52 Core.debug_render = !Core.debug_render; 53 console.open = !console.open; 54 } 55 56 if (inspector.open) 57 inspector.update(); 58 if (console.open) 59 console.update(); 60 } 61 62 public void render() { 63 raylib.BeginTextureMode(_render_target); 64 raylib.ClearBackground(Colors.BLANK); 65 if (inspector.open) 66 inspector.render(); 67 if (console.open) 68 console.render(); 69 raylib.EndTextureMode(); 70 71 // draw render target 72 RenderExt.draw_render_target(_render_target, Rectangle(0, 0, 73 Core.window.width, Core.window.height), _render_col); 74 } 75 76 /// clean up 77 public void destroy() { 78 if (inspector.open) { 79 inspector.close(); 80 } 81 RenderExt.destroy_render_target(_render_target); 82 } 83 }