Add more debug
This commit is contained in:
95
src/ui/uidebug.c
Normal file
95
src/ui/uidebug.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* 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[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;
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%.2f/%.2f/%d",
|
||||
TIME.dynamicDelta * 1000.0f,
|
||||
TIME.delta * 1000.0f,
|
||||
(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),
|
||||
"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();
|
||||
}
|
||||
Reference in New Issue
Block a user