diff options
author | pommicket <pommicket@gmail.com> | 2022-12-30 23:48:59 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-30 23:48:59 -0500 |
commit | f1751dbb895996728f293c6f895691693c9e8a86 (patch) | |
tree | c87f8545d0313e8b698583386f4115c85b2cfbeb | |
parent | 25f6cd6f5ffb9ff34d9e22c38e9d72cdadce2dc9 (diff) |
framerate-cap setting
-rw-r--r-- | config.c | 2 | ||||
-rw-r--r-- | main.c | 20 | ||||
-rw-r--r-- | ted.cfg | 6 | ||||
-rw-r--r-- | ted.h | 2 |
4 files changed, 21 insertions, 9 deletions
@@ -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}, @@ -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); @@ -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 @@ -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; |