mirror of
https://github.com/holub/mame
synced 2025-10-05 16:50:57 +03:00
Fixed joystick on Android preventing application to crash, cleanup init for SDL in total (nw)
This commit is contained in:
parent
0a3f7c37c7
commit
731abe8ba0
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user