Move the menu frame-rate throttling to NativeFrame

Now needed on Android since we added the ability to turn off vsync,
which caused the menu to burn battery by rendering too fast.
This commit is contained in:
Henrik Rydgård 2023-10-04 16:57:06 +02:00
parent f9403efaf0
commit ae0c1e88c3
2 changed files with 17 additions and 17 deletions

View file

@ -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() {

View file

@ -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);
@ -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) {