From c7c347fa9065e21536677571b2ba9da2ec1cfa82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Sun, 11 Feb 2024 01:01:49 +0100 Subject: [PATCH] win: improve fps timing and fix glfw vsync --- engine/joint/v4k.h | 118 +++++++++++++++++++------------------- engine/split/3rd_glfw3.h | 23 ++++---- engine/split/v4k_window.c | 95 +++++++++++++++--------------- engine/v4k | 23 ++++---- engine/v4k.c | 95 +++++++++++++++--------------- 5 files changed, 174 insertions(+), 180 deletions(-) diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index dbfb45a..cea1cb6 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -56017,14 +56017,12 @@ static void swapBuffersWGL(_GLFWwindow* window) { if (!window->monitor) { - if (IsWindowsVistaOrGreater()) + // HACK: Use DwmFlush when desktop composition is enabled on Windows Vista and 7 + if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater()) { - // DWM Composition is always enabled on Win8+ - BOOL enabled = IsWindows8OrGreater(); + BOOL enabled = FALSE; - // HACK: Use DwmFlush when desktop composition is enabled - if (enabled || - (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)) + if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled) { int count = abs(window->context.wgl.interval); while (count--) @@ -56039,20 +56037,19 @@ static void swapBuffersWGL(_GLFWwindow* window) static void swapIntervalWGL(int interval) { _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); + assert(window != NULL); window->context.wgl.interval = interval; if (!window->monitor) { - if (IsWindowsVistaOrGreater()) + // HACK: Disable WGL swap interval when desktop composition is enabled on Windows + // Vista and 7 to avoid interfering with DWM vsync + if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater()) { - // DWM Composition is always enabled on Win8+ - BOOL enabled = IsWindows8OrGreater(); + BOOL enabled = FALSE; - // HACK: Disable WGL swap interval when desktop composition is enabled to - // avoid interfering with DWM vsync - if (enabled || - (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)) + if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled) interval = 0; } } @@ -379093,7 +379090,8 @@ int fps__timing_thread(void *arg) { int64_t tt = (int64_t)(1e9/(float)framerate) - ns_excess; uint64_t took = -time_ns(); #if is(win32) - timeBeginPeriod(1); Sleep( tt > 0 ? tt/1e6 : 0 ); + do_once timeBeginPeriod(1); + sleep_ns( (float)tt ); #else sleep_ns( (float)tt ); #endif @@ -379452,7 +379450,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) { //glEnable(GL_TEXTURE_2D); // 0:disable vsync, 1:enable vsync, <0:adaptive (allow vsync when framerate is higher than syncrate and disable vsync when framerate drops below syncrate) - flags |= optioni("--vsync", 1) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED; + flags |= optioni("--vsync", 0) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED; flags |= optioni("--vsync-adaptive", 0) || flag("--vsync-adaptive") ? WINDOW_VSYNC_ADAPTIVE : 0; int has_adaptive_vsync = glfwExtensionSupported("WGL_EXT_swap_control_tear") || glfwExtensionSupported("GLX_EXT_swap_control_tear") || glfwExtensionSupported("EXT_swap_control_tear"); int wants_adaptive_vsync = (flags & WINDOW_VSYNC_ADAPTIVE); @@ -379487,54 +379485,54 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) { // static camera_t cam = {0}; id44(cam.view); id44(cam.proj); extern camera_t *last_camera; last_camera = &cam; v4k_pre_init(); - // display a progress bar meanwhile cook is working in the background - // Sleep(500); - if( !COOK_ON_DEMAND ) - if( have_tools() && cook_jobs() ) - while( cook_progress() < 100 ) { - for( int frames = 0; frames < 2/*10*/ && window_swap(); frames += cook_progress() >= 100 ) { - window_title(va("%s %.2d%%", cook_cancelling ? "Aborting" : "Cooking assets", cook_progress())); - if( input(KEY_ESC) ) cook_cancel(); + // display a progress bar meanwhile cook is working in the background + // Sleep(500); + if( !COOK_ON_DEMAND ) + if( have_tools() && cook_jobs() ) + while( cook_progress() < 100 ) { + for( int frames = 0; frames < 2/*10*/ && window_swap(); frames += cook_progress() >= 100 ) { + window_title(va("%s %.2d%%", cook_cancelling ? "Aborting" : "Cooking assets", cook_progress())); + if( input(KEY_ESC) ) cook_cancel(); - glNewFrame(); - - static float previous[JOBS_MAX] = {0}; - - #define ddraw_progress_bar(JOB_ID, JOB_MAX, PERCENT) do { \ - /* NDC coordinates (2d): bottom-left(-1,-1), center(0,0), top-right(+1,+1) */ \ - float progress = (PERCENT+1) / 100.f; if(progress > 1) progress = 1; \ - float speed = progress < 1 ? 0.05f : 0.75f; \ - float smooth = previous[JOB_ID] = progress * speed + previous[JOB_ID] * (1-speed); \ - \ - float pixel = 2.f / window_height(), dist = smooth*2-1, y = pixel*3*JOB_ID; \ - if(JOB_ID==0)ddraw_line(vec3(-1,y-pixel*2,0), vec3(1, y-pixel*2,0)); /* full line */ \ - ddraw_line(vec3(-1,y-pixel ,0), vec3(dist,y-pixel ,0)); /* progress line */ \ - ddraw_line(vec3(-1,y+0 ,0), vec3(dist,y+0 ,0)); /* progress line */ \ - ddraw_line(vec3(-1,y+pixel ,0), vec3(dist,y+pixel ,0)); /* progress line */ \ - if(JOB_ID==JOB_MAX-1)ddraw_line(vec3(-1,y+pixel*2,0), vec3(1, y+pixel*2,0)); /* full line */ \ - } while(0) - - if( FLAGS_TRANSPARENT ) {} else // @transparent - for(int i = 0; i < cook_jobs(); ++i) ddraw_progress_bar(i, cook_jobs(), jobs[i].progress); - // ddraw_progress_bar(0, 1, cook_progress()); - - ddraw_flush(); - - do_once window_visible(1); - - // render progress bar at 30Hz + give the cook threads more time to actually cook the assets. - // no big deal since progress bar is usually quiet when cooking assets most of the time. - // also, make the delay even larger when window is minimized or hidden. - // shaved cook times: 88s -> 57s (tcc), 50s -> 43s (vc) - sleep_ms( window_has_visible() && window_has_focus() ? 8 : 16 ); - } - // set black screen glNewFrame(); - window_swap(); -#if !ENABLE_RETAIL - window_title(""); -#endif + + static float previous[JOBS_MAX] = {0}; + + #define ddraw_progress_bar(JOB_ID, JOB_MAX, PERCENT) do { \ + /* NDC coordinates (2d): bottom-left(-1,-1), center(0,0), top-right(+1,+1) */ \ + float progress = (PERCENT+1) / 100.f; if(progress > 1) progress = 1; \ + float speed = progress < 1 ? 0.05f : 0.75f; \ + float smooth = previous[JOB_ID] = progress * speed + previous[JOB_ID] * (1-speed); \ + \ + float pixel = 2.f / window_height(), dist = smooth*2-1, y = pixel*3*JOB_ID; \ + if(JOB_ID==0)ddraw_line(vec3(-1,y-pixel*2,0), vec3(1, y-pixel*2,0)); /* full line */ \ + ddraw_line(vec3(-1,y-pixel ,0), vec3(dist,y-pixel ,0)); /* progress line */ \ + ddraw_line(vec3(-1,y+0 ,0), vec3(dist,y+0 ,0)); /* progress line */ \ + ddraw_line(vec3(-1,y+pixel ,0), vec3(dist,y+pixel ,0)); /* progress line */ \ + if(JOB_ID==JOB_MAX-1)ddraw_line(vec3(-1,y+pixel*2,0), vec3(1, y+pixel*2,0)); /* full line */ \ + } while(0) + + if( FLAGS_TRANSPARENT ) {} else // @transparent + for(int i = 0; i < cook_jobs(); ++i) ddraw_progress_bar(i, cook_jobs(), jobs[i].progress); + // ddraw_progress_bar(0, 1, cook_progress()); + + ddraw_flush(); + + do_once window_visible(1); + + // render progress bar at 30Hz + give the cook threads more time to actually cook the assets. + // no big deal since progress bar is usually quiet when cooking assets most of the time. + // also, make the delay even larger when window is minimized or hidden. + // shaved cook times: 88s -> 57s (tcc), 50s -> 43s (vc) + sleep_ms( window_has_visible() && window_has_focus() ? 8 : 16 ); } + // set black screen + glNewFrame(); + window_swap(); +#if !ENABLE_RETAIL + window_title(""); +#endif + } if(cook_cancelling) cook_stop(), exit(-1); diff --git a/engine/split/3rd_glfw3.h b/engine/split/3rd_glfw3.h index dcde19b..8253130 100644 --- a/engine/split/3rd_glfw3.h +++ b/engine/split/3rd_glfw3.h @@ -23097,14 +23097,12 @@ static void swapBuffersWGL(_GLFWwindow* window) { if (!window->monitor) { - if (IsWindowsVistaOrGreater()) + // HACK: Use DwmFlush when desktop composition is enabled on Windows Vista and 7 + if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater()) { - // DWM Composition is always enabled on Win8+ - BOOL enabled = IsWindows8OrGreater(); + BOOL enabled = FALSE; - // HACK: Use DwmFlush when desktop composition is enabled - if (enabled || - (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)) + if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled) { int count = abs(window->context.wgl.interval); while (count--) @@ -23119,20 +23117,19 @@ static void swapBuffersWGL(_GLFWwindow* window) static void swapIntervalWGL(int interval) { _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); + assert(window != NULL); window->context.wgl.interval = interval; if (!window->monitor) { - if (IsWindowsVistaOrGreater()) + // HACK: Disable WGL swap interval when desktop composition is enabled on Windows + // Vista and 7 to avoid interfering with DWM vsync + if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater()) { - // DWM Composition is always enabled on Win8+ - BOOL enabled = IsWindows8OrGreater(); + BOOL enabled = FALSE; - // HACK: Disable WGL swap interval when desktop composition is enabled to - // avoid interfering with DWM vsync - if (enabled || - (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)) + if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled) interval = 0; } } diff --git a/engine/split/v4k_window.c b/engine/split/v4k_window.c index d979667..1d574b1 100644 --- a/engine/split/v4k_window.c +++ b/engine/split/v4k_window.c @@ -15,7 +15,8 @@ int fps__timing_thread(void *arg) { int64_t tt = (int64_t)(1e9/(float)framerate) - ns_excess; uint64_t took = -time_ns(); #if is(win32) - timeBeginPeriod(1); Sleep( tt > 0 ? tt/1e6 : 0 ); + do_once timeBeginPeriod(1); + sleep_ns( (float)tt ); #else sleep_ns( (float)tt ); #endif @@ -374,7 +375,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) { //glEnable(GL_TEXTURE_2D); // 0:disable vsync, 1:enable vsync, <0:adaptive (allow vsync when framerate is higher than syncrate and disable vsync when framerate drops below syncrate) - flags |= optioni("--vsync", 1) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED; + flags |= optioni("--vsync", 0) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED; flags |= optioni("--vsync-adaptive", 0) || flag("--vsync-adaptive") ? WINDOW_VSYNC_ADAPTIVE : 0; int has_adaptive_vsync = glfwExtensionSupported("WGL_EXT_swap_control_tear") || glfwExtensionSupported("GLX_EXT_swap_control_tear") || glfwExtensionSupported("EXT_swap_control_tear"); int wants_adaptive_vsync = (flags & WINDOW_VSYNC_ADAPTIVE); @@ -409,54 +410,54 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) { // static camera_t cam = {0}; id44(cam.view); id44(cam.proj); extern camera_t *last_camera; last_camera = &cam; v4k_pre_init(); - // display a progress bar meanwhile cook is working in the background - // Sleep(500); - if( !COOK_ON_DEMAND ) - if( have_tools() && cook_jobs() ) - while( cook_progress() < 100 ) { - for( int frames = 0; frames < 2/*10*/ && window_swap(); frames += cook_progress() >= 100 ) { - window_title(va("%s %.2d%%", cook_cancelling ? "Aborting" : "Cooking assets", cook_progress())); - if( input(KEY_ESC) ) cook_cancel(); + // display a progress bar meanwhile cook is working in the background + // Sleep(500); + if( !COOK_ON_DEMAND ) + if( have_tools() && cook_jobs() ) + while( cook_progress() < 100 ) { + for( int frames = 0; frames < 2/*10*/ && window_swap(); frames += cook_progress() >= 100 ) { + window_title(va("%s %.2d%%", cook_cancelling ? "Aborting" : "Cooking assets", cook_progress())); + if( input(KEY_ESC) ) cook_cancel(); - glNewFrame(); - - static float previous[JOBS_MAX] = {0}; - - #define ddraw_progress_bar(JOB_ID, JOB_MAX, PERCENT) do { \ - /* NDC coordinates (2d): bottom-left(-1,-1), center(0,0), top-right(+1,+1) */ \ - float progress = (PERCENT+1) / 100.f; if(progress > 1) progress = 1; \ - float speed = progress < 1 ? 0.05f : 0.75f; \ - float smooth = previous[JOB_ID] = progress * speed + previous[JOB_ID] * (1-speed); \ - \ - float pixel = 2.f / window_height(), dist = smooth*2-1, y = pixel*3*JOB_ID; \ - if(JOB_ID==0)ddraw_line(vec3(-1,y-pixel*2,0), vec3(1, y-pixel*2,0)); /* full line */ \ - ddraw_line(vec3(-1,y-pixel ,0), vec3(dist,y-pixel ,0)); /* progress line */ \ - ddraw_line(vec3(-1,y+0 ,0), vec3(dist,y+0 ,0)); /* progress line */ \ - ddraw_line(vec3(-1,y+pixel ,0), vec3(dist,y+pixel ,0)); /* progress line */ \ - if(JOB_ID==JOB_MAX-1)ddraw_line(vec3(-1,y+pixel*2,0), vec3(1, y+pixel*2,0)); /* full line */ \ - } while(0) - - if( FLAGS_TRANSPARENT ) {} else // @transparent - for(int i = 0; i < cook_jobs(); ++i) ddraw_progress_bar(i, cook_jobs(), jobs[i].progress); - // ddraw_progress_bar(0, 1, cook_progress()); - - ddraw_flush(); - - do_once window_visible(1); - - // render progress bar at 30Hz + give the cook threads more time to actually cook the assets. - // no big deal since progress bar is usually quiet when cooking assets most of the time. - // also, make the delay even larger when window is minimized or hidden. - // shaved cook times: 88s -> 57s (tcc), 50s -> 43s (vc) - sleep_ms( window_has_visible() && window_has_focus() ? 8 : 16 ); - } - // set black screen glNewFrame(); - window_swap(); -#if !ENABLE_RETAIL - window_title(""); -#endif + + static float previous[JOBS_MAX] = {0}; + + #define ddraw_progress_bar(JOB_ID, JOB_MAX, PERCENT) do { \ + /* NDC coordinates (2d): bottom-left(-1,-1), center(0,0), top-right(+1,+1) */ \ + float progress = (PERCENT+1) / 100.f; if(progress > 1) progress = 1; \ + float speed = progress < 1 ? 0.05f : 0.75f; \ + float smooth = previous[JOB_ID] = progress * speed + previous[JOB_ID] * (1-speed); \ + \ + float pixel = 2.f / window_height(), dist = smooth*2-1, y = pixel*3*JOB_ID; \ + if(JOB_ID==0)ddraw_line(vec3(-1,y-pixel*2,0), vec3(1, y-pixel*2,0)); /* full line */ \ + ddraw_line(vec3(-1,y-pixel ,0), vec3(dist,y-pixel ,0)); /* progress line */ \ + ddraw_line(vec3(-1,y+0 ,0), vec3(dist,y+0 ,0)); /* progress line */ \ + ddraw_line(vec3(-1,y+pixel ,0), vec3(dist,y+pixel ,0)); /* progress line */ \ + if(JOB_ID==JOB_MAX-1)ddraw_line(vec3(-1,y+pixel*2,0), vec3(1, y+pixel*2,0)); /* full line */ \ + } while(0) + + if( FLAGS_TRANSPARENT ) {} else // @transparent + for(int i = 0; i < cook_jobs(); ++i) ddraw_progress_bar(i, cook_jobs(), jobs[i].progress); + // ddraw_progress_bar(0, 1, cook_progress()); + + ddraw_flush(); + + do_once window_visible(1); + + // render progress bar at 30Hz + give the cook threads more time to actually cook the assets. + // no big deal since progress bar is usually quiet when cooking assets most of the time. + // also, make the delay even larger when window is minimized or hidden. + // shaved cook times: 88s -> 57s (tcc), 50s -> 43s (vc) + sleep_ms( window_has_visible() && window_has_focus() ? 8 : 16 ); } + // set black screen + glNewFrame(); + window_swap(); +#if !ENABLE_RETAIL + window_title(""); +#endif + } if(cook_cancelling) cook_stop(), exit(-1); diff --git a/engine/v4k b/engine/v4k index 96427fc..2fd4bba 100644 --- a/engine/v4k +++ b/engine/v4k @@ -37132,14 +37132,12 @@ static void swapBuffersWGL(_GLFWwindow* window) { if (!window->monitor) { - if (IsWindowsVistaOrGreater()) + // HACK: Use DwmFlush when desktop composition is enabled on Windows Vista and 7 + if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater()) { - // DWM Composition is always enabled on Win8+ - BOOL enabled = IsWindows8OrGreater(); + BOOL enabled = FALSE; - // HACK: Use DwmFlush when desktop composition is enabled - if (enabled || - (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)) + if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled) { int count = abs(window->context.wgl.interval); while (count--) @@ -37154,20 +37152,19 @@ static void swapBuffersWGL(_GLFWwindow* window) static void swapIntervalWGL(int interval) { _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); + assert(window != NULL); window->context.wgl.interval = interval; if (!window->monitor) { - if (IsWindowsVistaOrGreater()) + // HACK: Disable WGL swap interval when desktop composition is enabled on Windows + // Vista and 7 to avoid interfering with DWM vsync + if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater()) { - // DWM Composition is always enabled on Win8+ - BOOL enabled = IsWindows8OrGreater(); + BOOL enabled = FALSE; - // HACK: Disable WGL swap interval when desktop composition is enabled to - // avoid interfering with DWM vsync - if (enabled || - (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)) + if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled) interval = 0; } } diff --git a/engine/v4k.c b/engine/v4k.c index 973630b..84e5ca8 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -26234,7 +26234,8 @@ int fps__timing_thread(void *arg) { int64_t tt = (int64_t)(1e9/(float)framerate) - ns_excess; uint64_t took = -time_ns(); #if is(win32) - timeBeginPeriod(1); Sleep( tt > 0 ? tt/1e6 : 0 ); + do_once timeBeginPeriod(1); + sleep_ns( (float)tt ); #else sleep_ns( (float)tt ); #endif @@ -26593,7 +26594,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) { //glEnable(GL_TEXTURE_2D); // 0:disable vsync, 1:enable vsync, <0:adaptive (allow vsync when framerate is higher than syncrate and disable vsync when framerate drops below syncrate) - flags |= optioni("--vsync", 1) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED; + flags |= optioni("--vsync", 0) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED; flags |= optioni("--vsync-adaptive", 0) || flag("--vsync-adaptive") ? WINDOW_VSYNC_ADAPTIVE : 0; int has_adaptive_vsync = glfwExtensionSupported("WGL_EXT_swap_control_tear") || glfwExtensionSupported("GLX_EXT_swap_control_tear") || glfwExtensionSupported("EXT_swap_control_tear"); int wants_adaptive_vsync = (flags & WINDOW_VSYNC_ADAPTIVE); @@ -26628,54 +26629,54 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) { // static camera_t cam = {0}; id44(cam.view); id44(cam.proj); extern camera_t *last_camera; last_camera = &cam; v4k_pre_init(); - // display a progress bar meanwhile cook is working in the background - // Sleep(500); - if( !COOK_ON_DEMAND ) - if( have_tools() && cook_jobs() ) - while( cook_progress() < 100 ) { - for( int frames = 0; frames < 2/*10*/ && window_swap(); frames += cook_progress() >= 100 ) { - window_title(va("%s %.2d%%", cook_cancelling ? "Aborting" : "Cooking assets", cook_progress())); - if( input(KEY_ESC) ) cook_cancel(); + // display a progress bar meanwhile cook is working in the background + // Sleep(500); + if( !COOK_ON_DEMAND ) + if( have_tools() && cook_jobs() ) + while( cook_progress() < 100 ) { + for( int frames = 0; frames < 2/*10*/ && window_swap(); frames += cook_progress() >= 100 ) { + window_title(va("%s %.2d%%", cook_cancelling ? "Aborting" : "Cooking assets", cook_progress())); + if( input(KEY_ESC) ) cook_cancel(); - glNewFrame(); - - static float previous[JOBS_MAX] = {0}; - - #define ddraw_progress_bar(JOB_ID, JOB_MAX, PERCENT) do { \ - /* NDC coordinates (2d): bottom-left(-1,-1), center(0,0), top-right(+1,+1) */ \ - float progress = (PERCENT+1) / 100.f; if(progress > 1) progress = 1; \ - float speed = progress < 1 ? 0.05f : 0.75f; \ - float smooth = previous[JOB_ID] = progress * speed + previous[JOB_ID] * (1-speed); \ - \ - float pixel = 2.f / window_height(), dist = smooth*2-1, y = pixel*3*JOB_ID; \ - if(JOB_ID==0)ddraw_line(vec3(-1,y-pixel*2,0), vec3(1, y-pixel*2,0)); /* full line */ \ - ddraw_line(vec3(-1,y-pixel ,0), vec3(dist,y-pixel ,0)); /* progress line */ \ - ddraw_line(vec3(-1,y+0 ,0), vec3(dist,y+0 ,0)); /* progress line */ \ - ddraw_line(vec3(-1,y+pixel ,0), vec3(dist,y+pixel ,0)); /* progress line */ \ - if(JOB_ID==JOB_MAX-1)ddraw_line(vec3(-1,y+pixel*2,0), vec3(1, y+pixel*2,0)); /* full line */ \ - } while(0) - - if( FLAGS_TRANSPARENT ) {} else // @transparent - for(int i = 0; i < cook_jobs(); ++i) ddraw_progress_bar(i, cook_jobs(), jobs[i].progress); - // ddraw_progress_bar(0, 1, cook_progress()); - - ddraw_flush(); - - do_once window_visible(1); - - // render progress bar at 30Hz + give the cook threads more time to actually cook the assets. - // no big deal since progress bar is usually quiet when cooking assets most of the time. - // also, make the delay even larger when window is minimized or hidden. - // shaved cook times: 88s -> 57s (tcc), 50s -> 43s (vc) - sleep_ms( window_has_visible() && window_has_focus() ? 8 : 16 ); - } - // set black screen glNewFrame(); - window_swap(); -#if !ENABLE_RETAIL - window_title(""); -#endif + + static float previous[JOBS_MAX] = {0}; + + #define ddraw_progress_bar(JOB_ID, JOB_MAX, PERCENT) do { \ + /* NDC coordinates (2d): bottom-left(-1,-1), center(0,0), top-right(+1,+1) */ \ + float progress = (PERCENT+1) / 100.f; if(progress > 1) progress = 1; \ + float speed = progress < 1 ? 0.05f : 0.75f; \ + float smooth = previous[JOB_ID] = progress * speed + previous[JOB_ID] * (1-speed); \ + \ + float pixel = 2.f / window_height(), dist = smooth*2-1, y = pixel*3*JOB_ID; \ + if(JOB_ID==0)ddraw_line(vec3(-1,y-pixel*2,0), vec3(1, y-pixel*2,0)); /* full line */ \ + ddraw_line(vec3(-1,y-pixel ,0), vec3(dist,y-pixel ,0)); /* progress line */ \ + ddraw_line(vec3(-1,y+0 ,0), vec3(dist,y+0 ,0)); /* progress line */ \ + ddraw_line(vec3(-1,y+pixel ,0), vec3(dist,y+pixel ,0)); /* progress line */ \ + if(JOB_ID==JOB_MAX-1)ddraw_line(vec3(-1,y+pixel*2,0), vec3(1, y+pixel*2,0)); /* full line */ \ + } while(0) + + if( FLAGS_TRANSPARENT ) {} else // @transparent + for(int i = 0; i < cook_jobs(); ++i) ddraw_progress_bar(i, cook_jobs(), jobs[i].progress); + // ddraw_progress_bar(0, 1, cook_progress()); + + ddraw_flush(); + + do_once window_visible(1); + + // render progress bar at 30Hz + give the cook threads more time to actually cook the assets. + // no big deal since progress bar is usually quiet when cooking assets most of the time. + // also, make the delay even larger when window is minimized or hidden. + // shaved cook times: 88s -> 57s (tcc), 50s -> 43s (vc) + sleep_ms( window_has_visible() && window_has_focus() ? 8 : 16 ); } + // set black screen + glNewFrame(); + window_swap(); +#if !ENABLE_RETAIL + window_title(""); +#endif + } if(cook_cancelling) cook_stop(), exit(-1);