From f1751dbb895996728f293c6f895691693c9e8a86 Mon Sep 17 00:00:00 2001 From: pommicket Date: Fri, 30 Dec 2022 23:48:59 -0500 Subject: framerate-cap setting --- config.c | 2 ++ main.c | 20 +++++++++++--------- ted.cfg | 6 ++++++ ted.h | 2 ++ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/config.c b/config.c index e4c0ac6..070f440 100644 --- a/config.c +++ b/config.c @@ -262,6 +262,7 @@ static OptionBool const options_bool[] = { {"signature-help-enabled", &options_zero.signature_help_enabled, true}, {"lsp-enabled", &options_zero.lsp_enabled, true}, {"hover-enabled", &options_zero.hover_enabled, true}, + {"vsync", &options_zero.vsync, false}, }; static OptionU8 const options_u8[] = { {"tab-width", &options_zero.tab_width, 1, 100, true}, @@ -276,6 +277,7 @@ static OptionU16 const options_u16[] = { {"text-size", &options_zero.text_size, TEXT_SIZE_MIN, TEXT_SIZE_MAX, false}, {"max-menu-width", &options_zero.max_menu_width, 10, U16_MAX, false}, {"error-display-time", &options_zero.error_display_time, 0, U16_MAX, false}, + {"framerate-cap", &options_zero.framerate_cap, 3, 1000, false}, }; static OptionU32 const options_u32[] = { {"max-file-size", &options_zero.max_file_size, 100, 2000000000, false}, diff --git a/main.c b/main.c index 38d4e4b..d091c64 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,6 @@ /* @TODO: - show line containing usage -- framerate-cap setting - change frame_time to a double - highlight-enabled, and highlight-auto - handle multiple symbols with same name in go-to-definition menu @@ -1139,17 +1138,20 @@ int main(int argc, char **argv) { SDL_ShowCursor(SDL_DISABLE); } - // annoyingly, SDL_GL_SwapWindow seems to be a busy loop on my laptop for some reason... - // enforce a framerate of 60. this isn't ideal but SDL_GetDisplayMode is *extremely slow* (250ms), so we don't really have a choice. - int refresh_rate = 60; - if (refresh_rate) { - i32 ms_wait = 1000 / refresh_rate - (i32)((frame_end_noswap - frame_start) * 1000); - if (ms_wait > 0) { + { + // annoyingly, SDL_GL_SwapWindow seems to be a busy loop on my laptop for some reason... + // this is why the framerate-cap settings exists + const Settings *settings = ted->default_settings; + if (settings->framerate_cap) { + i32 ms_wait = 1000 / (i32)settings->framerate_cap - (i32)((frame_end_noswap - frame_start) * 1000); ms_wait -= 1; // give swap an extra ms to make sure it's actually vsynced - SDL_Delay((u32)ms_wait); + if (ms_wait > 0) { + SDL_Delay((u32)ms_wait); + } } + SDL_GL_SetSwapInterval(settings->vsync ? 1 : 0); + SDL_GL_SwapWindow(window); } - SDL_GL_SwapWindow(window); PROFILE_TIME(frame_end) assert(glGetError() == 0); diff --git a/ted.cfg b/ted.cfg index 88204db..05116a5 100644 --- a/ted.cfg +++ b/ted.cfg @@ -51,6 +51,12 @@ max-file-size = 20000000 # ted will produce an error if a file larger than this is loaded. max-file-size-view-only = 100000000 +# whether to use vsync or not. you probably want this on. +vsync = off +# max framerate. vsync overrides this. +# you might want to increase this if you have a >60Hz monitor and you don't care about CPU usage. +framerate-cap = 60 + # search depth for files to generate tags for. # if set to 0, tag generation/regeneration will do nothing tags-max-depth = 2 diff --git a/ted.h b/ted.h index 41f7bbc..c8e62a6 100644 --- a/ted.h +++ b/ted.h @@ -140,6 +140,7 @@ typedef struct { u32 colors[COLOR_COUNT]; u32 max_file_size; u32 max_file_size_view_only; + u16 framerate_cap; u16 text_size; u16 max_menu_width; u16 error_display_time; @@ -157,6 +158,7 @@ typedef struct { bool signature_help_enabled; bool lsp_enabled; bool hover_enabled; + bool vsync; u8 tab_width; u8 cursor_width; u8 undo_save_time; -- cgit v1.2.3