diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index f46b82d89..9ca0c7f7c 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -915,6 +915,12 @@ void FileData::launchGame() const std::string fileName {baseName + Utils::FileSystem::getExtension(romPath)}; const std::string esPath {Utils::FileSystem::getExePath()}; + +#if defined(__ANDROID__) + // On Android we always run in the background, although the logic is a bit different + // as we don't need to wake up the application manually. + bool runInBackground {true}; +#else bool runInBackground {false}; // In addition to the global RunInBackground setting it's possible to define this flag @@ -933,6 +939,7 @@ void FileData::launchGame() // The global setting always applies. if (Settings::getInstance()->getBool("RunInBackground")) runInBackground = true; +#endif #if !defined(_WIN64) // Whether to parse .desktop files on Unix or open apps or alias files on macOS. @@ -1893,8 +1900,7 @@ returnValue = Utils::Platform::launchGameUnix(command, startDirectory, runInBack getSourceFileData()->getSystem()->getFullName()); } else { - std::vector& gameEndParams { - ViewController::getInstance()->getGameEndEventParams()}; + std::vector& gameEndParams {window->getGameEndEventParams()}; gameEndParams.emplace_back("game-end"); gameEndParams.emplace_back(romPath); gameEndParams.emplace_back(getSourceFileData()->metadata.get("name")); diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 6d89232a7..510d6cc71 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -1109,7 +1109,10 @@ bool ViewController::input(InputConfig* config, Input input) // If we're in this state and then register some input, it means that the user is back in ES-DE. // Therefore unset the game launch flag and update all the GUI components. This will re-enable // the video player and scrolling of game names and game descriptions as well as letting the - // screensaver start on schedule. + // screensaver start on schedule. On Android the onResume() method will call the native onResume + // function which will perform the same steps as shown below (on Android we always keep running + // when launching games). +#if !defined(__ANDROID__) if (mWindow->getGameLaunchedState()) { mWindow->setAllowTextScrolling(true); mWindow->setAllowFileAnimation(true); @@ -1119,13 +1122,14 @@ bool ViewController::input(InputConfig* config, Input input) if (config->isMappedTo("a", input) && input.value != 0) return true; // Trigger the game-end event. - if (mGameEndEventParams.size() == 5) { - Scripting::fireEvent(mGameEndEventParams[0], mGameEndEventParams[1], - mGameEndEventParams[2], mGameEndEventParams[3], - mGameEndEventParams[4]); - mGameEndEventParams.clear(); + auto& eventParams = mWindow->getGameEndEventParams(); + if (eventParams.size() == 5) { + Scripting::fireEvent(eventParams[0], eventParams[1], eventParams[2], eventParams[3], + eventParams[4]); + eventParams.clear(); } } +#endif // Open the main menu. if (!(UIModeController::getInstance()->isUIModeKid() && diff --git a/es-app/src/views/ViewController.h b/es-app/src/views/ViewController.h index 6d99cf5b4..f2a5c7107 100644 --- a/es-app/src/views/ViewController.h +++ b/es-app/src/views/ViewController.h @@ -93,7 +93,6 @@ public: mWindow->setBlockInput(true); }; const bool getGameLaunchTriggered() { return (mGameToLaunch != nullptr); } - std::vector& getGameEndEventParams() { return mGameEndEventParams; } bool input(InputConfig* config, Input input) override; void update(int deltaTime) override; @@ -184,7 +183,6 @@ private: std::shared_ptr mSystemListView; ViewTransitionAnimation mLastTransitionAnim; - std::vector mGameEndEventParams; FileData* mGameToLaunch; State mState; diff --git a/es-core/src/Window.h b/es-core/src/Window.h index 8ea2f4fbd..ebfa3b4a5 100644 --- a/es-core/src/Window.h +++ b/es-core/src/Window.h @@ -156,6 +156,7 @@ public: void invalidateCachedBackground(); bool isInvalidatingCachedBackground() { return mInvalidateCacheTimer > 0; } + std::vector& getGameEndEventParams() { return mGameEndEventParams; } bool getGameLaunchedState() { return mGameLaunchedState; } void setAllowTextScrolling(bool value) { mAllowTextScrolling = value; } bool getAllowTextScrolling() { return mAllowTextScrolling; } @@ -207,6 +208,7 @@ private: std::queue> mInfoPopupQueue; std::shared_ptr mPostprocessedBackground; + std::vector mGameEndEventParams; std::string mListScrollText; std::shared_ptr mListScrollFont; float mListScrollOpacity; @@ -223,9 +225,9 @@ private: bool mRenderMediaViewer; bool mRenderLaunchScreen; bool mRenderPDFViewer; - bool mGameLaunchedState; - bool mAllowTextScrolling; - bool mAllowFileAnimation; + std::atomic mGameLaunchedState; + std::atomic mAllowTextScrolling; + std::atomic mAllowFileAnimation; bool mCachedBackground; bool mInvalidatedCachedBackground; bool mInitiateCacheTimer;