Small refactor to enable upcoming commits

This commit is contained in:
Henrik Rydgård 2023-12-15 09:25:59 +01:00
parent ef149bd9f3
commit 91dbde9395

View File

@ -391,7 +391,7 @@ static void DoFrameDropLogging(float scaledTimestep) {
// All the throttling and frameskipping logic is here.
// This is called just before we drop out of the main loop, in order to allow the submit and present to happen.
static void DoFrameTiming(bool throttle, bool *skipFrame, float scaledTimestep) {
static void DoFrameTiming(bool throttle, bool *skipFrame, float scaledTimestep, bool endOfFrame) {
PROFILE_THIS_SCOPE("timing");
*skipFrame = false;
@ -438,6 +438,9 @@ static void DoFrameTiming(bool throttle, bool *skipFrame, float scaledTimestep)
nextFrameTime = curFrameTime;
} else {
// Wait until we've caught up.
// TODO: This is the wait we actually move to after the frame.
// But watch out, curFrameTime below must be updated correctly - I think.
while (time_now_d() < nextFrameTime) {
#ifdef _WIN32
sleep_ms(1); // Sleep for 1ms on this thread
@ -637,9 +640,13 @@ void __DisplayFlip(int cyclesLate) {
// Setting CORE_NEXTFRAME (which Core_NextFrame does) causes a swap.
const bool fbReallyDirty = gpu->FramebufferReallyDirty();
bool nextFrame = false;
if (fbReallyDirty || noRecentFlip || postEffectRequiresFlip) {
// Check first though, might've just quit / been paused.
if (!forceNoFlip && Core_NextFrame()) {
nextFrame = Core_NextFrame();
if (!forceNoFlip && nextFrame) {
gpu->CopyDisplayToOutput(fbReallyDirty);
if (fbReallyDirty) {
DisplayFireActualFlip();
@ -659,7 +666,7 @@ void __DisplayFlip(int cyclesLate) {
scaledTimestep *= (float)framerate / fpsLimit;
}
bool skipFrame;
DoFrameTiming(throttle, &skipFrame, scaledTimestep);
DoFrameTiming(throttle, &skipFrame, scaledTimestep, nextFrame);
int maxFrameskip = 8;
int frameSkipNum = DisplayCalculateFrameSkip();