From ad9ada78846b431ab7d837829e7c211ab1951690 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 17 May 2019 16:48:09 +0200 Subject: [PATCH] vr fps --- src/hmd.cpp | 2 +- src/main.cpp | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/hmd.cpp b/src/hmd.cpp index e58fb08..ee18993 100644 --- a/src/hmd.cpp +++ b/src/hmd.cpp @@ -195,7 +195,7 @@ void Vive::Draw() } comp_attempts = 0; - glFlush(); + //glFlush(); } bool Vive::Valid() diff --git a/src/main.cpp b/src/main.cpp index 04fb99c..f5c1295 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,6 +34,7 @@ std::map 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 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 lock(main_task_mutex); main_tasklist.emplace_back([=] {