This commit is contained in:
2019-05-17 16:48:09 +02:00
parent 7561bed8d2
commit ad9ada7884
2 changed files with 20 additions and 4 deletions

View File

@@ -34,6 +34,7 @@ std::map<kKey, int> vkey_map;
std::thread hmd_renderer;
std::thread renderer;
int vr_frames = 0;
int running = -1;
int vr_running = 0;
std::mutex render_mutex;
@@ -506,13 +507,24 @@ bool win32_vr_start()
};
const float target_tick_rate = 90;
unsigned long t0 = GetTickCount();
auto t0 = GetTickCount();
float one_sec_timer = 0;
int frames = 0;
while (vr_running && running == 1 && vive->Valid())
{
std::unique_lock<std::mutex> lock(hmd_render_mutex);
unsigned long t1 = GetTickCount();
auto t1 = GetTickCount();
float dt = (float)(t1 - t0) / 1000.0f;
one_sec_timer += dt;
if (one_sec_timer >= 1.f)
{
one_sec_timer = 0;
vr_frames = frames;
frames = 0;
}
frames++;
vive->Update();
App::I.vr_active = vive->m_active;
App::I.vr_controller = vive->m_controllers[0].m_mat;
@@ -541,6 +553,7 @@ bool win32_vr_start()
const int framerate = (1.f / target_tick_rate) * 1000;
const int diff = framerate - (t1 - t0);
t0 = t1;
hmd_render_cv.wait_for(lock, std::chrono::milliseconds(diff));
}
App::I.vr_active = false;
@@ -881,7 +894,10 @@ int main(int argc, char** argv)
if (one_sec > 1.f)
{
static wchar_t title_fps[512];
swprintf_s(title_fps, L"%s - %d fps", window_title, frames);
if (App::I.vr_active)
swprintf_s(title_fps, L"%s - %d fps - %d vr fps", window_title, frames, vr_frames);
else
swprintf_s(title_fps, L"%s - %d fps", window_title, frames);
std::lock_guard<std::mutex> lock(main_task_mutex);
main_tasklist.emplace_back([=] {