diff --git a/CMakeLists.txt b/CMakeLists.txt index 00b215cbc..ebba9b953 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ set(BINARY_NAME gbac CACHE INTERNAL "Name of output binaries") set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra -Wno-error=type-limits --std=gnu99") set(CMAKE_C_FLAGS_RELEASE "-O3 -Wall -Wextra --std=gnu99") set(USE_DEBUGGER ON CACHE BOOL "Whether or not to enable the ARM debugger") +set(EXTRA_LIB "") file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c) file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c) file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.c) @@ -42,7 +43,8 @@ endif() if(BUILD_PERF) set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c) + set(EXTRA_LIB ${EXTRA_LIB} rt) endif() add_executable(${BINARY_NAME} ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${PLATFORM_SRC} ${MAIN_SRC}) -target_link_libraries(${BINARY_NAME} m pthread ${DEBUGGER_LIB} ${SDL_LIBRARY} ${OPENGL_LIBRARY}) +target_link_libraries(${BINARY_NAME} m pthread ${DEBUGGER_LIB} ${SDL_LIBRARY} ${OPENGL_LIBRARY} ${EXTRA_LIB}) diff --git a/src/platform/perf-main.c b/src/platform/perf-main.c index dde8f65f5..5e71c5565 100644 --- a/src/platform/perf-main.c +++ b/src/platform/perf-main.c @@ -62,9 +62,25 @@ int main(int argc, char** argv) { } static void _GBAPerfRunloop(struct GBAThread* context, int* frames) { + struct timespec lastEcho; + clock_gettime(CLOCK_REALTIME, &lastEcho); + int lastFrames = 0; while (context->state < THREAD_EXITING) { if (GBASyncWaitFrameStart(&context->sync, 0)) { ++*frames; + ++lastFrames; + struct timespec currentTime; + long timeDiff; + clock_gettime(CLOCK_REALTIME, ¤tTime); + timeDiff = currentTime.tv_sec - lastEcho.tv_sec; + timeDiff *= 1000; + timeDiff += (currentTime.tv_nsec - lastEcho.tv_nsec) / 1000000; + if (timeDiff >= 1000) { + printf("\033[2K\rCurrent FPS: %g (%gx)", lastFrames / (timeDiff / 1000.0f), lastFrames / (float) (60 * (timeDiff / 1000.0f))); + fflush(stdout); + lastEcho = currentTime; + lastFrames = 0; + } } GBASyncWaitFrameEnd(&context->sync); }