wake up windows main loop when updating fps, use PostMessage instead of the blocking SendMessage

This commit is contained in:
2019-07-28 09:40:52 +02:00
parent 4ab35c6e9b
commit 7d3a95f42b

View File

@@ -23,6 +23,7 @@
#include <sstream> #include <sstream>
#define WM_USER_CLOSE (WM_USER + 1) #define WM_USER_CLOSE (WM_USER + 1)
#define WM_USER_WAKEUP (WM_USER + 2)
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp); LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
HINSTANCE hInst; HINSTANCE hInst;
@@ -108,7 +109,7 @@ void destroy_window()
{ {
std::lock_guard<std::mutex> lock(main_task_mutex); std::lock_guard<std::mutex> lock(main_task_mutex);
main_tasklist.emplace_back([=] { main_tasklist.emplace_back([=] {
SendMessage(hWnd, WM_USER_CLOSE, 0, 0); PostMessage(hWnd, WM_USER_CLOSE, 0, 0);
}); });
} }
@@ -196,10 +197,13 @@ void win32_update_fps(int frames)
else else
swprintf_s(title_fps, L"%s - %d fps", window_title, frames); swprintf_s(title_fps, L"%s - %d fps", window_title, frames);
std::lock_guard<std::mutex> lock(main_task_mutex); {
main_tasklist.emplace_back([] { std::lock_guard<std::mutex> lock(main_task_mutex);
SetWindowText(hWnd, title_fps); main_tasklist.emplace_back([] {
}); SetWindowText(hWnd, title_fps);
});
}
PostMessage(hWnd, WM_USER_WAKEUP, 0, 0);
} }
void win32_show_cursor(bool visible) void win32_show_cursor(bool visible)