diff options
author | 2016-04-02 15:37:08 +0200 | |
---|---|---|
committer | 2016-04-02 15:37:08 +0200 | |
commit | 731abe8ba09d51d3418411286d8ed6137ed716ba (patch) | |
tree | 2179a92dce31bfef97532d587f926353b73a633d | |
parent | 0a3f7c37c74986d53784e47027cec74bbf37eaa0 (diff) |
Fixed joystick on Android preventing application to crash, cleanup init for SDL in total (nw)
-rw-r--r-- | scripts/src/3rdparty.lua | 2 | ||||
-rw-r--r-- | src/osd/modules/input/input_sdl.cpp | 35 | ||||
-rw-r--r-- | src/osd/osdcore.cpp | 23 | ||||
-rw-r--r-- | src/osd/sdl/sdlmain.cpp | 14 | ||||
-rw-r--r-- | src/osd/sdl/window.cpp | 2 |
5 files changed, 50 insertions, 26 deletions
diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index 30cb3770a4a..02f1642c235 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -1187,7 +1187,7 @@ if _OPTIONS["targetos"]=="android" then "log", } linkoptions { - "-Wl,-soname,liSDL2.so" + "-Wl,-soname,libSDL2.so" } if _OPTIONS["SEPARATE_BIN"]~="1" then diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp index 2c5b2e45a8c..06096a6961b 100644 --- a/src/osd/modules/input/input_sdl.cpp +++ b/src/osd/modules/input/input_sdl.cpp @@ -681,9 +681,24 @@ public: : sdl_input_module(OSD_JOYSTICKINPUT_PROVIDER) { } - + + virtual void exit() override + { + sdl_input_module::exit(); + + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + } + virtual void input_init(running_machine &machine) override { + SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); + + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK)) + { + osd_printf_error("Could not initialize SDL Joystick: %s.\n", SDL_GetError()); + return; + } + sdl_input_module::input_init(machine); char tempname[512]; @@ -696,20 +711,8 @@ public: int physical_stick; for (physical_stick = 0; physical_stick < SDL_NumJoysticks(); physical_stick++) { - if (SDL_IsGameController(physical_stick)) { - osd_printf_verbose("Joystick %i is supported by the game controller interface!\n", physical_stick); - osd_printf_verbose("Compatible controller, named \'%s\'\n", SDL_GameControllerNameForIndex(physical_stick)); - SDL_GameController *joy = SDL_GameControllerOpen(physical_stick); - osd_printf_verbose("Controller is mapped as \"%s\".\n", SDL_GameControllerMapping(joy)); - std::string joy_name = remove_spaces(SDL_GameControllerName(joy)); - SDL_GameControllerClose(joy); + std::string joy_name = remove_spaces(SDL_JoystickNameForIndex(physical_stick)); devmap_register(&m_joy_map, physical_stick, joy_name.c_str()); - } else { - SDL_Joystick *joy = SDL_JoystickOpen(physical_stick); - std::string joy_name = remove_spaces(SDL_JoystickName(joy)); - SDL_JoystickClose(joy); - devmap_register(&m_joy_map, physical_stick, joy_name.c_str()); - } } for (int stick = 0; stick < MAX_DEVMAP_ENTRIES; stick++) @@ -720,13 +723,11 @@ public: continue; physical_stick = m_joy_map.map[stick].physical; - SDL_Joystick *joy = SDL_JoystickOpen(physical_stick); - devinfo->sdl_state.device = joy; devinfo->sdl_state.joystick_id = SDL_JoystickInstanceID(joy); - osd_printf_verbose("Joystick: %s\n", devinfo->name()); + osd_printf_verbose("Joystick: %s\n", SDL_JoystickNameForIndex(physical_stick)); osd_printf_verbose("Joystick: ... %d axes, %d buttons %d hats %d balls\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy), SDL_JoystickNumBalls(joy)); osd_printf_verbose("Joystick: ... Physical id %d mapped to logical id %d\n", physical_stick, stick + 1); diff --git a/src/osd/osdcore.cpp b/src/osd/osdcore.cpp index fef7d0d0f7a..3e783159a9b 100644 --- a/src/osd/osdcore.cpp +++ b/src/osd/osdcore.cpp @@ -5,6 +5,9 @@ #include <thread> #include <chrono> +#if defined(SDLMAME_ANDROID) +#include <SDL2/SDL.h> +#endif static const int MAXSTACK = 10; static osd_output *m_stack[MAXSTACK]; static int m_ptr = -1; @@ -58,7 +61,11 @@ void CLIB_DECL osd_printf_error(const char *format, ...) /* do the output */ va_start(argptr, format); +#if defined(SDLMAME_ANDROID) + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, format, argptr); +#else if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_ERROR, format, argptr); +#endif va_end(argptr); } @@ -74,7 +81,11 @@ void CLIB_DECL osd_printf_warning(const char *format, ...) /* do the output */ va_start(argptr, format); +#if defined(SDLMAME_ANDROID) + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, format, argptr); +#else if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_WARNING, format, argptr); +#endif va_end(argptr); } @@ -90,7 +101,11 @@ void CLIB_DECL osd_printf_info(const char *format, ...) /* do the output */ va_start(argptr, format); +#if defined(SDLMAME_ANDROID) + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, format, argptr); +#else if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_INFO, format, argptr); +#endif va_end(argptr); } @@ -106,7 +121,11 @@ void CLIB_DECL osd_printf_verbose(const char *format, ...) /* do the output */ va_start(argptr, format); +#if defined(SDLMAME_ANDROID) + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE, format, argptr); +#else if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_VERBOSE, format, argptr); +#endif va_end(argptr); } @@ -122,7 +141,11 @@ void CLIB_DECL osd_printf_debug(const char *format, ...) /* do the output */ va_start(argptr, format); +#if defined(SDLMAME_ANDROID) + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, format, argptr); +#else if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_DEBUG, format, argptr); +#endif va_end(argptr); } diff --git a/src/osd/sdl/sdlmain.cpp b/src/osd/sdl/sdlmain.cpp index c2e1479ddd2..8f978560642 100644 --- a/src/osd/sdl/sdlmain.cpp +++ b/src/osd/sdl/sdlmain.cpp @@ -198,6 +198,11 @@ int main(int argc, char *argv[]) setvbuf(stdout, (char *) NULL, _IONBF, 0); setvbuf(stderr, (char *) NULL, _IONBF, 0); +#if defined(SDLMAME_ANDROID) + /* Enable standard application logging */ + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE); +#endif + // FIXME: this should be done differently #ifdef SDLMAME_UNIX @@ -269,7 +274,7 @@ void sdl_osd_interface::osd_exit() if (!SDLMAME_INIT_IN_WORKER_THREAD) { - SDL_QuitSubSystem(SDL_INIT_TIMER| SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER ); + SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ); } } @@ -486,12 +491,7 @@ void sdl_osd_interface::init(running_machine &machine) if (!SDLMAME_INIT_IN_WORKER_THREAD) { -#ifdef SDLMAME_EMSCRIPTEN - // timer brings in threads which are not supported in Emscripten - if (SDL_InitSubSystem(SDL_INIT_VIDEO| SDL_INIT_GAMECONTROLLER|SDL_INIT_NOPARACHUTE)) { -#else - if (SDL_InitSubSystem(SDL_INIT_TIMER| SDL_INIT_VIDEO| SDL_INIT_GAMECONTROLLER|SDL_INIT_NOPARACHUTE)) { -#endif + if (SDL_InitSubSystem(SDL_INIT_VIDEO)) { osd_printf_error("Could not initialize SDL %s\n", SDL_GetError()); exit(-1); } diff --git a/src/osd/sdl/window.cpp b/src/osd/sdl/window.cpp index 8abf89ce5fc..18274b6ecb2 100644 --- a/src/osd/sdl/window.cpp +++ b/src/osd/sdl/window.cpp @@ -176,7 +176,7 @@ static OSDWORK_CALLBACK(sdlwindow_thread_id) if (SDLMAME_INIT_IN_WORKER_THREAD) { - if (SDL_InitSubSystem(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_GAMECONTROLLER|SDL_INIT_NOPARACHUTE)) + if (SDL_InitSubSystem(SDL_INIT_VIDEO)) { osd_printf_error("Could not initialize SDL: %s.\n", SDL_GetError()); exit(-1); |