all repos — mgba @ 3005c6c9fb7bb9d91c1f4dde4ec7e88f99a1a620

mGBA Game Boy Advance Emulator

Add per-second perf updating
Jeffrey Pfau jeffrey@endrift.com
Mon, 04 Nov 2013 21:07:41 -0800
commit

3005c6c9fb7bb9d91c1f4dde4ec7e88f99a1a620

parent

3b74b61862da06b71d6cb256754f48feec409f7f

2 files changed, 19 insertions(+), 1 deletions(-)

jump to
M CMakeLists.txtCMakeLists.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})
M src/platform/perf-main.csrc/platform/perf-main.c

@@ -62,9 +62,25 @@ return 0;

} 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, &currentTime); + 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); }