From 8bd32b60092465763178238f46edaa75d2f0b4d6 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 18 Jan 2021 10:46:57 -0800 Subject: [PATCH] Dialog: Manage status only through accessors. --- Core/Dialog/PSPDialog.cpp | 6 +----- Core/Dialog/PSPDialog.h | 19 +++++++++++-------- Core/Dialog/PSPGamedataInstallDialog.h | 6 ++++++ Core/Dialog/PSPNetconfDialog.cpp | 4 ++-- Core/Dialog/PSPPlaceholderDialog.cpp | 20 +++++++++----------- Core/Dialog/PSPSaveDialog.cpp | 2 +- Core/Dialog/PSPScreenshotDialog.cpp | 22 +++++++++++----------- Core/Dialog/PSPScreenshotDialog.h | 5 +++++ 8 files changed, 46 insertions(+), 38 deletions(-) diff --git a/Core/Dialog/PSPDialog.cpp b/Core/Dialog/PSPDialog.cpp index 561b818684..469d8ae7e8 100644 --- a/Core/Dialog/PSPDialog.cpp +++ b/Core/Dialog/PSPDialog.cpp @@ -28,11 +28,7 @@ #define FADE_TIME 1.0 const float FONT_SCALE = 0.55f; -PSPDialog::PSPDialog() - : status(SCE_UTILITY_STATUS_NONE), pendingStatus(SCE_UTILITY_STATUS_NONE), - pendingStatusTicks(0), lastButtons(0), buttons(0) -{ - +PSPDialog::PSPDialog() { } PSPDialog::~PSPDialog() { diff --git a/Core/Dialog/PSPDialog.h b/Core/Dialog/PSPDialog.h index 5aaeea0dcc..934b79168c 100644 --- a/Core/Dialog/PSPDialog.h +++ b/Core/Dialog/PSPDialog.h @@ -94,23 +94,23 @@ protected: void ChangeStatus(DialogStatus newStatus, int delayUs); void ChangeStatusInit(int delayUs); void ChangeStatusShutdown(int delayUs); + DialogStatus ReadStatus() { + return status; + } // TODO: Remove this once all dialogs are updated. - virtual bool UseAutoStatus() { - return true; - } + virtual bool UseAutoStatus() = 0; void StartFade(bool fadeIn_); void UpdateFade(int animSpeed); virtual void FinishFadeOut(); u32 CalcFadedColor(u32 inColor); - DialogStatus status; - DialogStatus pendingStatus; - u64 pendingStatusTicks; + DialogStatus pendingStatus = SCE_UTILITY_STATUS_NONE; + u64 pendingStatusTicks = 0; - unsigned int lastButtons; - unsigned int buttons; + unsigned int lastButtons = 0; + unsigned int buttons = 0; float fadeTimer; bool isFading; @@ -121,4 +121,7 @@ protected: ImageID cancelButtonImg; int okButtonFlag; int cancelButtonFlag; + +private: + DialogStatus status = SCE_UTILITY_STATUS_NONE; }; diff --git a/Core/Dialog/PSPGamedataInstallDialog.h b/Core/Dialog/PSPGamedataInstallDialog.h index 5c9662e24e..d3ef321ae6 100644 --- a/Core/Dialog/PSPGamedataInstallDialog.h +++ b/Core/Dialog/PSPGamedataInstallDialog.h @@ -46,6 +46,12 @@ public: int Abort(); std::string GetGameDataInstallFileName(SceUtilityGamedataInstallParam *param, std::string filename); +protected: + // TODO: Manage status correctly. + bool UseAutoStatus() override { + return true; + } + private: void UpdateProgress(); void OpenNextFile(); diff --git a/Core/Dialog/PSPNetconfDialog.cpp b/Core/Dialog/PSPNetconfDialog.cpp index b7126d3348..f92385de0e 100644 --- a/Core/Dialog/PSPNetconfDialog.cpp +++ b/Core/Dialog/PSPNetconfDialog.cpp @@ -62,7 +62,7 @@ PSPNetconfDialog::~PSPNetconfDialog() { int PSPNetconfDialog::Init(u32 paramAddr) { // Already running - if (status != SCE_UTILITY_STATUS_NONE) + if (ReadStatus() != SCE_UTILITY_STATUS_NONE) return SCE_ERROR_UTILITY_INVALID_STATUS; requestAddr = paramAddr; @@ -471,7 +471,7 @@ int PSPNetconfDialog::Update(int animSpeed) { } int PSPNetconfDialog::Shutdown(bool force) { - if (status != SCE_UTILITY_STATUS_FINISHED && !force) + if (ReadStatus() != SCE_UTILITY_STATUS_FINISHED && !force) return SCE_ERROR_UTILITY_INVALID_STATUS; PSPDialog::Shutdown(force); diff --git a/Core/Dialog/PSPPlaceholderDialog.cpp b/Core/Dialog/PSPPlaceholderDialog.cpp index 4672d07211..70bf4ccaef 100644 --- a/Core/Dialog/PSPPlaceholderDialog.cpp +++ b/Core/Dialog/PSPPlaceholderDialog.cpp @@ -25,20 +25,18 @@ PSPPlaceholderDialog::~PSPPlaceholderDialog() { } -int PSPPlaceholderDialog::Init() -{ - status = SCE_UTILITY_STATUS_INITIALIZE; +int PSPPlaceholderDialog::Init() { + ChangeStatus(SCE_UTILITY_STATUS_INITIALIZE, 0); return 0; } -int PSPPlaceholderDialog::Update(int animSpeed) -{ - if (status == SCE_UTILITY_STATUS_INITIALIZE) { - status = SCE_UTILITY_STATUS_RUNNING; - } else if (status == SCE_UTILITY_STATUS_RUNNING) { - status = SCE_UTILITY_STATUS_FINISHED; - } else if (status == SCE_UTILITY_STATUS_FINISHED) { - status = SCE_UTILITY_STATUS_SHUTDOWN; +int PSPPlaceholderDialog::Update(int animSpeed) { + if (ReadStatus() == SCE_UTILITY_STATUS_INITIALIZE) { + ChangeStatus(SCE_UTILITY_STATUS_RUNNING, 0); + } else if (ReadStatus() == SCE_UTILITY_STATUS_RUNNING) { + ChangeStatus(SCE_UTILITY_STATUS_FINISHED, 0); + } else if (ReadStatus() == SCE_UTILITY_STATUS_FINISHED) { + ChangeStatus(SCE_UTILITY_STATUS_SHUTDOWN, 0); } return 0; diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index ee584cd698..5a7ffe238a 100755 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -1013,7 +1013,7 @@ int PSPSaveDialog::Update(int animSpeed) break; } - if (status == SCE_UTILITY_STATUS_FINISHED || pendingStatus == SCE_UTILITY_STATUS_FINISHED) + if (ReadStatus() == SCE_UTILITY_STATUS_FINISHED || pendingStatus == SCE_UTILITY_STATUS_FINISHED) Memory::Memcpy(requestAddr, &request, request.common.size); return 0; diff --git a/Core/Dialog/PSPScreenshotDialog.cpp b/Core/Dialog/PSPScreenshotDialog.cpp index acec8d08d4..a4aa6ff5bf 100644 --- a/Core/Dialog/PSPScreenshotDialog.cpp +++ b/Core/Dialog/PSPScreenshotDialog.cpp @@ -61,7 +61,7 @@ PSPScreenshotDialog::~PSPScreenshotDialog() { int PSPScreenshotDialog::Init(u32 paramAddr) { // Already running - if (status != SCE_UTILITY_STATUS_NONE && status != SCE_UTILITY_STATUS_SHUTDOWN) { + if (ReadStatus() != SCE_UTILITY_STATUS_NONE && ReadStatus() != SCE_UTILITY_STATUS_SHUTDOWN) { ERROR_LOG_REPORT(HLE, "sceUtilityScreenshotInitStart(%08x): invalid status", paramAddr); return SCE_ERROR_UTILITY_INVALID_STATUS; } @@ -84,23 +84,23 @@ int PSPScreenshotDialog::Init(u32 paramAddr) { } mode = params_->mode; - status = SCE_UTILITY_STATUS_INITIALIZE; + ChangeStatus(SCE_UTILITY_STATUS_INITIALIZE, 0); return 0; } int PSPScreenshotDialog::Update(int animSpeed) { if (UseAutoStatus()) { - if (status == SCE_UTILITY_STATUS_INITIALIZE) { - status = SCE_UTILITY_STATUS_RUNNING; - } else if (status == SCE_UTILITY_STATUS_RUNNING) { + if (ReadStatus() == SCE_UTILITY_STATUS_INITIALIZE) { + ChangeStatus(SCE_UTILITY_STATUS_RUNNING, 0); + } else if (ReadStatus() == SCE_UTILITY_STATUS_RUNNING) { if (mode == SCE_UTILITY_SCREENSHOT_TYPE_CONT_START) { - status = SCE_UTILITY_STATUS_SCREENSHOT_UNKNOWN; + ChangeStatus(SCE_UTILITY_STATUS_SCREENSHOT_UNKNOWN, 0); } else { - status = SCE_UTILITY_STATUS_FINISHED; + ChangeStatus(SCE_UTILITY_STATUS_FINISHED, 0); } - } else if (status == SCE_UTILITY_STATUS_FINISHED) { - status = SCE_UTILITY_STATUS_SHUTDOWN; + } else if (ReadStatus() == SCE_UTILITY_STATUS_FINISHED) { + ChangeStatus(SCE_UTILITY_STATUS_SHUTDOWN, 0); } } return 0; @@ -108,11 +108,11 @@ int PSPScreenshotDialog::Update(int animSpeed) { int PSPScreenshotDialog::ContStart() { // Based on JPCSP http://code.google.com/p/jpcsp/source/detail?r=3381 - if (status != SCE_UTILITY_STATUS_SCREENSHOT_UNKNOWN) + if (ReadStatus() != SCE_UTILITY_STATUS_SCREENSHOT_UNKNOWN) return SCE_ERROR_UTILITY_INVALID_STATUS; // Check with JPCSPTrace log of Dream Club Portable - status = SCE_UTILITY_STATUS_FINISHED; + ChangeStatus(SCE_UTILITY_STATUS_FINISHED, 0); return 0; } diff --git a/Core/Dialog/PSPScreenshotDialog.h b/Core/Dialog/PSPScreenshotDialog.h index 17e7d083aa..60a639e9ef 100644 --- a/Core/Dialog/PSPScreenshotDialog.h +++ b/Core/Dialog/PSPScreenshotDialog.h @@ -33,6 +33,11 @@ public: virtual void DoState(PointerWrap &p) override; protected: + // TODO: Manage status correctly. + bool UseAutoStatus() override { + return true; + } + int mode; PSPPointer params_; };