diff --git a/gfx/fonts/Roboto-Medium.ttf b/gfx/fonts/Roboto-Medium.ttf new file mode 100644 index 0000000..aa00de0 Binary files /dev/null and b/gfx/fonts/Roboto-Medium.ttf differ diff --git a/src/main.c b/src/main.c index 06518f2..53a4fb5 100644 --- a/src/main.c +++ b/src/main.c @@ -25,7 +25,7 @@ static void handleCommandLine(int argc, const char *argv[]); int main(int argc, const char *argv[]) { - long then, nextSecond; + long then, nextSecond, frames; atexit(cleanup); @@ -39,6 +39,8 @@ int main(int argc, const char *argv[]) handleCommandLine(argc, argv); + frames = 0; + nextSecond = SDL_GetTicks() + 1000; while (1) @@ -57,8 +59,14 @@ int main(int argc, const char *argv[]) then = capFrameRate(then); + frames++; + if (SDL_GetTicks() >= nextSecond) { + dev.fps = frames; + + frames = 0; + game.timePlayed++; nextSecond = SDL_GetTicks() + 1000; diff --git a/src/system/atlas.c b/src/system/atlas.c index e1fb47e..30b65e8 100644 --- a/src/system/atlas.c +++ b/src/system/atlas.c @@ -36,6 +36,8 @@ void initAtlas(void) loadAtlasTexture(); loadAtlasData(); + + dev.debug = dev.showFPS = 1; } Atlas *getImageFromAtlas(char *filename) diff --git a/src/system/atlas.h b/src/system/atlas.h index 710798f..a190743 100644 --- a/src/system/atlas.h +++ b/src/system/atlas.h @@ -23,3 +23,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern Texture *getTexture(const char *filename); extern char *readFile(const char *filename); + +extern Dev dev; diff --git a/src/system/draw.c b/src/system/draw.c index 4e174ea..dd7e61d 100644 --- a/src/system/draw.c +++ b/src/system/draw.c @@ -48,6 +48,15 @@ void prepareScene(void) void presentScene(void) { + if (dev.debug) + { + drawText(5, SCREEN_HEIGHT - 25, 14, TA_LEFT, colors.white, "DEBUG MODE"); + if (dev.showFPS) + { + drawText(SCREEN_WIDTH - 5, SCREEN_HEIGHT - 25, 14, TA_RIGHT, colors.white, "FPS: %d", dev.fps); + } + } + SDL_SetRenderTarget(app.renderer, NULL); SDL_RenderCopy(app.renderer, app.backBuffer, NULL, NULL); SDL_RenderPresent(app.renderer); diff --git a/src/system/draw.h b/src/system/draw.h index 456adfa..ea42b66 100644 --- a/src/system/draw.h +++ b/src/system/draw.h @@ -20,5 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" +extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); + extern App app; extern Colors colors; +extern Dev dev; diff --git a/src/system/text.c b/src/system/text.c index 92ae42b..27ff076 100644 --- a/src/system/text.c +++ b/src/system/text.c @@ -297,7 +297,7 @@ static void loadFont(int size) { SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "loadFonts(%d)", size); - font[size] = TTF_OpenFont(getFileLocation("data/fonts/LiberationMono-Regular.ttf"), size); + font[size] = TTF_OpenFont(getFileLocation("gfx/fonts/Roboto-Medium.ttf"), size); } void destroyFonts(void)