[Scummvm-git-logs] scummvm master -> e844981cd029b1c3d1815ef8d81f9ec5fb2189e1

sev- sev at scummvm.org
Mon Mar 29 18:25:45 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e844981cd0 BACKENDS: MACOS: Query number of MIDI devices at the start of ScummVM in a thread


Commit: e844981cd029b1c3d1815ef8d81f9ec5fb2189e1
    https://github.com/scummvm/scummvm/commit/e844981cd029b1c3d1815ef8d81f9ec5fb2189e1
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-03-29T20:25:37+02:00

Commit Message:
BACKENDS: MACOS: Query number of MIDI devices at the start of ScummVM in a thread

The call to MIDIGetNumberOfDestinations() starts the MIDI server which takes
3-4l seconds even on the modern hardware. We are querying this in the GUI Options
which then lags on the first launch.

Thus, we are creating a separate thread and make this call at the start of
ScummVM, so by the time the user gets to the GUI, the server is already launched
and there is no lag.

Of course, that would mean that we will launch MIDI even for the games which are
not using it, so this is a tradeoff for the better UX.

Changed paths:
    backends/platform/sdl/macosx/macosx.cpp


diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp
index 49f4a2c14a..331e56e54d 100644
--- a/backends/platform/sdl/macosx/macosx.cpp
+++ b/backends/platform/sdl/macosx/macosx.cpp
@@ -45,6 +45,18 @@
 #include "ApplicationServices/ApplicationServices.h"	// for LSOpenFSRef
 #include "CoreFoundation/CoreFoundation.h"	// for CF* stuff
 
+// For querying number of MIDI devices
+#include <pthread.h>
+#include <CoreMIDI/CoreMIDI.h>
+
+void *coreMIDIthread(void *threadarg) {
+	(void)MIDIGetNumberOfDestinations();
+
+	pthread_exit(NULL);
+
+	return NULL;
+}
+
 OSystem_MacOSX::~OSystem_MacOSX() {
 	releaseMenu();
 }
@@ -64,6 +76,15 @@ void OSystem_MacOSX::init() {
 	_dialogManager = new MacOSXDialogManager();
 #endif
 
+	// The call to query the number of MIDI devices is ubiquitously slow
+	// on the first run. This is apparent when opening Options in GUI,
+	// which takes 2-3 secs.
+	//
+	// Thus, we are launching it now, in a separate thread, so
+	// the subsequent calls are instantaneous
+	pthread_t thread;
+	pthread_create(&thread, NULL, coreMIDIthread, NULL);
+
 	// Invoke parent implementation of this method
 	OSystem_POSIX::init();
 }




More information about the Scummvm-git-logs mailing list