Files
dusk/archive/dusksdl2/display/ui/renderfps.c
2025-08-20 19:18:38 -05:00

46 lines
1.1 KiB
C

/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "renderfps.h"
#include "display/render.h"
#include "display/ui/rendertext.h"
#include "time.h"
#include "game.h"
float_t RENDER_FPS_AVG = -1.0f;
float_t RENDER_TPS_AVG = -1.0f;
void renderFPSDraw(void) {
if(TIME.delta > 0) {
float_t fps = 1.0f / TIME.realDelta;
if(RENDER_FPS_AVG == -1.0f) {
RENDER_FPS_AVG = fps;
} else {
RENDER_FPS_AVG = (RENDER_FPS_AVG + fps) / 2.0f;
}
}
if(TIME.time != TIME.lastTick) {
float_t timeSinceLastTick = TIME.realTime - TIME.lastTick;
float_t tps = 1.0f / timeSinceLastTick;
if(RENDER_TPS_AVG == -1.0f) {
RENDER_TPS_AVG = tps;
} else {
RENDER_TPS_AVG = (RENDER_TPS_AVG + tps) / 2.0f;
}
}
char_t buffer[64];
snprintf(buffer, sizeof(buffer), "%.1f/%.1f", RENDER_FPS_AVG, RENDER_TPS_AVG);
int32_t width, height;
renderTextMeasure(buffer, &width, &height);
renderTextDraw(RENDER_WIDTH - width, 0, buffer, 0x00, 0xFF, 0x00);
}