From ee25d7be38f47d229129456332ed7e2aeae44511 Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Sun, 24 May 2020 18:20:57 +0200 Subject: [PATCH] Prediction fix --- apps/openmw/mwvr/vrsession.cpp | 5 ++++- apps/openmw/mwvr/vrsession.hpp | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwvr/vrsession.cpp b/apps/openmw/mwvr/vrsession.cpp index 3706fde08..7d31af1cb 100644 --- a/apps/openmw/mwvr/vrsession.cpp +++ b/apps/openmw/mwvr/vrsession.cpp @@ -118,6 +118,9 @@ void VRSession::swapBuffers(osg::GraphicsContext* gc, VRViewer& viewer) xr->endFrame(mPostdrawFrame->mPredictedDisplayTime, 1, &layerStack); mLastRenderedFrame = mPostdrawFrame->mFrameNo; + auto now = std::chrono::steady_clock::now(); + mLastFrameInterval = std::chrono::duration_cast(now - mLastRenderedFrameTimestamp); + mLastRenderedFrameTimestamp = now; } void VRSession::advanceFramePhase(void) @@ -148,7 +151,7 @@ void VRSession::startFrame() } else if (mFrames > mLastRenderedFrame) { - predictedDisplayTime = frameState.predictedDisplayTime + frameState.predictedDisplayPeriod; + predictedDisplayTime = frameState.predictedDisplayTime + mLastFrameInterval.count() * (mFrames - mLastRenderedFrame); } if (mFrames == 0 || predictedDisplayTime == 0) diff --git a/apps/openmw/mwvr/vrsession.hpp b/apps/openmw/mwvr/vrsession.hpp index f235eec65..ceb769482 100644 --- a/apps/openmw/mwvr/vrsession.hpp +++ b/apps/openmw/mwvr/vrsession.hpp @@ -73,6 +73,9 @@ public: long long mFrames{ 0 }; long long mLastRenderedFrame{ 0 }; + std::chrono::nanoseconds mLastFrameInterval{}; + std::chrono::steady_clock::time_point mLastRenderedFrameTimestamp{std::chrono::steady_clock::now()}; + float mPlayerScale{ 1.f }; };