Skip to content

Commit

Permalink
Merge pull request #18309 from hrydgard/menu-throttle
Browse files Browse the repository at this point in the history
Move the menu frame-rate throttling to NativeFrame
  • Loading branch information
hrydgard committed Oct 4, 2023
2 parents 5b14cb6 + ae0c1e8 commit 14c7eda
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
17 changes: 0 additions & 17 deletions Core/Core.cpp
Expand Up @@ -212,24 +212,7 @@ void Core_RunLoop(GraphicsContext *ctx) {
return;
}

bool menuThrottle = (GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT;

double startTime;
if (menuThrottle) {
startTime = time_now_d();
}

NativeFrame(ctx);

if (menuThrottle) {
float refreshRate = System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE);
// Simple throttling to not burn the GPU in the menu.
// TODO: This should move into NativeFrame. Also, it's only necessary in MAILBOX or IMMEDIATE presentation modes.
double diffTime = time_now_d() - startTime;
int sleepTime = (int)(1000.0 / refreshRate) - (int)(diffTime * 1000.0);
if (sleepTime > 0)
sleep_ms(sleepTime);
}
}

void Core_DoSingleStep() {
Expand Down
17 changes: 17 additions & 0 deletions UI/NativeApp.cpp
Expand Up @@ -1070,6 +1070,13 @@ static Matrix4x4 ComputeOrthoMatrix(float xres, float yres) {
void NativeFrame(GraphicsContext *graphicsContext) {
PROFILE_END_FRAME();

bool menuThrottle = (GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT;

double startTime;
if (menuThrottle) {
startTime = time_now_d();
}

std::vector<PendingMessage> toProcess;
{
std::lock_guard<std::mutex> lock(pendingMutex);
Expand Down Expand Up @@ -1184,6 +1191,16 @@ void NativeFrame(GraphicsContext *graphicsContext) {
// INFO_LOG(G3D, "Polling graphics context");
graphicsContext->Poll();
}

if (menuThrottle) {
float refreshRate = System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE);
// Simple throttling to not burn the GPU in the menu.
// TODO: This should move into NativeFrame. Also, it's only necessary in MAILBOX or IMMEDIATE presentation modes.
double diffTime = time_now_d() - startTime;
int sleepTime = (int)(1000.0 / refreshRate) - (int)(diffTime * 1000.0);
if (sleepTime > 0)
sleep_ms(sleepTime);
}
}

bool HandleGlobalMessage(UIMessage message, const std::string &value) {
Expand Down

0 comments on commit 14c7eda

Please sign in to comment.