Files
dusk/src/ui/uidebug.c
Dominic Masters af5bf987c8
All checks were successful
Build Dusk / run-tests (push) Successful in 2m12s
Build Dusk / build-linux (push) Successful in 1m49s
Build Dusk / build-psp (push) Successful in 1m52s
Add inventory.
2026-01-06 07:47:16 -06:00

98 lines
2.2 KiB
C

/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#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_DEBUG_DRAW = true;
void uiDebugRender(const tileset_t *tileset, texture_t *texture) {
if(!UI_DEBUG_DRAW) return;
char_t buffer[128];
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;
snprintf(
buffer,
sizeof(buffer),
"%.2f/%.2f/%d/%d",
TIME.dynamicDelta * 1000.0f,
TIME.delta * 1000.0f,
TIME.dynamicUpdate,
(int32_t)fpsDynamic
);
color = (
fpsDynamic >= 50.0f ? COLOR_GREEN :
fpsDynamic >= 30.0f ? COLOR_YELLOW :
COLOR_RED
);
#else
float_t fps = TIME.delta > 0.0f ? (1.0f / TIME.delta) : 0.0f;
snprintf(
buffer,
sizeof(buffer),
"%.2f/%d/FXD",
TIME.delta * 1000.0f,
(int32_t)fps
);
color = (
fps >= 50.0f ? COLOR_GREEN :
fps >= 30.0f ? COLOR_YELLOW :
COLOR_RED
);
#endif
uiTextMeasure(buffer, tileset, &w, &h);
uiTextDraw(
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),
// "%d,%d,%d/%d/%d",
// player->position.x,
// player->position.y,
// player->position.z,
// (int32_t)player->direction,
// (int32_t)player->animation
// );
// }
// uiTextMeasure(buffer, tileset, &w, &h);
// uiTextDraw(
// SCREEN.width - w, hOffset,
// buffer, COLOR_GREEN, tileset, texture
// );
// hOffset += h;
spriteBatchFlush();
}