add experimental menu

This commit is contained in:
2019-03-18 20:26:18 +01:00
parent 4bb1eb28a3
commit e635ad00a8
5 changed files with 217 additions and 105 deletions

View File

@@ -446,6 +446,77 @@ void init_vk_map()
}
}
std::mutex hmd_render_mutex;
std::condition_variable hmd_render_cv;
Vive* vive = nullptr;
bool win32_vr_start()
{
if (sandboxed)
return false;
vive = new Vive;
vive->on_draw = [](const glm::mat4& proj, const glm::mat4& view, const glm::mat4& pose) { App::I.vr_draw(proj, view, pose); };
async_lock();
if (!vive->Initialize())
{
delete vive;
vive = nullptr;
LOG("VR: failed to initialize vive");
async_unlock();
return false;
}
async_unlock();
hmd_renderer = std::thread([&] {
if (!vive)
return;
BT_SetTerminate();
LOG("start hmd render thread");
App::I.has_vr = true;
const float target_tick_rate = 90;
unsigned long t0 = GetTickCount();
while (running == 1 && vive->Valid())
{
std::unique_lock<std::mutex> lock(hmd_render_mutex);
unsigned long t1 = GetTickCount();
float dt = (float)(t1 - t0) / 1000.0f;
vive->Update();
App::I.vr_active = vive->m_active;
if (vive->m_active)
{
async_lock();
vive->Draw();
async_unlock();
}
const int framerate = (1.f / target_tick_rate) * 1000;
const int diff = framerate - (t1 - t0);
hmd_render_cv.wait_for(lock, std::chrono::milliseconds(diff));
}
App::I.vr_active = false;
App::I.has_vr = false;
async_lock();
vive->Terminate();
async_unlock();
LOG("hmd renderer terminated");
});
return true;
}
void win32_vr_stop()
{
if (vive)
{
vive->Terminate();
delete vive;
vive = nullptr;
}
}
int main(int argc, char** argv)
{
WNDCLASS wc;
@@ -620,21 +691,6 @@ int main(int argc, char** argv)
LOG("init app");
App::I.init();
Vive* vive = nullptr;
if (!sandboxed)
{
vive = new Vive;
vive->on_draw = [](const glm::mat4& proj, const glm::mat4& view, const glm::mat4& pose) { App::I.vr_draw(proj, view, pose); };
async_lock();
if (!vive->Initialize())
{
delete vive;
vive = nullptr;
LOG("VR: failed to initialize vive");
}
async_unlock();
}
LOG("show main window");
ShowWindow(hWnd, SW_NORMAL);
@@ -654,11 +710,6 @@ int main(int argc, char** argv)
SendMessage(hWnd, WM_SETICON, ICON_SMALL,
(LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON1)));
//LOG("set redraw interval");
//SetTimer(hWnd, 1, 500, [](HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
// App::I.redraw = true;
//});
running = 1;
renderer = std::thread([&] {
@@ -766,47 +817,6 @@ int main(int argc, char** argv)
LOG("renderer terminated");
});
std::mutex hmd_render_mutex;
std::condition_variable hmd_render_cv;
hmd_renderer = std::thread([&] {
if (!vive)
return;
BT_SetTerminate();
LOG("start hmd render thread");
App::I.has_vr = true;
const float target_tick_rate = 90;
unsigned long t0 = GetTickCount();
while (running == 1 && vive->Valid())
{
std::unique_lock<std::mutex> lock(hmd_render_mutex);
unsigned long t1 = GetTickCount();
float dt = (float)(t1 - t0) / 1000.0f;
vive->Update();
App::I.vr_active = vive->m_active;
if (vive->m_active)
{
async_lock();
vive->Draw();
async_unlock();
}
const int framerate = (1.f / target_tick_rate) * 1000;
const int diff = framerate - (t1 - t0);
hmd_render_cv.wait_for(lock, std::chrono::milliseconds(diff));
}
App::I.vr_active = false;
App::I.has_vr = false;
async_lock();
vive->Terminate();
async_unlock();
LOG("hmd renderer terminated");
});
SetTimer(hWnd, 1, 500, NULL);
MSG msg;