mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-19 06:39:59 +00:00
Predictions were off due to count of frames in flight off by 1.
This commit is contained in:
parent
b65c1f582a
commit
4361f4191d
3 changed files with 29 additions and 32 deletions
|
@ -31,25 +31,23 @@ namespace MWVR
|
||||||
|
|
||||||
static void statsThreadRun()
|
static void statsThreadRun()
|
||||||
{
|
{
|
||||||
while (statsThreadRunning)
|
//while (statsThreadRunning)
|
||||||
{
|
//{
|
||||||
std::stringstream ss;
|
// std::stringstream ss;
|
||||||
for (auto& context : stats)
|
// for (auto& context : stats)
|
||||||
{
|
// {
|
||||||
for (auto& measurement : *context.second)
|
// for (auto& measurement : *context.second)
|
||||||
{
|
// {
|
||||||
double ms = static_cast<double>(measurement.second) / 1000000.;
|
// double ms = static_cast<double>(measurement.second) / 1000000.;
|
||||||
Log(Debug::Verbose) << context.first << "." << measurement.first << ": " << ms << "ms";
|
// 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)
|
Timer::Timer(const char* name) : mName(name)
|
||||||
{
|
{
|
||||||
|
@ -69,11 +67,11 @@ namespace MWVR
|
||||||
stats.emplace_back(MeasurementContext(mName, mContext));
|
stats.emplace_back(MeasurementContext(mName, mContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!statsThreadRunning)
|
//if (!statsThreadRunning)
|
||||||
{
|
//{
|
||||||
statsThreadRunning = true;
|
// statsThreadRunning = true;
|
||||||
statsThread = std::thread([] { statsThreadRun(); });
|
// statsThread = std::thread([] { statsThreadRun(); });
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
Timer::~Timer()
|
Timer::~Timer()
|
||||||
{
|
{
|
||||||
|
|
|
@ -145,19 +145,18 @@ void VRSession::startFrame()
|
||||||
// we make our own (bad) prediction and let openxr wait
|
// we make our own (bad) prediction and let openxr wait
|
||||||
auto frameState = xr->impl().frameState();
|
auto frameState = xr->impl().frameState();
|
||||||
long long predictedDisplayTime = 0;
|
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)
|
else if (mFrames > mLastRenderedFrame)
|
||||||
{
|
{
|
||||||
predictedDisplayTime = frameState.predictedDisplayTime + mLastFrameInterval.count() * (mFrames - mLastRenderedFrame);
|
//predictedDisplayTime = mLastPredictedDisplayTime + mLastFrameInterval.count() * (mFrames - mLastRenderedFrame);
|
||||||
}
|
float intervalsf = static_cast<double>(mLastFrameInterval.count()) / static_cast<double>(frameState.predictedDisplayPeriod);
|
||||||
|
int intervals = (int)std::roundf(intervalsf);
|
||||||
if (mFrames == 0 || predictedDisplayTime == 0)
|
predictedDisplayTime = mLastPredictedDisplayTime + intervals * (mFrames - mLastRenderedFrame) * frameState.predictedDisplayPeriod;
|
||||||
{
|
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PoseSet predictedPoses{};
|
PoseSet predictedPoses{};
|
||||||
|
@ -182,7 +181,6 @@ void VRSession::startFrame()
|
||||||
predictedPoses = mPostdrawFrame->mPredictedPoses;
|
predictedPoses = mPostdrawFrame->mPredictedPoses;
|
||||||
}
|
}
|
||||||
|
|
||||||
mFrames++;
|
|
||||||
|
|
||||||
mPredrawFrame.reset(new VRFrame);
|
mPredrawFrame.reset(new VRFrame);
|
||||||
mPredrawFrame->mPredictedDisplayTime = predictedDisplayTime;
|
mPredrawFrame->mPredictedDisplayTime = predictedDisplayTime;
|
||||||
|
|
|
@ -72,7 +72,8 @@ public:
|
||||||
|
|
||||||
long long mFrames{ 0 };
|
long long mFrames{ 0 };
|
||||||
long long mLastRenderedFrame{ 0 };
|
long long mLastRenderedFrame{ 0 };
|
||||||
|
long long mLastPredictedDisplayTime{ 0 };
|
||||||
|
long long mLastPredictedDisplayPeriod{ 0 };
|
||||||
std::chrono::nanoseconds mLastFrameInterval{};
|
std::chrono::nanoseconds mLastFrameInterval{};
|
||||||
std::chrono::steady_clock::time_point mLastRenderedFrameTimestamp{std::chrono::steady_clock::now()};
|
std::chrono::steady_clock::time_point mLastRenderedFrameTimestamp{std::chrono::steady_clock::now()};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue