Mercurial > repos > blastem
changeset 1482:2d203bf73dbd nuklear_ui
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 25 Nov 2017 14:42:38 -0800 |
parents | 77a401044935 |
children | 001120e91fed |
files | nuklear_ui/blastem_nuklear.c render.h render_sdl.c |
diffstat | 3 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/nuklear_ui/blastem_nuklear.c Sat Nov 25 13:57:38 2017 -0800 +++ b/nuklear_ui/blastem_nuklear.c Sat Nov 25 14:42:38 2017 -0800 @@ -206,8 +206,15 @@ void idle_loop(void) { + const uint32_t MIN_UI_DELAY = 15; + static uint32_t last; while (current_view != view_play) { + uint32_t current = render_elapsed_ms(); + if ((current - last) < MIN_UI_DELAY) { + render_sleep_ms(MIN_UI_DELAY - (current - last) - 1); + } + last = current; render_update_display(); } }
--- a/render.h Sat Nov 25 13:57:38 2017 -0800 +++ b/render.h Sat Nov 25 14:42:38 2017 -0800 @@ -103,6 +103,8 @@ uint32_t render_emulated_height(); uint32_t render_overscan_top(); uint32_t render_overscan_left(); +uint32_t render_elapsed_ms(void); +void render_sleep_ms(uint32_t delay); #endif //RENDER_H_
--- a/render_sdl.c Sat Nov 25 13:57:38 2017 -0800 +++ b/render_sdl.c Sat Nov 25 14:42:38 2017 -0800 @@ -1220,3 +1220,13 @@ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, title, message, NULL); } +uint32_t render_elapsed_ms(void) +{ + return SDL_GetTicks(); +} + +void render_sleep_ms(uint32_t delay) +{ + return SDL_Delay(delay); +} +