Windows Port: Reduce CPU usage while the emulator is idle.

This commit is contained in:
rogerman 2018-03-03 20:41:23 -08:00
parent e825cddbe5
commit 8fb0d6ddc5
1 changed files with 26 additions and 6 deletions

View File

@ -2082,14 +2082,31 @@ void displayProc()
} }
void displayThread(void*) void displayThread(void *arg)
{ {
for(;;) { do
if(display_die) return; {
if ( (MainWindow == NULL) || IsMinimized(MainWindow->getHWnd()) )
{
WaitForSingleObject(display_wakeup_event, INFINITE);
}
else if ( (emu_paused || !execute || !romloaded) && (!HudEditorMode && !CommonSettings.hud.ShowInputDisplay && !CommonSettings.hud.ShowGraphicalInputDisplay) )
{
WaitForSingleObject(display_wakeup_event, 250);
}
else
{
WaitForSingleObject(display_wakeup_event, 10);
}
if (display_die)
{
break;
}
displayProc(); displayProc();
//Sleep(10); //don't be greedy and use a whole cpu core, but leave room for 60fps
WaitForSingleObject(display_wakeup_event, 10); // same as sleep but lets something wake us up early } while (!display_die);
}
} }
void KillDisplay() void KillDisplay()
@ -2135,6 +2152,8 @@ void Display()
memcpy(db.buffer,dispInfo.masterCustomBuffer,targetSize); memcpy(db.buffer,dispInfo.masterCustomBuffer,targetSize);
slock_unlock(display_mutex); slock_unlock(display_mutex);
SetEvent(display_wakeup_event);
} }
} }
@ -5090,6 +5109,7 @@ DOKEYDOWN:
UpdateWndRects(hwnd); UpdateWndRects(hwnd);
MainWindowToolbar->OnSize(); MainWindowToolbar->OnSize();
SetEvent(display_wakeup_event);
} }
break; break;
} }