Changed the game launch state to be kept in Window instead of ViewController

This commit is contained in:
Leon Styhre 2023-12-23 23:03:40 +01:00
parent e1322d711b
commit e3387c9016
4 changed files with 23 additions and 13 deletions

View file

@ -915,6 +915,12 @@ void FileData::launchGame()
const std::string fileName {baseName + Utils::FileSystem::getExtension(romPath)}; const std::string fileName {baseName + Utils::FileSystem::getExtension(romPath)};
const std::string esPath {Utils::FileSystem::getExePath()}; 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}; bool runInBackground {false};
// In addition to the global RunInBackground setting it's possible to define this flag // 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. // The global setting always applies.
if (Settings::getInstance()->getBool("RunInBackground")) if (Settings::getInstance()->getBool("RunInBackground"))
runInBackground = true; runInBackground = true;
#endif
#if !defined(_WIN64) #if !defined(_WIN64)
// Whether to parse .desktop files on Unix or open apps or alias files on macOS. // 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()); getSourceFileData()->getSystem()->getFullName());
} }
else { else {
std::vector<std::string>& gameEndParams { std::vector<std::string>& gameEndParams {window->getGameEndEventParams()};
ViewController::getInstance()->getGameEndEventParams()};
gameEndParams.emplace_back("game-end"); gameEndParams.emplace_back("game-end");
gameEndParams.emplace_back(romPath); gameEndParams.emplace_back(romPath);
gameEndParams.emplace_back(getSourceFileData()->metadata.get("name")); gameEndParams.emplace_back(getSourceFileData()->metadata.get("name"));

View file

@ -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. // 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 // 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 // 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()) { if (mWindow->getGameLaunchedState()) {
mWindow->setAllowTextScrolling(true); mWindow->setAllowTextScrolling(true);
mWindow->setAllowFileAnimation(true); mWindow->setAllowFileAnimation(true);
@ -1119,13 +1122,14 @@ bool ViewController::input(InputConfig* config, Input input)
if (config->isMappedTo("a", input) && input.value != 0) if (config->isMappedTo("a", input) && input.value != 0)
return true; return true;
// Trigger the game-end event. // Trigger the game-end event.
if (mGameEndEventParams.size() == 5) { auto& eventParams = mWindow->getGameEndEventParams();
Scripting::fireEvent(mGameEndEventParams[0], mGameEndEventParams[1], if (eventParams.size() == 5) {
mGameEndEventParams[2], mGameEndEventParams[3], Scripting::fireEvent(eventParams[0], eventParams[1], eventParams[2], eventParams[3],
mGameEndEventParams[4]); eventParams[4]);
mGameEndEventParams.clear(); eventParams.clear();
} }
} }
#endif
// Open the main menu. // Open the main menu.
if (!(UIModeController::getInstance()->isUIModeKid() && if (!(UIModeController::getInstance()->isUIModeKid() &&

View file

@ -93,7 +93,6 @@ public:
mWindow->setBlockInput(true); mWindow->setBlockInput(true);
}; };
const bool getGameLaunchTriggered() { return (mGameToLaunch != nullptr); } const bool getGameLaunchTriggered() { return (mGameToLaunch != nullptr); }
std::vector<std::string>& getGameEndEventParams() { return mGameEndEventParams; }
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
@ -184,7 +183,6 @@ private:
std::shared_ptr<SystemView> mSystemListView; std::shared_ptr<SystemView> mSystemListView;
ViewTransitionAnimation mLastTransitionAnim; ViewTransitionAnimation mLastTransitionAnim;
std::vector<std::string> mGameEndEventParams;
FileData* mGameToLaunch; FileData* mGameToLaunch;
State mState; State mState;

View file

@ -156,6 +156,7 @@ public:
void invalidateCachedBackground(); void invalidateCachedBackground();
bool isInvalidatingCachedBackground() { return mInvalidateCacheTimer > 0; } bool isInvalidatingCachedBackground() { return mInvalidateCacheTimer > 0; }
std::vector<std::string>& getGameEndEventParams() { return mGameEndEventParams; }
bool getGameLaunchedState() { return mGameLaunchedState; } bool getGameLaunchedState() { return mGameLaunchedState; }
void setAllowTextScrolling(bool value) { mAllowTextScrolling = value; } void setAllowTextScrolling(bool value) { mAllowTextScrolling = value; }
bool getAllowTextScrolling() { return mAllowTextScrolling; } bool getAllowTextScrolling() { return mAllowTextScrolling; }
@ -207,6 +208,7 @@ private:
std::queue<std::pair<std::string, int>> mInfoPopupQueue; std::queue<std::pair<std::string, int>> mInfoPopupQueue;
std::shared_ptr<TextureResource> mPostprocessedBackground; std::shared_ptr<TextureResource> mPostprocessedBackground;
std::vector<std::string> mGameEndEventParams;
std::string mListScrollText; std::string mListScrollText;
std::shared_ptr<Font> mListScrollFont; std::shared_ptr<Font> mListScrollFont;
float mListScrollOpacity; float mListScrollOpacity;
@ -223,9 +225,9 @@ private:
bool mRenderMediaViewer; bool mRenderMediaViewer;
bool mRenderLaunchScreen; bool mRenderLaunchScreen;
bool mRenderPDFViewer; bool mRenderPDFViewer;
bool mGameLaunchedState; std::atomic<bool> mGameLaunchedState;
bool mAllowTextScrolling; std::atomic<bool> mAllowTextScrolling;
bool mAllowFileAnimation; std::atomic<bool> mAllowFileAnimation;
bool mCachedBackground; bool mCachedBackground;
bool mInvalidatedCachedBackground; bool mInvalidatedCachedBackground;
bool mInitiateCacheTimer; bool mInitiateCacheTimer;