From e2ce809762ad450ff350ba206f1b68492ddfab0a Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 9 Nov 2025 19:04:40 -0600 Subject: [PATCH] Add more debug --- src/scene/scene/scenemap.c | 2 -- src/ui/CMakeLists.txt | 2 +- src/ui/ui.c | 4 +-- src/ui/{uifps.c => uidebug.c} | 47 +++++++++++++++++++++++++++++------ src/ui/{uifps.h => uidebug.h} | 4 +-- 5 files changed, 44 insertions(+), 15 deletions(-) rename src/ui/{uifps.c => uidebug.c} (56%) rename src/ui/{uifps.h => uidebug.h} (76%) diff --git a/src/scene/scene/scenemap.c b/src/scene/scene/scenemap.c index ce3698b..360dcc5 100644 --- a/src/scene/scene/scenemap.c +++ b/src/scene/scene/scenemap.c @@ -120,8 +120,6 @@ void sceneMapRender(scenedata_t *data) { cameraPopMatrix(); } - - void sceneMapRenderEntity(entity_t *entity) { assertNotNull(entity, "Entity cannot be NULL"); diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index a877b34..c46cc1d 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -8,7 +8,7 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE ui.c uitext.c - uifps.c + uidebug.c uiframe.c uitextbox.c ) \ No newline at end of file diff --git a/src/ui/ui.c b/src/ui/ui.c index 0f2a1f2..d575ea5 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -7,7 +7,7 @@ #include "ui.h" #include "assert/assert.h" -#include "ui/uifps.h" +#include "ui/uidebug.h" #include "util/memory.h" #include "display/tileset/tileset_minogram.h" #include "display/screen.h" @@ -41,7 +41,7 @@ void uiRender(void) { // Render UI elements here if(UI.fontTexture.width > 0) { - uiFPSRender(UI.fontTileset, &UI.fontTexture); + uiDebugRender(UI.fontTileset, &UI.fontTexture); uiTextboxRender(); } cameraPopMatrix(); diff --git a/src/ui/uifps.c b/src/ui/uidebug.c similarity index 56% rename from src/ui/uifps.c rename to src/ui/uidebug.c index 82e9a9e..6073ad2 100644 --- a/src/ui/uifps.c +++ b/src/ui/uidebug.c @@ -5,21 +5,24 @@ * https://opensource.org/licenses/MIT */ -#include "uifps.h" +#include "uidebug.h" #include "time/time.h" #include "util/string.h" #include "ui/uitext.h" #include "display/screen.h" #include "display/spritebatch.h" +#include "rpg/entity/entity.h" -bool_t UI_FPS_DRAW = true; +bool_t UI_DEBUG_DRAW = true; -void uiFPSRender(const tileset_t *tileset, texture_t *texture) { - if(!UI_FPS_DRAW) return; +void uiDebugRender(const tileset_t *tileset, texture_t *texture) { + if(!UI_DEBUG_DRAW) return; char_t buffer[96]; color_t color; + int32_t w, h, hOffset = 0; + // FPS Meter #if TIME_FIXED == 0 float_t fpsDynamic = TIME.dynamicDelta > 0.0f ? (1.0f / TIME.dynamicDelta) : 0.0f; float_t fpsFixed = TIME.delta > 0.0f ? (1.0f / TIME.delta) : 0.0f; @@ -42,7 +45,7 @@ void uiFPSRender(const tileset_t *tileset, texture_t *texture) { snprintf( buffer, sizeof(buffer), - "%.2f/%d", + "%.2f/%d/FXD", TIME.delta * 1000.0f, (int32_t)fps ); @@ -53,12 +56,40 @@ void uiFPSRender(const tileset_t *tileset, texture_t *texture) { COLOR_RED ); #endif - - int32_t w, h; + uiTextMeasure(buffer, tileset, &w, &h); uiTextDraw( - SCREEN.width - w, 0, + SCREEN.width - w, hOffset, buffer, color, tileset, texture ); + hOffset += h; + + // Player position + entity_t *player = NULL; + for(uint8_t i = 0; i < ENTITY_COUNT; i++) { + if(ENTITIES[i].type != ENTITY_TYPE_PLAYER) continue; + player = &ENTITIES[i]; + break; + } + if(player == NULL) { + snprintf(buffer, sizeof(buffer), "Player: N/A"); + } else { + snprintf( + buffer, + sizeof(buffer), + "Player: (%d, %d) Dir:%d Anim:%d", + player->position.x, + player->position.y, + (int32_t)player->direction, + (int32_t)player->animation + ); + } + uiTextMeasure(buffer, tileset, &w, &h); + uiTextDraw( + SCREEN.width - w, hOffset, + buffer, COLOR_WHITE, tileset, texture + ); + hOffset += h; + spriteBatchFlush(); } \ No newline at end of file diff --git a/src/ui/uifps.h b/src/ui/uidebug.h similarity index 76% rename from src/ui/uifps.h rename to src/ui/uidebug.h index 24823f0..3f106df 100644 --- a/src/ui/uifps.h +++ b/src/ui/uidebug.h @@ -10,9 +10,9 @@ #include "display/texture.h" /** - * Renders the FPS counter UI. + * Renders the debug information UI element. * * @param tileset The tileset to use for rendering text. * @param texture The texture associated with the tileset. */ -void uiFPSRender(const tileset_t *tileset, texture_t *texture); \ No newline at end of file +void uiDebugRender(const tileset_t *tileset, texture_t *texture); \ No newline at end of file