1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-15 17:09:46 +00:00

Predictions were off due to count of frames in flight off by 1.

This commit is contained in:
Mads Buvik Sandvei 2020-05-31 13:19:26 +02:00
parent b65c1f582a
commit 4361f4191d
3 changed files with 29 additions and 32 deletions

View file

@ -31,25 +31,23 @@ namespace MWVR
static void statsThreadRun()
{
while (statsThreadRunning)
{
std::stringstream ss;
for (auto& context : stats)
{
for (auto& measurement : *context.second)
{
double ms = static_cast<double>(measurement.second) / 1000000.;
Log(Debug::Verbose) << context.first << "." << measurement.first << ": " << ms << "ms";
}
}
//while (statsThreadRunning)
//{
// std::stringstream ss;
// for (auto& context : stats)
// {
// for (auto& measurement : *context.second)
// {
// double ms = static_cast<double>(measurement.second) / 1000000.;
// Log(Debug::Verbose) << context.first << "." << measurement.first << ": " << ms << "ms";
// }
// }
//Log(Debug::Verbose) << ss.str();
// Log(Debug::Verbose) << ss.str();
std::this_thread::sleep_for(std::chrono::seconds(1));
// std::this_thread::sleep_for(std::chrono::seconds(1));
//}
}
}
Timer::Timer(const char* name) : mName(name)
{
@ -69,11 +67,11 @@ namespace MWVR
stats.emplace_back(MeasurementContext(mName, mContext));
}
if (!statsThreadRunning)
{
statsThreadRunning = true;
statsThread = std::thread([] { statsThreadRun(); });
}
//if (!statsThreadRunning)
//{
// statsThreadRunning = true;
// statsThread = std::thread([] { statsThreadRun(); });
//}
}
Timer::~Timer()
{

View file

@ -145,19 +145,18 @@ void VRSession::startFrame()
// we make our own (bad) prediction and let openxr wait
auto frameState = xr->impl().frameState();
long long predictedDisplayTime = 0;
if (mFrames == mLastRenderedFrame)
mFrames++;
if (mLastPredictedDisplayTime == 0)
{
predictedDisplayTime = frameState.predictedDisplayTime;
// First time, need to invent a frame time since openxr won't help us without calling waitframe.
predictedDisplayTime = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
}
else if (mFrames > mLastRenderedFrame)
{
predictedDisplayTime = frameState.predictedDisplayTime + mLastFrameInterval.count() * (mFrames - mLastRenderedFrame);
}
if (mFrames == 0 || predictedDisplayTime == 0)
{
// First time, need to populate the frame state struct
predictedDisplayTime = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
//predictedDisplayTime = mLastPredictedDisplayTime + mLastFrameInterval.count() * (mFrames - mLastRenderedFrame);
float intervalsf = static_cast<double>(mLastFrameInterval.count()) / static_cast<double>(frameState.predictedDisplayPeriod);
int intervals = (int)std::roundf(intervalsf);
predictedDisplayTime = mLastPredictedDisplayTime + intervals * (mFrames - mLastRenderedFrame) * frameState.predictedDisplayPeriod;
}
PoseSet predictedPoses{};
@ -182,7 +181,6 @@ void VRSession::startFrame()
predictedPoses = mPostdrawFrame->mPredictedPoses;
}
mFrames++;
mPredrawFrame.reset(new VRFrame);
mPredrawFrame->mPredictedDisplayTime = predictedDisplayTime;

View file

@ -72,7 +72,8 @@ public:
long long mFrames{ 0 };
long long mLastRenderedFrame{ 0 };
long long mLastPredictedDisplayTime{ 0 };
long long mLastPredictedDisplayPeriod{ 0 };
std::chrono::nanoseconds mLastFrameInterval{};
std::chrono::steady_clock::time_point mLastRenderedFrameTimestamp{std::chrono::steady_clock::now()};