diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 43958384b..9d7c97402 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -26,10 +26,6 @@ #include -#ifdef _WIN64 -#include -#endif - FileData::FileData( FileType type, const std::string& path, @@ -549,14 +545,13 @@ void FileData::launchGame(Window* window) Utils::String::toUpper(std::to_string(returnValue) + ")"), 6000); window->setInfoPopup(s); } - // This code is only needed for Windows, where we need to keep ES running while - // the game/emulator is in use. It's basically used to pause any playing game video. #ifdef _WIN64 + // This code is only needed for Windows, where we may need to keep ES running while + // the game/emulator is in use. It's basically used to pause any playing game video + // and to keep the screensaver from activating. else { - window->setLaunchedGame(); - // Temporary hack to stop the user from sending any input to ES while - // the game is launching. - SDL_Delay(3000); + if (Settings::getInstance()->getBool("RunInBackground")) + window->setLaunchedGame(); } #endif diff --git a/es-app/src/animations/LaunchAnimation.h b/es-app/src/animations/LaunchAnimation.h index dc593a062..cff2e6486 100644 --- a/es-app/src/animations/LaunchAnimation.h +++ b/es-app/src/animations/LaunchAnimation.h @@ -56,6 +56,12 @@ public: void apply(float t) override { + // TEMPORARY - disabled the launch animations as they don't work properly and more + // work is needed to fix them. This has been done in LaunchAnimation.h instead of in + // ViewController as not calling the animation leads to input not being properly + // consumed. This also needs to be fixed later on. + return; + cameraOut = Transform4x4f::Identity(); float zoom = Math::lerp(1.0, 4.25f, t*t); diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 9f0c347f2..736d6bd53 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -601,6 +601,13 @@ void GuiMenu::openOtherSettings() s->addWithLabel("HIDE TASKBAR (REQUIRES RESTART)", hide_taskbar); s->addSaveFunc([hide_taskbar] { Settings::getInstance()-> setBool("HideTaskbar", hide_taskbar->getState()); }); + + // Run ES in the background when a game has been launched. + auto run_in_background = std::make_shared(mWindow); + run_in_background->setState(Settings::getInstance()->getBool("RunInBackground")); + s->addWithLabel("RUN IN BACKGROUND (WHILE GAME IS LAUNCHED)", run_in_background); + s->addSaveFunc([run_in_background] { Settings::getInstance()-> + setBool("RunInBackground", run_in_background->getState()); }); #endif // Allow overriding of the launch command per game (the option to disable this is diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 61642b91c..2508391f2 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -264,13 +264,21 @@ void ViewController::launch(FileData* game, Vector3f center) // Let launch sound play to the end before launching game. while (NavigationSounds::getInstance()->isPlayingThemeNavigationSound(LAUNCHSOUND)); - game->launchGame(mWindow); - mLockInput = false; - this->onFileChanged(game, FILE_METADATA_CHANGED); - // TEMPORARY - disabled the launch animations as they don't work properly and more - // work is needed to fix them. - // + // work is needed to fix them. This has been done in LaunchAnimation.h instead of here, + // as not calling the animation leads to input not being properly consumed. This also + // needs to be fixed later on. + setAnimation(new LaunchAnimation(mCamera, mFadeOpacity, center, 1500), 0, + [this, origCamera, center, game] { + game->launchGame(mWindow); + mCamera = origCamera; + setAnimation(new LaunchAnimation(mCamera, mFadeOpacity, center, 600), 0, [this] { + mLockInput = false; }, true); + this->onFileChanged(game, FILE_METADATA_CHANGED); + if (mCurrentView) + mCurrentView->onShow(); + }); + // if (transition_style == "fade") { // // Fade out, launch game, fade back in. // auto fadeFunc = [this](float t) { @@ -409,20 +417,22 @@ std::shared_ptr ViewController::getSystemListView() return mSystemListView; } - bool ViewController::input(InputConfig* config, Input input) { if (mLockInput) return true; - // This code is only needed for Windows, where we need to keep ES running while - // the game/emulator is in use. It's basically used to pause any playing game video. #ifdef _WIN64 - // If we have previously launched a game and there is now input registered, it means - // the user is back in ES, so unset the flag to indicate that a game has been launched - // and update all the GUI components to reflect this. - if (mWindow->getGameLaunchedState()) { - mWindow->unsetLaunchedGame(); + // This code is only needed for Windows, where we may need to keep ES running while + // the game/emulator is in use. It's basically used to pause any playing game video + // and to keep the screensaver from activating. + if (Settings::getInstance()->getBool("RunInBackground")) { + // If we have previously launched a game and there is now input registered, it means + // the user is back in ES, so unset the flag to indicate that a game has been launched + // and update all the GUI components to reflect this. + bool testbool = mWindow->getGameLaunchedState(); + if (mWindow->getGameLaunchedState()) + mWindow->unsetLaunchedGame(); } #endif @@ -550,12 +560,15 @@ void ViewController::reloadGameListView(IGameListView* view, bool reloadTheme) } } - // This code is only needed for Windows, where we need to keep ES running while - // the game/emulator is in use. It's basically used to pause any playing game video. #ifdef _WIN64 - // If a game has been launched, then update all the GUI components to reflect this. - if (mWindow->getGameLaunchedState()) - mWindow->setLaunchedGame(); + // This code is only needed for Windows, where we may need to keep ES running while + // the game/emulator is in use. It's basically used to pause any playing game video + // and to keep the screensaver from activating. + if (Settings::getInstance()->getBool("RunInBackground")) { + // If a game has been launched, then update all the GUI components to reflect this. + if (mWindow->getGameLaunchedState()) + mWindow->setLaunchedGame(); + } #endif // Redisplay the current view. diff --git a/es-core/src/Platform.cpp b/es-core/src/Platform.cpp index e7215d4d5..939e9bbcd 100644 --- a/es-core/src/Platform.cpp +++ b/es-core/src/Platform.cpp @@ -11,6 +11,7 @@ #include "AudioManager.h" #include "Log.h" #include "MameNames.h" +#include "Settings.h" #if defined(__linux__) || defined(_WIN64) #include @@ -138,13 +139,15 @@ int launchEmulatorWindows(const std::wstring& cmd_utf16) &pi); // Pointer to the PROCESS_INFORMATION structure. // Unfortunately suspending ES and resuming when the emulator process has exited - // doesn't work reliably on Windows, so we need to keep ES running. Maybe there is - // some workaround for this. Possibly it's just SDL that is glitchy or it's actually - // something OS-specific. Keeping the code here just in case it could be reactivated. - // For sure it would simplify things, like not having to pause playing videos. -// // Wait for the child process to exit. -// WaitForSingleObject(pi.hThread, INFINITE); -// WaitForSingleObject(pi.hProcess, INFINITE); + // doesn't work reliably on Windows, so we may need to keep ES running in the + // background while the game is launched. I'm not sure if there is a workaround + // for this, but on some Windows installations it seems to work fine so we'll let + // the user choose via a menu option. + if (!Settings::getInstance()->getBool("RunInBackground")) { + // Wait for the child process to exit. + WaitForSingleObject(pi.hThread, INFINITE); + WaitForSingleObject(pi.hProcess, INFINITE); + } // If the return value is false, then something failed. if (!processReturnValue) { diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 9a2d7e87d..d2e482fa1 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -187,6 +187,7 @@ void Settings::setDefaults() mStringMap["SaveGamelistsMode"] = "always"; #ifdef _WIN64 mBoolMap["HideTaskbar"] = false; + mBoolMap["RunInBackground"] = true; #endif mStringMap["MediaDirectory"] = ""; mBoolMap["LaunchCommandOverride"] = true;