Added a font registry, a text rendering helper, and an FPS counter function

This commit is contained in:
2026-05-06 11:12:42 -04:00
parent 284ffd7b4a
commit c3847160da
9 changed files with 81 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
#include <SDL3/SDL.h>
#include <SDL3_image/SDL_image.h>
#include <SDL3_mixer/SDL_mixer.h>
#include <SDL3_ttf/SDL_ttf.h>
#include <stdio.h>
#include <akerror.h>
@@ -32,6 +33,9 @@ akerr_ErrorContext AKERR_NOIGNORE *GAME_init()
int i = 0;
PREPARE_ERROR(errctx);
ATTEMPT {
game.gameStartTime = SDL_GetTicksNS();
game.lastIterTime = game.gameStartTime;
game.lastFPSTime = game.gameStartTime;
FAIL_ZERO_BREAK(errctx, strlen((char *)&game.name), AKERR_NULLPOINTER, "Must provide game name");
FAIL_ZERO_BREAK(errctx, strlen((char *)&game.version), AKERR_NULLPOINTER, "Must provide game version");
FAIL_ZERO_BREAK(errctx, strlen((char *)&game.uri), AKERR_NULLPOINTER, "Must provide game uri");
@@ -40,6 +44,8 @@ akerr_ErrorContext AKERR_NOIGNORE *GAME_init()
CATCH(errctx, registry_init_sprite());
CATCH(errctx, registry_init_spritesheet());
CATCH(errctx, registry_init_character());
CATCH(errctx, registry_init_font());
CATCH(errctx, registry_init_music());
CATCH(errctx, registry_init_actor_state_strings());
} CLEANUP {
} PROCESS(errctx) {
@@ -87,9 +93,28 @@ akerr_ErrorContext AKERR_NOIGNORE *GAME_init()
"Unable to create mixer device: %s",
SDL_GetError());
FAIL_ZERO_RETURN(
errctx,
TTF_Init(),
AKERR_SDL,
"Couldn't initialize front engine: %s",
SDL_GetError());
camera.x = 0;
camera.y = 0;
camera.w = game.screenwidth;
camera.h = game.screenheight;
camera.h = game.screenheight;
}
void GAME_updateFPS()
{
SDL_Time curTime;
curTime = SDL_GetTicksNS();
if ( (curTime - game.lastFPSTime) > TIME_ONESEC_NS ) {
game.fps = game.framesSinceUpdate;
game.framesSinceUpdate = 0;
game.lastFPSTime = curTime;
}
game.framesSinceUpdate += 1;
game.lastIterTime = curTime;
}