Own main workers and narrow Apple render hooks
This commit is contained in:
18
src/main.cpp
18
src/main.cpp
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user