Own main workers and narrow Apple render hooks

This commit is contained in:
2026-06-16 07:43:44 +02:00
parent 6f4bd4b26f
commit 0c72aa0312
9 changed files with 167 additions and 52 deletions

View File

@@ -30,6 +30,7 @@
#include <iomanip>
#include <ctime>
#include <sstream>
#include <stop_token>
#define WM_USER_CLOSE (WM_USER + 1)
#define WM_USER_WAKEUP (WM_USER + 2)
@@ -47,7 +48,7 @@ std::thread::id gl_thread;
std::map<kKey, int> vkey_map;
static wchar_t window_title[512];
std::thread hmd_renderer;
std::jthread hmd_renderer;
int vr_frames = 0;
int running = -1;
int vr_running = 0;
@@ -535,8 +536,11 @@ bool win32_vr_start()
}
if (hmd_renderer.joinable())
{
hmd_renderer.request_stop();
hmd_renderer.join();
hmd_renderer = std::thread([&] {
}
hmd_renderer = std::jthread([&](std::stop_token stop_token) {
if (!vive)
return;
@@ -558,7 +562,7 @@ bool win32_vr_start()
auto t0 = GetTickCount64();
float one_sec_timer = 0;
int frames = 0;
while (vr_running && running == 1 && vive->Valid())
while (!stop_token.stop_requested() && vr_running && running == 1 && vive->Valid())
{
std::unique_lock<std::mutex> lock(hmd_render_mutex);
auto t1 = GetTickCount64();
@@ -606,7 +610,10 @@ void win32_vr_stop()
{
vr_running = false;
if (hmd_renderer.joinable())
{
hmd_renderer.request_stop();
hmd_renderer.join();
}
vive->Terminate();
delete vive;
vive = nullptr;
@@ -764,7 +771,7 @@ int main(int argc, char** argv)
LOG("data files ok");
}
std::thread dialog_thread(splash_thread_loop);
std::jthread dialog_thread(splash_thread_loop);
init_vk_map();
@@ -1034,7 +1041,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
case WM_USER_CLOSE:
running = 0;
if (hmd_renderer.joinable())
{
hmd_renderer.request_stop();
hmd_renderer.join();
}
App::I->runtime().ui_thread_stop();
App::I->runtime().render_thread_stop();
App::I->terminate();