From 0df61f5a7699b65340cee8e10107a7a76ec3e260 Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Wed, 15 Jul 2026 08:18:49 +0200 Subject: [PATCH] Refined debug to only work in debug mode + dedicated struct --- src/debug.odin | 83 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/src/debug.odin b/src/debug.odin index fd2ac07..a055d9a 100644 --- a/src/debug.odin +++ b/src/debug.odin @@ -2,33 +2,84 @@ package game import rl "vendor:raylib" -debug_init :: proc() { - rl.TraceLog(.INFO, "Game initialized") +Debug :: struct { + active: bool, + bounds_active: bool, + camera_active: bool, + camera: rl.Camera2D, +} + +debug_init :: proc(game: ^Game) { + when DEBUG_MODE { + game.debug.active = true + game.debug.camera_active = false + game.debug.camera = debug_camera_init(game.player) + + log_info("!! Debug Mode Enabled") + } } debug_fps :: proc() { - if !DEBUG_MODE do return - rl.DrawFPS(20, 20) + when DEBUG_MODE { + rl.DrawFPS(20, 20) + } } // DEBUG CAMERA debug_camera_init :: proc(player: Player) -> rl.Camera2D { - offset_adjust := (TILE_SIZE / 2) * 0.3 + when !DEBUG_MODE { return rl.Camera2D{} } - return rl.Camera2D { - target = player.pos, - offset = rl.Vector2{ f32(GAME_WIDTH/2 - offset_adjust), f32(GAME_HEIGHT/2 - offset_adjust) }, - rotation = 0, - zoom = 0.3 + when DEBUG_MODE { + offset_adjust := (TILE_SIZE / 2) * 0.3 + + return rl.Camera2D { + target = player.pos, + offset = rl.Vector2{ f32(GAME_WIDTH/2 - offset_adjust), f32(GAME_HEIGHT/2 - offset_adjust) }, + rotation = 0, + zoom = 0.3 + } } } -update_debug_camera :: proc(camera: ^rl.Camera2D) { - if rl.IsKeyDown(.LEFT_CONTROL) { - scroll := rl.GetMouseWheelMove() - if scroll != 0.0 { - camera.zoom += scroll * 0.1 - } +debug_camera_update :: proc(debug: ^Debug) { + when DEBUG_MODE { + if rl.IsKeyPressed(.ONE) { + debug.camera_active = !debug.camera_active + } + + if rl.IsKeyPressed(.TWO) { + debug.bounds_active = !debug.bounds_active + } + + if rl.IsKeyDown(.LEFT_CONTROL) { + scroll := rl.GetMouseWheelMove() + if scroll != 0.0 { + debug.camera.zoom += scroll * 0.1 + } + } } } +debug_camera_draw :: proc(camera: ^rl.Camera2D, active: bool) { + when DEBUG_MODE { + if active { + view_width := GAME_WIDTH / camera.zoom + view_height := GAME_HEIGHT / camera.zoom + + top_left := camera.target - rl.Vector2{ f32(view_width)/2, f32(view_height)/2 } + + rl.DrawRectangleLines(i32(top_left.x), i32(top_left.y), i32(view_width), i32(view_height), rl.RED) + } + } +} + +// Collision stuff +debug_bounds :: proc(game: ^Game) { + when DEBUG_MODE { + if game.debug.bounds_active { + // player + player := game.player + rl.DrawRectangleLines( i32(player.pos.x - (TILE_SIZE / 2)), i32(player.pos.y - (TILE_SIZE / 2)), TILE_SIZE, TILE_SIZE, rl.GREEN) + } + } +}