Show the FPS readout in the top right

This commit is contained in:
2026-05-06 11:13:06 -04:00
parent 4da733b5db
commit 32eeaf9769
2 changed files with 30 additions and 3 deletions

View File

@@ -16,6 +16,7 @@
#include <sdl3game/sprite.h>
#include <sdl3game/actor.h>
#include <sdl3game/registry.h>
#include <sdl3game/text.h>
int numsprites = 8;
char *spritepaths[] = {
@@ -145,6 +146,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
controlmap->controls[5].key = SDLK_M;
controlmap->controls[5].event_on = SDL_EVENT_KEY_DOWN;
controlmap->controls[5].handler_on = &music_toggle;
CATCH(errctx, text_loadFont("C64Pro", "assets/C64_Pro-STYLE.ttf", 18));
} CLEANUP {
} PROCESS(errctx) {
@@ -180,8 +183,11 @@ SDL_AppResult SDL_AppIterate(void *appstate)
//b2Vec2 position;
int i = 0;
iterator opflags;
char fpsText[32];
PREPARE_ERROR(errctx);
GAME_updateFPS();
BITMASK_CLEAR(opflags.flags);
BITMASK_ADD(opflags.flags, ITERATOR_OP_UPDATE);
@@ -200,7 +206,28 @@ SDL_AppResult SDL_AppIterate(void *appstate)
return SDL_APP_FAILURE;
} FINISH_NORETURN(errctx);
}
SDL_RenderPresent(renderer);
ATTEMPT {
memset((char *)&fpsText, 0x00, 32);
snprintf((char *)&fpsText, 31, "FPS : %d", game.fps);
CATCH(errctx, text_renderTextAt(
SDL_GetPointerProperty(
REGISTRY_FONT,
"C64Pro",
NULL),
(char *)&fpsText,
(SDL_Color){255, 255, 255, 255},
0,
450,
10)
);
} CLEANUP {
SDL_RenderPresent(renderer);
} PROCESS(errctx) {
} HANDLE_DEFAULT(errctx) {
LOG_ERROR(errctx);
return SDL_APP_FAILURE;
} FINISH_NORETURN(errctx);
return SDL_APP_CONTINUE;
}