SDL events are now parsed on startup before the main application loop.

Also removed the mouse pointer removal hack.
This commit is contained in:
Leon Styhre 2023-01-29 22:38:16 +01:00
parent 6e7e8397c4
commit 5125f81c78
3 changed files with 12 additions and 15 deletions

View file

@ -25,6 +25,7 @@
#include "views/GamelistView.h"
#include "views/ViewController.h"
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_timer.h>
#include <fstream>
@ -537,9 +538,14 @@ bool SystemData::loadConfig()
unsigned int lastTime {0};
unsigned int accumulator {0};
SDL_Event event {};
for (pugi::xml_node system {systemList.child("system")}; system;
system = system.next_sibling("system")) {
// Parse events so that the OS doesn't think the application is hanging on startup,
// this is required as the main application loop hasn't started yet.
while (SDL_PollEvent(&event)) {};
std::string name;
std::string fullname;
std::string sortName;

View file

@ -685,15 +685,7 @@ int main(int argc, char* argv[])
if (Settings::getInstance()->getBool("SplashScreen"))
window->renderSplashScreen(Window::SplashScreenState::SCANNING, 0.0f);
InputManager::getInstance().parseEvent(event);
if (event.type == SDL_QUIT)
return 1;
#if !defined(__APPLE__)
// This hides the mouse cursor during startup, i.e. before we have begun to capture SDL events.
// On macOS this causes the mouse cursor to jump back to the Dock so don't do it on this OS.
SDL_SetRelativeMouseMode(SDL_TRUE);
#endif
while (SDL_PollEvent(&event)) {};
#if defined(_WIN64)
// Hide taskbar if the setting for this is enabled.
@ -769,12 +761,6 @@ int main(int argc, char* argv[])
.count()
<< " ms";
#if !defined(__APPLE__)
// Now that we've finished loading, disable the relative mouse mode or otherwise mouse
// input wouldn't work in any games that are launched.
SDL_SetRelativeMouseMode(SDL_FALSE);
#endif
// Main application loop.
#if defined(__EMSCRIPTEN__)

View file

@ -1112,9 +1112,14 @@ void ViewController::preload()
float loadedSystems {0.0f};
unsigned int lastTime {0};
unsigned int accumulator {0};
SDL_Event event {};
for (auto it = SystemData::sSystemVector.cbegin(); // Line break.
it != SystemData::sSystemVector.cend(); ++it) {
// Parse events so that the OS doesn't think the application is hanging on startup,
// this is required as the main application loop hasn't started yet.
while (SDL_PollEvent(&event)) {};
const std::string entryType {(*it)->isCustomCollection() ? "custom collection" : "system"};
LOG(LogDebug) << "ViewController::preload(): Populating gamelist for " << entryType << " \""
<< (*it)->getName() << "\"";