Harden runtime flags and thin Apple/canvas seams
This commit is contained in:
32
src/main.cpp
32
src/main.cpp
@@ -31,6 +31,7 @@
|
||||
#include <ctime>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
#include <stop_token>
|
||||
|
||||
#define WM_USER_CLOSE (WM_USER + 1)
|
||||
@@ -50,9 +51,9 @@ std::map<kKey, int> vkey_map;
|
||||
static wchar_t window_title[512];
|
||||
|
||||
std::jthread hmd_renderer;
|
||||
int vr_frames = 0;
|
||||
int running = -1;
|
||||
int vr_running = 0;
|
||||
std::atomic<int> vr_frames{0};
|
||||
std::atomic<int> running{-1};
|
||||
std::atomic_bool vr_running{false};
|
||||
|
||||
int gl_count = 0;
|
||||
std::deque<std::packaged_task<void()>> main_tasklist;
|
||||
@@ -233,8 +234,9 @@ void win32_update_stylus(float dt)
|
||||
void win32_update_fps(int frames)
|
||||
{
|
||||
static wchar_t title_fps[512];
|
||||
const int vr_fps = vr_frames.load(std::memory_order_relaxed);
|
||||
if (App::I->vr_active)
|
||||
swprintf_s(title_fps, L"%s - %d fps - %d vr fps", window_title, frames, vr_frames);
|
||||
swprintf_s(title_fps, L"%s - %d fps - %d vr fps", window_title, frames, vr_fps);
|
||||
else
|
||||
swprintf_s(title_fps, L"%s - %d fps", window_title, frames);
|
||||
|
||||
@@ -547,7 +549,7 @@ bool win32_vr_start()
|
||||
BT_SetTerminate();
|
||||
LOG("start hmd render thread");
|
||||
App::I->has_vr = true;
|
||||
vr_running = true;
|
||||
vr_running.store(true, std::memory_order_relaxed);
|
||||
|
||||
vive->on_analog_button = std::bind(&App::vr_analog, App::I, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
|
||||
@@ -562,7 +564,7 @@ bool win32_vr_start()
|
||||
auto t0 = GetTickCount64();
|
||||
float one_sec_timer = 0;
|
||||
int frames = 0;
|
||||
while (!stop_token.stop_requested() && vr_running && running == 1 && vive->Valid())
|
||||
while (!stop_token.stop_requested() && vr_running.load(std::memory_order_relaxed) && running.load(std::memory_order_relaxed) == 1 && vive->Valid())
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(hmd_render_mutex);
|
||||
auto t1 = GetTickCount64();
|
||||
@@ -572,7 +574,7 @@ bool win32_vr_start()
|
||||
if (one_sec_timer >= 1.f)
|
||||
{
|
||||
one_sec_timer = 0;
|
||||
vr_frames = frames;
|
||||
vr_frames.store(frames, std::memory_order_relaxed);
|
||||
frames = 0;
|
||||
}
|
||||
frames++;
|
||||
@@ -583,7 +585,7 @@ bool win32_vr_start()
|
||||
App::I->vr_head = vive->m_pose;
|
||||
App::I->vr_update(dt);
|
||||
|
||||
if (vr_running && vive->m_active)
|
||||
if (vr_running.load(std::memory_order_relaxed) && vive->m_active)
|
||||
{
|
||||
App::I->render_task([] {
|
||||
vive->Draw();
|
||||
@@ -597,7 +599,7 @@ bool win32_vr_start()
|
||||
}
|
||||
App::I->vr_active = false;
|
||||
App::I->has_vr = false;
|
||||
vr_running = false;
|
||||
vr_running.store(false, std::memory_order_relaxed);
|
||||
vive->Terminate();
|
||||
LOG("hmd renderer terminated");
|
||||
});
|
||||
@@ -608,7 +610,7 @@ void win32_vr_stop()
|
||||
{
|
||||
if (vive)
|
||||
{
|
||||
vr_running = false;
|
||||
vr_running.store(false, std::memory_order_relaxed);
|
||||
if (hmd_renderer.joinable())
|
||||
{
|
||||
hmd_renderer.request_stop();
|
||||
@@ -937,7 +939,7 @@ int main(int argc, char** argv)
|
||||
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
|
||||
running = 1;
|
||||
running.store(1, std::memory_order_relaxed);
|
||||
App::I->runtime().render_thread_start(*App::I);
|
||||
App::I->runtime().ui_thread_start(*App::I);
|
||||
|
||||
@@ -985,14 +987,14 @@ int main(int argc, char** argv)
|
||||
|
||||
MSG msg;
|
||||
LOG("start main loop");
|
||||
while (running == 1)
|
||||
while (running.load(std::memory_order_relaxed) == 1)
|
||||
{
|
||||
// If there any message in the queue process it
|
||||
auto present = App::I->animate || App::I->redraw ?
|
||||
PeekMessage(&msg, 0, 0, 0, PM_REMOVE) : GetMessage(&msg, 0, 0, 0);
|
||||
|
||||
if (msg.message == WM_QUIT)
|
||||
running = 0;
|
||||
running.store(0, std::memory_order_relaxed);
|
||||
|
||||
if (present)
|
||||
{
|
||||
@@ -1038,7 +1040,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
switch (msg)
|
||||
{
|
||||
case WM_USER_CLOSE:
|
||||
running = 0;
|
||||
running.store(0, std::memory_order_relaxed);
|
||||
if (hmd_renderer.joinable())
|
||||
{
|
||||
hmd_renderer.request_stop();
|
||||
@@ -1071,7 +1073,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
auto w = (float)LOWORD(lp);
|
||||
auto h = (float)HIWORD(lp);
|
||||
if (h != 0 && running == 1)
|
||||
if (h != 0 && running.load(std::memory_order_relaxed) == 1)
|
||||
{
|
||||
App::I->ui_task_async([=]
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user