add experimental menu
This commit is contained in:
132
src/main.cpp
132
src/main.cpp
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user