diff --git a/README.md b/README.md index 864ed2e51..5c187a445 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ You can use `--help` or `-h` to view a list of command-line options. Briefly out --no-exit - do not display 'exit' in the ES menu. --debug - print additional output to the console, primarily about input. --windowed - run ES in a window, works best in conjunction with --resolution [w] [h]. +--vsync [0/1] - turn vsync on or off (default is on), only works in fullscreen. --scrape - run the interactive command-line metadata scraper. ``` diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index 50889da91..d506d0f9f 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -61,14 +61,13 @@ SystemData::~SystemData() delete mRootFolder; } -std::string strreplace(std::string& str, std::string replace, std::string with) +std::string strreplace(std::string str, const std::string& replace, const std::string& with) { - size_t pos = str.find(replace); - - if(pos != std::string::npos) - return str.replace(pos, replace.length(), with.c_str(), with.length()); - else - return str; + size_t pos; + while((pos = str.find(replace)) != std::string::npos) + str = str.replace(pos, replace.length(), with.c_str(), with.length()); + + return str; } std::string escapePath(const boost::filesystem::path& path) diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index c631264d7..383958896 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -57,6 +57,10 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height }else if(strcmp(argv[i], "--windowed") == 0) { Settings::getInstance()->setBool("Windowed", true); + }else if(strcmp(argv[i], "--vsync") == 0) + { + Settings::getInstance()->setBool("VSync", atoi(argv[i + 1])); + i++; // skip vsync value }else if(strcmp(argv[i], "--scrape") == 0) { scrape_cmdline = true; @@ -75,6 +79,7 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height "--debug even more logging\n" "--scrape scrape using command line interface\n" "--windowed not fullscreen, should be used with --resolution\n" + "--vsync [0/1] turn vsync on or off (default is on)\n" "--help, -h summon a sentient, angry tuba\n\n" "More information available in README.md.\n"; return false; //exit after printing help diff --git a/es-core/src/Renderer_init_sdlgl.cpp b/es-core/src/Renderer_init_sdlgl.cpp index dcc13ebfd..6924749b3 100644 --- a/es-core/src/Renderer_init_sdlgl.cpp +++ b/es-core/src/Renderer_init_sdlgl.cpp @@ -49,7 +49,6 @@ namespace Renderer #ifdef USE_OPENGL_ES SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); #endif - //SDL_GL_SetSwapInterval(1); //0 for immediate updates, 1 for updates synchronized with the vertical retrace, -1 for late swap tearing SDL_DisplayMode dispMode; SDL_GetDesktopDisplayMode(0, &dispMode); @@ -96,6 +95,19 @@ namespace Renderer sdlContext = SDL_GL_CreateContext(sdlWindow); + // vsync + if(Settings::getInstance()->getBool("VSync")) + { + // SDL_GL_SetSwapInterval(0) for immediate updates (no vsync, default), + // 1 for updates synchronized with the vertical retrace, + // or -1 for late swap tearing. + // SDL_GL_SetSwapInterval returns 0 on success, -1 on error. + // if vsync is requested, try late swap tearing; if that doesn't work, try normal vsync + // if that doesn't work, report an error + if(SDL_GL_SetSwapInterval(-1) != 0 && SDL_GL_SetSwapInterval(1) != 0) + LOG(LogWarning) << "Tried to enable vsync, but failed! (" << SDL_GetError() << ")"; + } + //hide mouse cursor initialCursorState = SDL_ShowCursor(0) == 1; diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 34c82773c..be3d7fd62 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -16,6 +16,7 @@ std::vector settings_dont_save = boost::assign::list_of ("ParseGamelistOnly") ("ShowExit") ("Windowed") + ("VSync") ("IgnoreGamelist"); Settings::Settings() @@ -41,6 +42,15 @@ void Settings::setDefaults() mBoolMap["DrawFramerate"] = false; mBoolMap["ShowExit"] = true; mBoolMap["Windowed"] = false; + +#ifdef _RPI_ + // don't enable VSync by default on the Pi, since it already + // has trouble trying to render things at 60fps in certain menus + mBoolMap["VSync"] = false; +#else + mBoolMap["VSync"] = true; +#endif + mBoolMap["EnableSounds"] = true; mBoolMap["ShowHelpPrompts"] = true; mBoolMap["ScrapeRatings"] = true; diff --git a/es-core/src/Sound.cpp b/es-core/src/Sound.cpp index adbfa9cf3..c915ea544 100644 --- a/es-core/src/Sound.cpp +++ b/es-core/src/Sound.cpp @@ -111,7 +111,7 @@ void Sound::play() if(mSampleData == NULL) return; - if(Settings::getInstance()->getBool("EnableSounds")) + if(!Settings::getInstance()->getBool("EnableSounds")) return; SDL_LockAudio();