FPS toggle

This commit is contained in:
2025-09-11 22:25:57 -05:00
parent 268e9ffefd
commit b4d94c2cbe
5 changed files with 20 additions and 4 deletions

View File

@@ -13,4 +13,4 @@ bind enter accept;
bind q cancel;
bind esc quit;
bind f1 togglefps;
fps 1;

View File

@@ -15,7 +15,7 @@ void cmdSet(const consolecmdexec_t *exec) {
consolevar_t *var = &CONSOLE.variables[i];
if(stringCompare(var->name, exec->argv[0]) != 0) continue;
consoleVarSetValue(var, exec->argv[1]);
consolePrint("%s %s", var->name, var->value);
// consolePrint("%s %s", var->name, var->value);
for(i = 0; i < var->eventCount; i++) {
assertNotNull(var->events[i], "Event is NULL");
var->events[i](var);

View File

@@ -34,6 +34,8 @@ errorret_t uiInit(void) {
UI.scale = 2.0f;
uiFPSInit();
errorOk();
}

View File

@@ -8,10 +8,20 @@
#include "uifps.h"
#include "display/ui/uitext.h"
#include "time/time.h"
#include "console/console.h"
#include "util/string.h"
void uiFPSInit(void) {
consoleRegVar("fps", "1", NULL);
}
void uiFPSRender(void) {
float_t fps = TIME.delta > 0.0f ? (1.0f / TIME.delta) : 0.0f;
if(stringCompare(consoleVarGet("fps")->value, "0") == 0) {
return;
}
char_t buffer[64];
snprintf(
buffer,
@@ -20,8 +30,11 @@ void uiFPSRender(void) {
(int32_t)fps
);
color_t color = fps >= 50.0f ? COLOR_GREEN :
(fps >= 30.0f ? COLOR_YELLOW : COLOR_RED);
color_t color = (
fps >= 50.0f ? COLOR_GREEN :
fps >= 30.0f ? COLOR_YELLOW :
COLOR_RED
);
uiTextDraw(0, 0, buffer, color);
}

View File

@@ -8,4 +8,5 @@
#pragma once
#include "dusk.h"
void uiFPSInit(void);
void uiFPSRender(void);