diff --git a/basegraph.cpp b/basegraph.cpp index 6224201e..e1cbb30c 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -1516,12 +1516,14 @@ EX void initialize_all() { DEBBI(DF_INIT | DF_GRAPH, ("initgraph")); + DEBB(DF_INIT, ("initconfig")); initConfig(); #if CAP_SDLJOY joyx = joyy = 0; joydir.d = -1; #endif + DEBB(DF_INIT, ("restartGraph")); restartGraph(); if(noGUI) { @@ -1531,11 +1533,14 @@ EX void initialize_all() { return; } + DEBB(DF_INIT, ("preparesort")); preparesort(); #if CAP_CONFIG + DEBB(DF_INIT, ("loadConfig")); loadConfig(); #endif #if CAP_ARCM + DEBB(DF_INIT, ("parse symbol")); arcm::current.parse(); #endif if(mhybrid) geometry = hybrid::underlying; @@ -1544,19 +1549,26 @@ EX void initialize_all() { arg::read(2); #endif + DEBB(DF_INIT | DF_GRAPH, ("init graph")); init_graph(); + DEBB(DF_INIT | DF_POLY, ("check CGI")); check_cgi(); + DEBB(DF_INIT | DF_POLY, ("require basic")); cgi.require_basics(); + DEBB(DF_INIT | DF_GRAPH, ("init font")); init_font(); #if CAP_SDLJOY - initJoysticks(); + initJoysticks_async(); #endif #if CAP_SDLAUDIO + DEBB(DF_INIT, ("init audio")); initAudio(); #endif + + DEBB(DF_INIT, ("initialize_all done")); } EX void quit_all() { diff --git a/config.cpp b/config.cpp index bb20f12e..355a1690 100644 --- a/config.cpp +++ b/config.cpp @@ -1278,6 +1278,8 @@ EX void initConfig() { -> help("Background particle effects, e.g., in the Blizzard."); // control + param_enum(joy_init, "joyinit", jiFast) + ->editable({{"off", "do not use joysticks"}, {"fast", "do not wait until the joysticks are initialized"}, {"wait", "wait until the joysticks are initialized"}}, "joystick initialization", 'j'); param_i(vid.joyvalue, "vid.joyvalue", 4800); param_i(vid.joyvalue2, "vid.joyvalue2", 5600); param_i(vid.joysmooth, "vid.joysmooth", 200); @@ -2427,6 +2429,8 @@ EX void showJoyConfig() { dialog::addSelItem(XLAT("second joystick: panning speed"), fts(vid.joypanspeed * 1000), 'd'); dialog::addSelItem(XLAT("smoothen"), its(vid.joysmooth) + " ms", 'e'); + add_edit(joy_init); + dialog::addBreak(50); dialog::addBack(); dialog::display(); diff --git a/control.cpp b/control.cpp index 865dee77..5d5f5a51 100644 --- a/control.cpp +++ b/control.cpp @@ -212,16 +212,30 @@ EX void mousemovement() { EX SDL_Joystick* sticks[8]; EX int numsticks; -EX void initJoysticks() { +EX bool joysticks_initialized; - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) - { - printf("Failed to initialize joysticks.\n"); - numsticks = 0; - return; +#if HDR +enum eJoystickInit { jiNoJoystick, jiFast, jiWait }; +#endif +EX eJoystickInit joy_init = jiFast; + +#if CAP_THREAD +EX std::thread *joythread; +std::atomic joystick_done(false); +#endif + +EX void initJoysticks_async() { + if(joy_init == jiNoJoystick) return; + #if CAP_THREAD + if(joy_init == jiWait) { initJoysticks(); return; } + joythread = new std::thread([] { initJoysticks(); joystick_done = true; }); + #else + initJoysticks(); + #endif } - DEBB(DF_INIT, ("init joysticks")); +EX void countJoysticks() { + DEBB(DF_INIT, ("opening joysticks")); numsticks = SDL_NumJoysticks(); if(numsticks > 8) numsticks = 8; for(int i=0; ijoin(); delete joythread; joystick_done = false; } #endif } @@ -1015,8 +1046,7 @@ EX void handle_event(SDL_Event& ev) { /* if(ev.type == SDL_JOYDEVICEADDED || ev.type == SDL_JOYDEVICEREMOVED) { joyx = joyy = 0; panjoyx = panjoyy = 0; - closeJoysticks(); - initJoysticks(); + countJoysticks(); } */ #if CAP_SDL2