Be consistent about how we read and update the UI state variable

This commit is contained in:
Henrik Rydgard 2014-06-22 09:38:46 +02:00
parent b5435260b0
commit 6ec74ef99e
10 changed files with 30 additions and 24 deletions

View file

@ -136,13 +136,13 @@ static inline void UpdateRunLoop() {
EndInputState(&input_state);
}
if (globalUIState != UISTATE_EXIT) {
if (GetUIState() != UISTATE_EXIT) {
NativeRender();
}
}
void Core_RunLoop() {
while ((globalUIState != UISTATE_INGAME || !PSP_IsInited()) && globalUIState != UISTATE_EXIT) {
while ((GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT) {
time_update();
#if defined(USING_WIN_UI)
@ -161,7 +161,7 @@ void Core_RunLoop() {
#endif
}
while (!coreState && globalUIState == UISTATE_INGAME) {
while (!coreState && GetUIState() == UISTATE_INGAME) {
time_update();
UpdateRunLoop();
#if defined(USING_WIN_UI)
@ -203,9 +203,9 @@ void Core_Run()
#endif
{
reswitch:
if (globalUIState != UISTATE_INGAME) {
if (GetUIState() != UISTATE_INGAME) {
CoreStateProcessed();
if (globalUIState == UISTATE_EXIT) {
if (GetUIState() == UISTATE_EXIT) {
return;
}
Core_RunLoop();

View file

@ -26,5 +26,5 @@
int PSPMixer::Mix(short *stereoout, int numSamples)
{
return __AudioMix(stereoout, numSamples);
return __AudioMix(stereoout, numSamples);
}

View file

@ -72,7 +72,7 @@ enum CPUThreadState {
MetaFileSystem pspFileSystem;
ParamSFOData g_paramSFO;
GlobalUIState globalUIState;
static GlobalUIState globalUIState;
static CoreParameter coreParameter;
static PSPMixer *mixer;
static std::thread *cpuThread = NULL;
@ -96,6 +96,10 @@ void UpdateUIState(GlobalUIState newState) {
}
}
GlobalUIState GetUIState() {
return globalUIState;
}
bool IsAudioInitialised() {
return mixer != NULL;
}

View file

@ -45,9 +45,9 @@ enum PSPDirectories {
DIRECTORY_DUMP,
};
extern GlobalUIState globalUIState;
void UpdateUIState(GlobalUIState newState);
GlobalUIState GetUIState();
bool PSP_Init(const CoreParameter &coreParam, std::string *error_string);
bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string);

View file

@ -118,7 +118,7 @@ void EmuScreen::bootGame(const std::string &filename) {
}
void EmuScreen::bootComplete() {
globalUIState = UISTATE_INGAME;
UpdateUIState(UISTATE_INGAME);
host->BootDone();
host->UpdateDisassembly();

View file

@ -76,4 +76,6 @@ private:
// In-memory save state used for freezeFrame, which is useful for debugging.
std::vector<u8> freezeState_;
std::string tag_;
};

View file

@ -1063,7 +1063,7 @@ UI::EventReturn MainScreen::OnExit(UI::EventParams &e) {
exit(0);
#endif
globalUIState = UISTATE_EXIT;
UpdateUIState(UISTATE_EXIT);
return UI::EVENT_DONE;
}

View file

@ -816,7 +816,7 @@ void CDisasm::SetDebugMode(bool _bDebug, bool switchPC)
HWND hDlg = m_hDlg;
// Update Dialog Windows
if (_bDebug && globalUIState == UISTATE_INGAME && PSP_IsInited())
if (_bDebug && GetUIState() == UISTATE_INGAME && PSP_IsInited())
{
Core_WaitInactive(TEMP_BREAKPOINT_WAIT_MS);
CBreakPoints::ClearTemporaryBreakPoints();
@ -849,7 +849,7 @@ void CDisasm::SetDebugMode(bool _bDebug, bool switchPC)
{
updateThreadLabel(true);
if (globalUIState == UISTATE_INGAME && PSP_IsInited())
if (GetUIState() == UISTATE_INGAME && PSP_IsInited())
{
SetDlgItemText(m_hDlg, IDC_STOPGO, L"Stop");
EnableWindow( GetDlgItem(hDlg, IDC_STOPGO), TRUE);

View file

@ -58,7 +58,7 @@ void EmuThread_Stop()
return;
}
globalUIState = UISTATE_EXIT;
UpdateUIState(UISTATE_EXIT);
Core_Stop();
Core_WaitInactive(800);
if (WAIT_TIMEOUT == WaitForSingleObject(emuThread, 800))
@ -132,7 +132,7 @@ unsigned int WINAPI TheThread(void *)
Core_EnableStepping(FALSE);
while (globalUIState != UISTATE_EXIT)
while (GetUIState() != UISTATE_EXIT)
{
// We're here again, so the game quit. Restart Core_Run() which controls the UI.
// This way they can load a new game.

View file

@ -267,7 +267,7 @@ namespace MainWindow {
}
void CorrectCursor() {
bool autoHide = g_Config.bFullScreen && !mouseButtonDown && globalUIState == UISTATE_INGAME;
bool autoHide = g_Config.bFullScreen && !mouseButtonDown && GetUIState() == UISTATE_INGAME;
if (autoHide && hideCursor) {
while (cursorCounter >= 0) {
cursorCounter = ShowCursor(FALSE);
@ -652,7 +652,7 @@ namespace MainWindow {
// TODO: Urgh! Why do we need this here?
// The menu is supposed to enable/disable this stuff directly afterward.
SetIngameMenuItemStates(globalUIState);
SetIngameMenuItemStates(GetUIState());
DrawMenuBar(hwndMain);
UpdateMenus();
@ -837,7 +837,7 @@ namespace MainWindow {
}
browsePauseAfter = false;
if (globalUIState == UISTATE_INGAME) {
if (GetUIState() == UISTATE_INGAME) {
browsePauseAfter = Core_IsStepping();
if (!browsePauseAfter)
Core_EnableStepping(true);
@ -858,7 +858,7 @@ namespace MainWindow {
Core_EnableStepping(false);
}
} else {
if (globalUIState == UISTATE_INGAME || globalUIState == UISTATE_PAUSEMENU) {
if (GetUIState() == UISTATE_INGAME || GetUIState() == UISTATE_PAUSEMENU) {
Core_EnableStepping(false);
}
@ -1020,7 +1020,7 @@ namespace MainWindow {
g_activeWindow = WINDOW_MAINWINDOW;
pause = false;
}
if (!noFocusPause && g_Config.bPauseOnLostFocus && globalUIState == UISTATE_INGAME) {
if (!noFocusPause && g_Config.bPauseOnLostFocus && GetUIState() == UISTATE_INGAME) {
if (pause != Core_IsStepping()) { // != is xor for bools
if (disasmWindow[0])
SendMessage(disasmWindow[0]->GetDlgHandle(), WM_COMMAND, IDC_STOPGO, 0);
@ -1100,7 +1100,7 @@ namespace MainWindow {
break;
case ID_TOGGLE_PAUSE:
if (globalUIState == UISTATE_PAUSEMENU) {
if (GetUIState() == UISTATE_PAUSEMENU) {
// Causes hang
//NativeMessageReceived("run", "");
@ -1814,18 +1814,18 @@ namespace MainWindow {
static GlobalUIState lastGlobalUIState = UISTATE_PAUSEMENU;
static CoreState lastCoreState = CORE_ERROR;
if (lastGlobalUIState == globalUIState && lastCoreState == coreState)
if (lastGlobalUIState == GetUIState() && lastCoreState == coreState)
return;
lastCoreState = coreState;
lastGlobalUIState = globalUIState;
lastGlobalUIState = GetUIState();
HMENU menu = GetMenu(GetHWND());
bool isPaused = Core_IsStepping() && globalUIState == UISTATE_INGAME;
bool isPaused = Core_IsStepping() && GetUIState() == UISTATE_INGAME;
TranslateMenuItem(ID_TOGGLE_PAUSE, L"\tF8", isPaused ? "Run" : "Pause");
SetIngameMenuItemStates(globalUIState);
SetIngameMenuItemStates(GetUIState());
EnableMenuItem(menu, ID_DEBUG_LOG, !g_Config.bEnableLogging);
}