# HG changeset patch # User Mike Pavone # Date 1380860525 25200 # Node ID db5880d8ea034595ffcfbb16b0746a92c9644f1c # Parent b449af228c6327e79fc75406b17551013cd74ec1 Add an FPS counter to the title bar diff -r b449af228c63 -r db5880d8ea03 render_sdl.c --- a/render_sdl.c Thu Oct 03 21:21:47 2013 -0700 +++ b/render_sdl.c Thu Oct 03 21:22:05 2013 -0700 @@ -93,6 +93,8 @@ return screen->format->BytesPerPixel * 8; } +char * caption = NULL; + void render_init(int width, int height, char * title, uint32_t fps, uint8_t fullscreen) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) { @@ -118,6 +120,7 @@ exit(1); } SDL_WM_SetCaption(title, title); + caption = title; min_delay = 0; for (int i = 0; i < 100; i++) { uint32_t start = SDL_GetTicks(); @@ -326,6 +329,8 @@ return 0; } +char * fps_caption = NULL; + uint32_t frame_counter = 0; uint32_t start = 0; int wait_render_frame(vdp_context * context, int frame_limit) @@ -349,18 +354,22 @@ } } render_context(context); - - + + //TODO: Figure out why this causes segfaults - /*frame_counter++; + frame_counter++; if ((last_frame - start) > 1000) { if (start && (last_frame-start)) { - printf("\r%f fps", ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); + if (!fps_caption) { + fps_caption = malloc(strlen(caption) + strlen(" - 1000.1 fps") + 1); + } + sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); + SDL_WM_SetCaption(fps_caption, caption); fflush(stdout); } start = last_frame; frame_counter = 0; - }*/ + } return ret; }