1 module re.ng.diag.debugger; 2 3 import re.core; 4 import re.ecs; 5 import re.input.input; 6 import re.math; 7 import re.gfx; 8 import re.gfx.render_ext; 9 import re.ng.diag.console; 10 import re.ng.diag.inspector; 11 static import raylib; 12 static import raygui; 13 14 /// a robust overlay debugging tool 15 debug class Debugger { 16 public enum screen_padding = 12; 17 private enum bg_col = Color(180, 180, 180, 180); 18 private raylib.RenderTexture2D _render_target; 19 private enum _render_col = Color(255, 255, 255, 160); 20 21 /// inspector panel 22 public static Inspector inspector; 23 24 /// debug console 25 public static Console console; 26 27 /// sets up debugger 28 this() { 29 inspector = new Inspector(); 30 console = new Console(); 31 if (!Core.headless) { 32 _render_target = raylib.LoadRenderTexture(Core.window.width, Core.window.height); 33 } 34 } 35 36 public void update() { 37 if (Input.is_key_pressed(console.key)) { 38 Core.debug_render = !Core.debug_render; 39 console.open = !console.open; 40 } 41 42 if (inspector.open) 43 inspector.update(); 44 if (console.open) 45 console.update(); 46 } 47 48 public void render() { 49 raylib.BeginTextureMode(_render_target); 50 raylib.ClearBackground(Colors.BLANK); 51 if (inspector.open) 52 inspector.render(); 53 if (console.open) 54 console.render(); 55 raylib.EndTextureMode(); 56 57 // draw render target 58 RenderExt.draw_render_target(_render_target, Rectangle(0, 0, 59 Core.window.width, Core.window.height), _render_col); 60 } 61 62 /// clean up 63 public void destroy() { 64 if (inspector.open) { 65 inspector.close(); 66 } 67 raylib.UnloadRenderTexture(_render_target); 68 } 69 }