From 2592ac32c15622249028fecfb2043eda3129e8be Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sat, 14 Jan 2023 15:57:22 +1100 Subject: [PATCH] osd: Added option to accept SDL game controller/joystick input when losing UI focus. --- docs/source/commandline/commandline-all.rst | 55 ++++++++++++++----- docs/source/commandline/commandline-index.rst | 32 +++++++---- docs/source/commandline/index.rst | 14 ++--- docs/source/commandline/sdlconfig.rst | 4 +- docs/source/commandline/windowsconfig.rst | 49 ++++++++++++++--- src/osd/modules/input/input_rawinput.cpp | 4 +- src/osd/modules/input/input_sdl.cpp | 13 +++-- src/osd/modules/lib/osdobj_common.cpp | 3 +- src/osd/modules/lib/osdobj_common.h | 2 + src/osd/windows/winmain.cpp | 1 - src/osd/windows/winmain.h | 2 - 11 files changed, 126 insertions(+), 53 deletions(-) diff --git a/docs/source/commandline/commandline-all.rst b/docs/source/commandline/commandline-all.rst index a615e5c5b3b..2e84e552b1b 100644 --- a/docs/source/commandline/commandline-all.rst +++ b/docs/source/commandline/commandline-all.rst @@ -4,7 +4,7 @@ Universal Command-line Options ============================== This section contains configuration options that are applicable to *all* MAME -configurations (both including both SDL and Windows native). +configurations (including both SDL and Windows native). .. contents:: :local: @@ -698,9 +698,10 @@ OSD-related Options **-controller_map** / **-ctrlmap** ** Path to a text file containing game controller button and axis mappings in - the format used by SDL2 and Steam. Must use an ASCII-compatible text - encoding with native line endings (e.g. CRLF on Windows). Currently only - supported when using the ``sdlgame`` joystick provider. + the format used by SDL2 and Steam, or ``none`` to use only built-in + mappings. Must use an ASCII-compatible text encoding with native line + endings (e.g. CRLF on Windows). Currently only supported when using the + ``sdlgame`` joystick provider. The default setting is ``none``. A `community-sourced list of game controller mappings `_ can be found on GitHub. @@ -714,10 +715,24 @@ OSD-related Options in the **config** folder inside your Steam installation folder. Example: - .. code-bock:: bash + .. code-block:: bash mame -controller_map gamecontrollerdb.txt sf2ce +.. _mame-commandline-backgroundinput: + +**-[no]background_input** + + Sets whether input is accepted or ignored when MAME does not have UI focus. + Currently supported for RawInput mouse/keyboard input on Windows, and SDL + game controller/joystick input. This setting is ignored when the debugger + is enabled. The default is OFF (**-nobackground_input**). + + Example: + .. code-block:: bash + + mame -background_input ssf2tb + .. _mame-commandline-uifontprovider: **-uifontprovider** ** @@ -912,7 +927,8 @@ Example: **-joystickprovider** ** - Chooses how MAME will get joystick input. The default is ``auto``. + Chooses how MAME will get joystick and other game controller input. The + default is ``auto``. .. list-table:: Supported joystick input providers per-platform :header-rows: 0 @@ -941,19 +957,32 @@ Example: .. [#JIPAutoSDL] On SDL, auto will default to ``sdlgame``. -.. Tip:: Note that Microsoft Xbox 360 and Xbox One controllers connected to - Windows will work best with ``winhybrid`` or ``xinput``. The - ``winhybrid`` option supports a mix of DirectInput and XInput - controllers at the same time. +winhybrid + Uses XInput for compatible game controllers, falling back to DirectInput for + other game controllers. Typically provides the best experience on Windows. +dinput + Uses DirectInput for all game controllers. May be useful if you want to use + more than four XInput game controllers simultaneously. Note that LT and RT + controls are combined with using XInput game controllers via DirectInput. +xinput + Supports up to four XInput game controllers. +sdlgame + Uses the SDL game controller API for game controllers with button/axis + mappings available, falling back to the SDL joystick API for other game + controllers. Provides consistent button and axis assignment and meaningful + control names for popular game controllers. Use the :ref:`controller_map + option ` to supply mappings for additional + game controllers or override built-in mappings. +sdljoy + Uses the SDL joystick API for all game controllers. +none + Ignores all game controllers. Example: .. code-block:: bash mame mk2 -joystickprovider winhybrid -.. Tip:: On Windows, winhybrid is likely to give the best experience by - supporting both XInput and DirectInput controllers. - .. _mame-commandline-cliverbs: diff --git a/docs/source/commandline/commandline-index.rst b/docs/source/commandline/commandline-index.rst index 2e1451af384..7caffd6d3b3 100644 --- a/docs/source/commandline/commandline-index.rst +++ b/docs/source/commandline/commandline-index.rst @@ -1,14 +1,17 @@ .. _index-commandline: -Commandline Index -================= +Command-line Index +================== -This is a complete index of all commandline options and commands for MAME, suitable for quickly finding a given command. +This is a complete index of all command-line options and verbs for MAME, +suitable for quickly finding a given option. -Universal Commandline Options ------------------------------ -This section contains configuration options that are applicable to *all* MAME sub-builds (both SDL and Windows native). +Universal Command-line Options +------------------------------ + +This section contains configuration options that are applicable to *all* MAME +configurations (including both SDL and Windows native). Core Verbs @@ -53,6 +56,8 @@ OSD-related Options ~~~~~~~~~~~~~~~~~~~ | :ref:`uimodekey ` +| :ref:`controller_map ` +| :ref:`background_input ` | :ref:`uifontprovider ` | :ref:`keyboardprovider ` | :ref:`mouseprovider ` @@ -351,8 +356,11 @@ PortAudio Options | :ref:`pa_latency ` -Windows-Specific Commandline Options ------------------------------------- +Windows-Specific Command-line Options +------------------------------------- + +This section contains configuration options that are specific to the native +(non-SDL) Windows version of MAME. Windows Performance Options @@ -377,10 +385,12 @@ Windows Input Device Options | :ref:`[no]dual_lightgun ` -SDL-Specific Commandline Options --------------------------------- -This section contains configuration options that are specific to any build supported by SDL (including Windows where compiled as SDL instead of native). +SDL-Specific Command-line Options +--------------------------------- + +This section contains configuration options that are specific to any build +supported by SDL (including Windows when built with SDL instead of native). SDL Performance Options diff --git a/docs/source/commandline/index.rst b/docs/source/commandline/index.rst index 4237c7f30f4..a03fe113708 100644 --- a/docs/source/commandline/index.rst +++ b/docs/source/commandline/index.rst @@ -1,11 +1,11 @@ -MAME Commandline Usage and OS-Specific Configuration ----------------------------------------------------- +MAME Command-line Usage and OS-Specific Configuration +----------------------------------------------------- .. toctree:: - :titlesonly: + :titlesonly: - commandline-all - windowsconfig - sdlconfig + commandline-all + windowsconfig + sdlconfig - commandline-index + commandline-index diff --git a/docs/source/commandline/sdlconfig.rst b/docs/source/commandline/sdlconfig.rst index 84f31bf89b9..ad9b5a47de8 100644 --- a/docs/source/commandline/sdlconfig.rst +++ b/docs/source/commandline/sdlconfig.rst @@ -1,10 +1,8 @@ SDL-Specific Commandline Options ================================ - This section contains configuration options that are specific to any build -supported by SDL (including Windows where compiled as SDL instead of -native). +supported by SDL (including Windows when built with SDL instead of native). diff --git a/docs/source/commandline/windowsconfig.rst b/docs/source/commandline/windowsconfig.rst index 85f555e9a21..dc0cdac3091 100644 --- a/docs/source/commandline/windowsconfig.rst +++ b/docs/source/commandline/windowsconfig.rst @@ -1,7 +1,8 @@ -Windows-Specific Commandline Options -==================================== +Windows-Specific Command-line Options +===================================== -This section contains configuration options that are specific to the native (non-SDL) Windows version of MAME. +This section contains configuration options that are specific to the native +(non-SDL) Windows version of MAME. @@ -12,7 +13,10 @@ Performance options **-priority** ** - Sets the thread priority for the MAME threads. By default the priority is left alone to guarantee proper cooperation with other applications. The valid range is -15 to 1, with 1 being the highest priority. The default is *0* (*NORMAL priority*). + Sets the thread priority for the MAME threads. By default the priority is + left alone to guarantee proper cooperation with other applications. The + valid range is -15 to 1, with 1 being the highest priority. The default is + *0* (*NORMAL priority*). .. _mame-wcommandline-profile: @@ -28,25 +32,46 @@ Full screen options **-[no]triplebuffer** / **-[no]tb** - Enables or disables "triple buffering". Normally, MAME just draws directly to the screen, without any fancy buffering. But with this option enabled, MAME creates three buffers to draw to, and cycles between them in order. It attempts to keep things flowing such that one buffer is currently displayed, the second buffer is waiting to be displayed, and the third buffer is being drawn to. **-triplebuffer** will override **-waitvsync**, if the buffer is successfully created. This option does not work with **-video gdi**. The default is OFF (**-notriplebuffer**). + Enables or disables “triple buffering”. Normally, MAME just draws directly + to the screen, without any fancy buffering. But with this option enabled, + MAME creates three buffers to draw to, and cycles between them in order. It + attempts to keep things flowing such that one buffer is currently displayed, + the second buffer is waiting to be displayed, and the third buffer is being + drawn to. **-triplebuffer** will override **-waitvsync**, if the buffer is + successfully created. This option does not work with **-video gdi**. The + default is OFF (**-notriplebuffer**). .. _mame-wcommandline-fullscreenbrightness: **-full_screen_brightness** ** / **-fsb** ** - Controls the brightness, or black level, of the entire display. The standard value is 1.0. Selecting lower values (down to 0.1) will produce a darkened display, while selecting higher values (up to 2.0) will give a brighter display. Note that not all video cards have hardware to support this option. This option does not work with **-video gdi**. The default is ``1.0``. + Controls the brightness, or black level, of the entire display. The + standard value is 1.0. Lower values (down to 0.1) will produce a darkened + display, while higher values (up to 2.0) will give a brighter display. Note + that not all video cards have hardware to support this option. This option + does not work with **-video gdi**. The default is *1.0*. .. _mame-wcommandline-fullscreencontrast: **-full_screen_contrast** ** / **-fsc** ** - Controls the contrast, or white level, of the entire display. The standard value is 1.0. Selecting lower values (down to 0.1) will produce a dimmer display, while selecting higher values (up to 2.0) will give a more saturated display. Note that not all video cards have hardware to support this option. This option does not work with **-video gdi**. The default is ``1.0``. + Controls the contrast, or white level, of the entire display. The standard + value is 1.0. Lower values (down to 0.1) will produce a dimmer display, + while higher values (up to 2.0) will give a more saturated display. Note + that not all video cards have hardware to support this option. This option + does not work with **-video gdi**. The default is *1.0*. .. _mame-wcommandline-fullscreengamma: **-full_screen_gamma** ** / **-fsg** ** - Controls the gamma, which produces a potentially nonlinear black to white ramp, for the entire display. The standard value is 1.0, which gives a linear ramp from black to white. Selecting lower values (down to 0.1) will increase the nonlinearity toward black, while selecting higher values (up to 3.0) will push the nonlinearity toward white. Note that not all video cards have hardware to support this option. This option does not work with **-video gdi**. The default is ``1.0``. + Controls the gamma, which produces a potentially nonlinear black to white + ramp, for the entire display. The standard value is 1.0, which gives a + linear ramp from black to white. Lower values (down to 0.1) will increase + the nonlinearity toward black, while higher values (up to 3.0) will push the + nonlinearity toward white. Note that not all video cards have hardware to + support this option. This option does not work with **-video gdi**. The + default is *1.0*. @@ -57,4 +82,10 @@ Input device options **-[no]dual_lightgun** / **-[no]dual** - Controls whether or not MAME attempts to track two lightguns connected at the same time. This option requires -lightgun. This option is a hack for supporting certain older dual lightgun setups. If you have multiple lightguns connected, you will probably just need to enable -mouse and configure each lightgun independently. The default is *OFF* (**-nodual_lightgun**). + Controls whether or not MAME attempts to track two lightguns connected + simultaneously. This option requires the :ref:`lightgun option + ` to be on. This option is a hack for supporting + certain older dual lightgun setups. If you have multiple lightguns + connected, you will probably just need to enable the :ref:`mouse option + ` and configure each lightgun independently. The + default is OFF (**-nodual_lightgun**). diff --git a/src/osd/modules/input/input_rawinput.cpp b/src/osd/modules/input/input_rawinput.cpp index 94018f9c404..c681017a061 100644 --- a/src/osd/modules/input/input_rawinput.cpp +++ b/src/osd/modules/input/input_rawinput.cpp @@ -481,9 +481,9 @@ public: for (int devnum = retrieved - 1; devnum >= 0; devnum--) add_rawinput_device(machine, rawinput_devices[devnum]); - // don't enable global inputs when debugging + // don't enable background input when debugging if (!machine.options().debug()) - m_global_inputs_enabled = downcast(machine.options()).global_inputs(); + m_global_inputs_enabled = options()->background_input(); // If we added no devices, no need to register for notifications if (devicelist().empty()) diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp index b54af499dbb..295935fda88 100644 --- a/src/osd/modules/input/input_sdl.cpp +++ b/src/osd/modules/input/input_sdl.cpp @@ -1859,6 +1859,11 @@ public: virtual void input_init(running_machine &machine) override { + auto &sdlopts = downcast(*options()); + bool const sixaxis_mode = sdlopts.sixaxis(); + + if (!machine().options().debug && sdlopts.background_input()) + SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); init_joystick(); @@ -1867,8 +1872,6 @@ public: sdl_joystick_module_base::input_init(machine); - bool const sixaxis_mode = downcast(options())->sixaxis(); - osd_printf_verbose("Joystick: Start initialization\n"); for (int physical_stick = 0; physical_stick < SDL_NumJoysticks(); physical_stick++) create_joystick_device(machine, physical_stick, sixaxis_mode); @@ -1947,11 +1950,13 @@ public: virtual void input_init(running_machine &machine) override { - SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); - auto &sdlopts = downcast(*options()); bool const sixaxis_mode = sdlopts.sixaxis(); + if (!machine().options().debuge() && sdlopts.background_input()) + SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); + SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); + init_joystick(); if (!have_joystick()) return; diff --git a/src/osd/modules/lib/osdobj_common.cpp b/src/osd/modules/lib/osdobj_common.cpp index c6f551b63fc..9aab7f1dec0 100644 --- a/src/osd/modules/lib/osdobj_common.cpp +++ b/src/osd/modules/lib/osdobj_common.cpp @@ -29,13 +29,14 @@ const options_entry osd_options::s_option_entries[] = { - { nullptr, nullptr, core_options::option_type::HEADER, "OSD KEYBOARD MAPPING OPTIONS" }, + { nullptr, nullptr, core_options::option_type::HEADER, "OSD INPUT MAPPING OPTIONS" }, #if defined(SDLMAME_MACOSX) || defined(OSD_MAC) { OSDOPTION_UIMODEKEY, "DEL", core_options::option_type::STRING, "key to enable/disable MAME controls when emulated system has keyboard inputs" }, #else { OSDOPTION_UIMODEKEY, "auto", core_options::option_type::STRING, "key to enable/disable MAME controls when emulated system has keyboard inputs" }, #endif // SDLMAME_MACOSX { OSDOPTION_CONTROLLER_MAP_FILE ";ctrlmap", OSDOPTVAL_NONE, core_options::option_type::PATH, "game controller mapping file" }, + { OSDOPTION_BACKGROUND_INPUT, "0", core_options::option_type::BOOLEAN, "don't ignore input when losing UI focus" }, { nullptr, nullptr, core_options::option_type::HEADER, "OSD FONT OPTIONS" }, { OSD_FONT_PROVIDER, OSDOPTVAL_AUTO, core_options::option_type::STRING, "provider for UI font: " }, diff --git a/src/osd/modules/lib/osdobj_common.h b/src/osd/modules/lib/osdobj_common.h index 92a9a498c3c..bf680195fca 100644 --- a/src/osd/modules/lib/osdobj_common.h +++ b/src/osd/modules/lib/osdobj_common.h @@ -36,6 +36,7 @@ #define OSDOPTION_UIMODEKEY "uimodekey" #define OSDOPTION_CONTROLLER_MAP_FILE "controller_map" +#define OSDOPTION_BACKGROUND_INPUT "background_input" #define OSDCOMMAND_LIST_MIDI_DEVICES "listmidi" #define OSDCOMMAND_LIST_NETWORK_ADAPTERS "listnetwork" @@ -109,6 +110,7 @@ public: // keyboard mapping const char *ui_mode_key() const { return value(OSDOPTION_UIMODEKEY); } const char *controller_mapping_file() const { return value(OSDOPTION_CONTROLLER_MAP_FILE); } + bool background_input() const { return bool_value(OSDOPTION_BACKGROUND_INPUT); } // debugging options const char *debugger() const { return value(OSDOPTION_DEBUGGER); } diff --git a/src/osd/windows/winmain.cpp b/src/osd/windows/winmain.cpp index 91c78be5b20..3311031228f 100644 --- a/src/osd/windows/winmain.cpp +++ b/src/osd/windows/winmain.cpp @@ -276,7 +276,6 @@ const options_entry windows_options::s_option_entries[] = // input options { nullptr, nullptr, core_options::option_type::HEADER, "INPUT DEVICE OPTIONS" }, - { WINOPTION_GLOBAL_INPUTS, "0", core_options::option_type::BOOLEAN, "enable global inputs" }, { WINOPTION_DUAL_LIGHTGUN ";dual", "0", core_options::option_type::BOOLEAN, "enable dual lightgun input" }, { nullptr } diff --git a/src/osd/windows/winmain.h b/src/osd/windows/winmain.h index 7c1689cff9f..7c148c94e5b 100644 --- a/src/osd/windows/winmain.h +++ b/src/osd/windows/winmain.h @@ -116,7 +116,6 @@ #define WINOPTION_FULLSCREENGAMMA "full_screen_gamma" // input options -#define WINOPTION_GLOBAL_INPUTS "global_inputs" #define WINOPTION_DUAL_LIGHTGUN "dual_lightgun" //============================================================ @@ -228,7 +227,6 @@ public: float full_screen_gamma() const { return float_value(WINOPTION_FULLSCREENGAMMA); } // input options - bool global_inputs() const { return bool_value(WINOPTION_GLOBAL_INPUTS); } bool dual_lightgun() const { return bool_value(WINOPTION_DUAL_LIGHTGUN); } static const options_entry s_option_entries[];