From 20588ab236f6fe306d275dffa7e25bfe1a8d8949 Mon Sep 17 00:00:00 2001 From: Jack Punter Date: Thu, 2 Jun 2022 22:13:57 +0100 Subject: [PATCH 1/3] Update refresh rate to be based on monitor (win only) --- platform_win32/win32_4ed.cpp | 46 ++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index f3257fd3..85a1a91e 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -9,8 +9,8 @@ // TOP -#define FPS 60 -#define frame_useconds (1000000 / FPS) +// #define FPS 144 +// #define frame_useconds (1000000 / FPS) #include @@ -299,14 +299,35 @@ system_get_proc_sig(){ return((Void_Func*)(GetProcAddress(lib, proc_name))); } -//////////////////////////////// +//- internal void system_schedule_step(u32 code){ PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, code, 0); } -//////////////////////////////// +//- + +// NOTE(jack): Query win32 API to get montior refresh rate. +internal u64 +win32_get_frame_rate() { + u64 frame_rate = 60; + + DEVMODE device_mode = { 0 }; + // memset(&device_mode, 0, sizeof(DEVMODE)); + device_mode.dmSize = sizeof(DEVMODE); + device_mode.dmDriverExtra = 0; + + // If the Display settings can be retrieved use the device's refresh rate + if(EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &device_mode) != 0){ + frame_rate = device_mode.dmDisplayFrequency; + } + + return frame_rate; +} + + +//- internal void win32_toggle_fullscreen(){ @@ -369,7 +390,7 @@ system_set_key_mode_sig(){ win32vars.key_mode = mode; } -//////////////////////////////// +//- // NOTE(allen): Clipboard internal String_Const_u8 @@ -870,7 +891,7 @@ win32_free_object(Win32_Object *object){ dll_insert(&win32vars.free_win32_objects, &object->node); } -//////////////////////////////// +//- internal system_now_time_sig(){ @@ -977,7 +998,7 @@ system_sleep_sig(){ Sleep(milliseconds); } -//////////////////////////////// +//- internal DWORD CALL_CONVENTION win32_thread_wrapper(void *ptr){ @@ -1117,7 +1138,7 @@ system_condition_variable_free_sig(){ } } -//////////////////////////////// +//- internal LRESULT CALL_CONVENTION win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ @@ -1415,7 +1436,7 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ return(result); } -//////////////////////////////// +//- internal b32 win32_wgl_good(Void_Func *f){ @@ -1664,7 +1685,7 @@ win32_gl_create_window(HWND *wnd_out, HGLRC *context_out, DWORD style, RECT rect return(result); } -//////////////////////////////// +//- int CALL_CONVENTION WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ @@ -2007,6 +2028,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS SetActiveWindow(win32vars.window_handle); ShowWindow(win32vars.window_handle, SW_SHOW); + //- @Added by jack + u64 frame_rate = win32_get_frame_rate(); + u64 frame_useconds = (1000000 / frame_rate); + //- + win32vars.global_frame_mutex = system_mutex_make(); system_acquire_global_frame_mutex(win32vars.tctx); From 264891de8d1002eb623bce7dbe95853805bd6cdd Mon Sep 17 00:00:00 2001 From: Jack Punter Date: Sun, 5 Jun 2022 18:34:23 +0100 Subject: [PATCH 2/3] Fix overdraw in large listers Fix bug where every element in a lister is drawn regardless of whether it is visible or not. This is a drastic performance improvements for large listers (Alt + J in Ryan's layer with large codebases for example) --- custom/4coder_lister_base.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/custom/4coder_lister_base.cpp b/custom/4coder_lister_base.cpp index 05c39b2b..c67a0361 100644 --- a/custom/4coder_lister_base.cpp +++ b/custom/4coder_lister_base.cpp @@ -295,6 +295,9 @@ lister_render(Application_Links *app, Frame_Info frame_info, View_ID view){ i32 first_index = (i32)(scroll_y/block_height); y_pos += first_index*block_height; + i32 max_count = first_index + lister->visible_count + 3; + count = clamp_to(lister->filtered.count, max_count); + for (i32 i = first_index; i < count; i += 1){ Lister_Node *node = lister->filtered.node_ptrs[i]; From 4a8265048d080a4ff5e88bf99d157e99ebc7bf30 Mon Sep 17 00:00:00 2001 From: Jack Punter Date: Mon, 6 Jun 2022 15:03:08 +0100 Subject: [PATCH 3/3] Fix Handle leak in windows platform Also fix a typo in my previous commit :| --- custom/4coder_lister_base.cpp | 2 +- platform_win32/win32_4ed_functions.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/custom/4coder_lister_base.cpp b/custom/4coder_lister_base.cpp index c67a0361..640fa737 100644 --- a/custom/4coder_lister_base.cpp +++ b/custom/4coder_lister_base.cpp @@ -296,7 +296,7 @@ lister_render(Application_Links *app, Frame_Info frame_info, View_ID view){ y_pos += first_index*block_height; i32 max_count = first_index + lister->visible_count + 3; - count = clamp_to(lister->filtered.count, max_count); + count = clamp_top(lister->filtered.count, max_count); for (i32 i = first_index; i < count; i += 1){ Lister_Node *node = lister->filtered.node_ptrs[i]; diff --git a/platform_win32/win32_4ed_functions.cpp b/platform_win32/win32_4ed_functions.cpp index 6e449b1d..79d02b7d 100644 --- a/platform_win32/win32_4ed_functions.cpp +++ b/platform_win32/win32_4ed_functions.cpp @@ -335,6 +335,7 @@ system_get_file_list_sig(){ result.infos[counter] = node; counter += 1; } + FindClose(search); } return(result); @@ -474,7 +475,7 @@ color_picker_hook(HWND Window, UINT Message, WPARAM WParam, LPARAM LParam){ if(GetDlgCtrlID(swatch_window) == 0x2c5) { CHOOSECOLORW *win32_params = - (CHOOSECOLORW *)GetWindowLongPtr(Window, GWLP_USERDATA); + (CHOOSECOLORW *)GetWindowLongPtr(Window, GWLP_USERDATA); if(win32_params) { Color_Picker *picker = (Color_Picker*)win32_params->lCustData;