From 022446bce75ad9f6e1fa9c0fdb96e4e9e621ca71 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 22 Jan 2023 23:24:08 +0100 Subject: [PATCH] Found a better method to limit buffer swaps during splash screen rendering. --- es-app/src/SystemData.cpp | 16 +++++++++++++--- es-app/src/main.cpp | 8 -------- es-app/src/views/ViewController.cpp | 3 +++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index 72fdb29ce..7baa51526 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -25,6 +25,8 @@ #include "views/GamelistView.h" #include "views/ViewController.h" +#include + #include #include #include @@ -511,6 +513,7 @@ bool SystemData::loadConfig() const bool splashScreen {Settings::getInstance()->getBool("SplashScreen")}; float systemCount {0.0f}; float loadedSystems {0.0f}; + long unsigned int lastTime {0}; for (pugi::xml_node system {systemList.child("system")}; system; system = system.next_sibling("system")) { @@ -531,10 +534,17 @@ bool SystemData::loadConfig() path = system.child("path").text().get(); if (splashScreen) { + const long unsigned int curTime {SDL_GetTicks64()}; + const long unsigned int deltaTime {curTime - lastTime}; + lastTime = curTime; ++loadedSystems; - const float progress {glm::mix(0.0f, 0.5f, loadedSystems / systemCount)}; - Window::getInstance()->renderSplashScreen(Window::SplashScreenState::SCANNING, - progress); + // This prevents Renderer::swapBuffers() from being called excessively which + // could lead to significantly longer application startup times. + if (deltaTime > 15) { + const float progress {glm::mix(0.0f, 0.5f, loadedSystems / systemCount)}; + Window::getInstance()->renderSplashScreen(Window::SplashScreenState::SCANNING, + progress); + } } auto nameFindFunc = [&] { diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 7fb8dca4d..d32fc08b6 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -707,15 +707,7 @@ int main(int argc, char* argv[]) AudioManager::getInstance(); MameNames::getInstance(); ThemeData::populateThemeSets(); - // We need to temporarily disable VSync as the splash screen may otherwise slow down - // application startup significantly due to excessive swapBuffers() calls. - const bool splashScreen {Settings::getInstance()->getBool("SplashScreen")}; - const bool vSync {Settings::getInstance()->getBool("VSync")}; - if (splashScreen && vSync) - SDL_GL_SetSwapInterval(0); loadSystemsReturnCode loadSystemsStatus {loadSystemConfigFile()}; - if (splashScreen && vSync) - SDL_GL_SetSwapInterval(1); if (loadSystemsStatus) { // If there was an issue parsing the es_systems.xml file, display an error message. diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 37ca8ee66..fbbd10750 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -1104,6 +1104,9 @@ void ViewController::preload() { unsigned int systemCount {static_cast(SystemData::sSystemVector.size())}; + if (Settings::getInstance()->getBool("SplashScreen")) + mWindow->renderSplashScreen(Window::SplashScreenState::POPULATING, 0.5f); + // This reduces the amount of texture pop-in when loading theme extras. if (!SystemData::sSystemVector.empty()) getSystemListView();