From 8637f7ede3da174e2f559e2c2acb33ac6cfc38ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Wed, 17 Apr 2024 13:31:56 +0200 Subject: [PATCH] chg: centralise --capture to tests_captureframes() --- engine/joint/v4k.h | 18 ++++++++++++------ engine/split/v4k_main.c | 2 +- engine/split/v4k_window.c | 16 +++++++++++----- engine/v4k.c | 18 ++++++++++++------ 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index a901cd5..1707d46 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -392320,6 +392320,14 @@ void record_frame() { #line 0 #line 1 "v4k_window.c" +//----------------------------------------------------------------------------- +// capture tests +static +uint64_t tests_captureframes() { + static uint64_t capture_target; do_once capture_target = optioni("--capture", 0); + return capture_target; +} + //----------------------------------------------------------------------------- // fps locking @@ -392387,8 +392395,7 @@ int fps_wait() { } static void window_vsync(float hz) { - static uint64_t capture_target; do_once capture_target = optioni("--capture", 0); - if( capture_target ) return; + if( tests_captureframes() ) return; if( hz <= 0 ) return; do_once fps_locker(1); framerate = hz; @@ -392610,7 +392617,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) { int winWidth = window_canvas().w * scale; int winHeight = window_canvas().h * scale; - if (optioni("--capture", 0)) { + if (tests_captureframes()) { winWidth = 1280; winHeight = 720; } @@ -392989,8 +392996,7 @@ int window_swap() { } static uint64_t capture_frame = 0; - static uint64_t capture_target; do_once capture_target = optioni("--capture", 0); - if( cook_done && ++capture_frame == capture_target ) { + if( cook_done && ++capture_frame == tests_captureframes() ) { mkdir( "tests/out", 0777 ); const char *screenshot_file = va("tests/out/%s.png", app_name()); @@ -395721,7 +395727,7 @@ static void v4k_post_init(float refresh_rate) { glfwShowWindow(window); glfwGetFramebufferSize(window, &w, &h); //glfwGetWindowSize(window, &w, &h); - randset(time_ns() * !optioni("--capture",0)); + randset(time_ns() * !tests_captureframes()); boot_time = -time_ss(); // measure boot time, this is continued in window_stats() // clean any errno setup by cooking stage diff --git a/engine/split/v4k_main.c b/engine/split/v4k_main.c index abfb409..2e94666 100644 --- a/engine/split/v4k_main.c +++ b/engine/split/v4k_main.c @@ -40,7 +40,7 @@ static void v4k_post_init(float refresh_rate) { glfwShowWindow(window); glfwGetFramebufferSize(window, &w, &h); //glfwGetWindowSize(window, &w, &h); - randset(time_ns() * !optioni("--capture",0)); + randset(time_ns() * !tests_captureframes()); boot_time = -time_ss(); // measure boot time, this is continued in window_stats() // clean any errno setup by cooking stage diff --git a/engine/split/v4k_window.c b/engine/split/v4k_window.c index 9a1cc7d..3ed6979 100644 --- a/engine/split/v4k_window.c +++ b/engine/split/v4k_window.c @@ -1,3 +1,11 @@ +//----------------------------------------------------------------------------- +// capture tests +static +uint64_t tests_captureframes() { + static uint64_t capture_target; do_once capture_target = optioni("--capture", 0); + return capture_target; +} + //----------------------------------------------------------------------------- // fps locking @@ -65,8 +73,7 @@ int fps_wait() { } static void window_vsync(float hz) { - static uint64_t capture_target; do_once capture_target = optioni("--capture", 0); - if( capture_target ) return; + if( tests_captureframes() ) return; if( hz <= 0 ) return; do_once fps_locker(1); framerate = hz; @@ -288,7 +295,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) { int winWidth = window_canvas().w * scale; int winHeight = window_canvas().h * scale; - if (optioni("--capture", 0)) { + if (tests_captureframes()) { winWidth = 1280; winHeight = 720; } @@ -667,8 +674,7 @@ int window_swap() { } static uint64_t capture_frame = 0; - static uint64_t capture_target; do_once capture_target = optioni("--capture", 0); - if( cook_done && ++capture_frame == capture_target ) { + if( cook_done && ++capture_frame == tests_captureframes() ) { mkdir( "tests/out", 0777 ); const char *screenshot_file = va("tests/out/%s.png", app_name()); diff --git a/engine/v4k.c b/engine/v4k.c index 17b88ad..7f0622f 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -26860,6 +26860,14 @@ void record_frame() { #line 0 #line 1 "v4k_window.c" +//----------------------------------------------------------------------------- +// capture tests +static +uint64_t tests_captureframes() { + static uint64_t capture_target; do_once capture_target = optioni("--capture", 0); + return capture_target; +} + //----------------------------------------------------------------------------- // fps locking @@ -26927,8 +26935,7 @@ int fps_wait() { } static void window_vsync(float hz) { - static uint64_t capture_target; do_once capture_target = optioni("--capture", 0); - if( capture_target ) return; + if( tests_captureframes() ) return; if( hz <= 0 ) return; do_once fps_locker(1); framerate = hz; @@ -27150,7 +27157,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) { int winWidth = window_canvas().w * scale; int winHeight = window_canvas().h * scale; - if (optioni("--capture", 0)) { + if (tests_captureframes()) { winWidth = 1280; winHeight = 720; } @@ -27529,8 +27536,7 @@ int window_swap() { } static uint64_t capture_frame = 0; - static uint64_t capture_target; do_once capture_target = optioni("--capture", 0); - if( cook_done && ++capture_frame == capture_target ) { + if( cook_done && ++capture_frame == tests_captureframes() ) { mkdir( "tests/out", 0777 ); const char *screenshot_file = va("tests/out/%s.png", app_name()); @@ -30261,7 +30267,7 @@ static void v4k_post_init(float refresh_rate) { glfwShowWindow(window); glfwGetFramebufferSize(window, &w, &h); //glfwGetWindowSize(window, &w, &h); - randset(time_ns() * !optioni("--capture",0)); + randset(time_ns() * !tests_captureframes()); boot_time = -time_ss(); // measure boot time, this is continued in window_stats() // clean any errno setup by cooking stage