Clock updates

This commit is contained in:
Aiden
2026-05-12 21:44:26 +10:00
parent 5c66cfdc64
commit 3a83d9617f
9 changed files with 131 additions and 12 deletions

View File

@@ -71,7 +71,7 @@ GLuint InputFrameTexture::PollAndUpload(InputFrameMailbox* mailbox)
return mTexture;
InputFrame frame;
if (!mailbox->TryAcquireLatest(frame))
if (!mailbox->TryAcquireOldest(frame))
{
++mUploadMisses;
mLastUploadMilliseconds = 0.0;

View File

@@ -13,6 +13,7 @@ RenderCadenceClock::RenderCadenceClock(double frameDurationMilliseconds)
void RenderCadenceClock::Reset(TimePoint now)
{
mNextRenderTime = now;
mPendingFrameAdvance = 1;
mOverrunCount = 0;
mSkippedFrameCount = 0;
}
@@ -27,10 +28,12 @@ RenderCadenceClock::Tick RenderCadenceClock::Poll(TimePoint now)
}
tick.due = true;
mPendingFrameAdvance = 1;
const Duration lateBy = now - mNextRenderTime;
if (lateBy > mFrameDuration)
{
tick.skippedFrames = static_cast<uint64_t>(lateBy / mFrameDuration);
mPendingFrameAdvance += tick.skippedFrames;
++mOverrunCount;
mSkippedFrameCount += tick.skippedFrames;
}
@@ -39,7 +42,8 @@ RenderCadenceClock::Tick RenderCadenceClock::Poll(TimePoint now)
void RenderCadenceClock::MarkRendered(TimePoint now)
{
mNextRenderTime += mFrameDuration;
mNextRenderTime += mFrameDuration * mPendingFrameAdvance;
mPendingFrameAdvance = 1;
if (now - mNextRenderTime > mFrameDuration * 4)
mNextRenderTime = now + mFrameDuration;
}

View File

@@ -31,6 +31,7 @@ public:
private:
Duration mFrameDuration;
TimePoint mNextRenderTime = Clock::now();
uint64_t mPendingFrameAdvance = 1;
uint64_t mOverrunCount = 0;
uint64_t mSkippedFrameCount = 0;
};