Add a low FPS callback to aid in debugging, and fix a huge memory leak in akgl_text_rendertextat
This commit is contained in:
10
src/game.c
10
src/game.c
@@ -30,6 +30,12 @@ MIX_Track *akgl_tracks[AKGL_GAME_AUDIO_MAX_TRACKS];
|
||||
SDL_FRect camera;
|
||||
akgl_Game game;
|
||||
|
||||
void akgl_game_lowfps(void)
|
||||
{
|
||||
SDL_Log("Low FPS! %d", game.fps);
|
||||
return;
|
||||
}
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init()
|
||||
{
|
||||
int screenwidth = 0;
|
||||
@@ -42,6 +48,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init()
|
||||
game.gameStartTime = SDL_GetTicksNS();
|
||||
game.lastIterTime = game.gameStartTime;
|
||||
game.lastFPSTime = game.gameStartTime;
|
||||
game.lowfpsfunc = &akgl_game_lowfps;
|
||||
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");
|
||||
@@ -142,6 +149,9 @@ void akgl_game_updateFPS()
|
||||
game.framesSinceUpdate = 0;
|
||||
game.lastFPSTime = curTime;
|
||||
}
|
||||
if ( game.fps < 30 ) {
|
||||
game.lowfpsfunc();
|
||||
}
|
||||
game.framesSinceUpdate += 1;
|
||||
game.lastIterTime = curTime;
|
||||
}
|
||||
|
||||
@@ -56,5 +56,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_text_rendertextat(TTF_Font *font, char *
|
||||
SDL_GetTextureSize(texture, &dest.w, &dest.h);
|
||||
FAIL_ZERO_RETURN(errctx, SDL_RenderTexture(renderer, texture, NULL, &dest), AKERR_NULLPOINTER, "%s", SDL_GetError());
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_DestroySurface(textsurf);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user