1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-09 15:39:55 +00:00

faster joystick intiialization

This commit is contained in:
Zeno Rogue 2024-05-28 11:59:03 +02:00
parent 6bf198946c
commit 5901d9598d
3 changed files with 56 additions and 10 deletions

View File

@ -1516,12 +1516,14 @@ EX void initialize_all() {
DEBBI(DF_INIT | DF_GRAPH, ("initgraph")); DEBBI(DF_INIT | DF_GRAPH, ("initgraph"));
DEBB(DF_INIT, ("initconfig"));
initConfig(); initConfig();
#if CAP_SDLJOY #if CAP_SDLJOY
joyx = joyy = 0; joydir.d = -1; joyx = joyy = 0; joydir.d = -1;
#endif #endif
DEBB(DF_INIT, ("restartGraph"));
restartGraph(); restartGraph();
if(noGUI) { if(noGUI) {
@ -1531,11 +1533,14 @@ EX void initialize_all() {
return; return;
} }
DEBB(DF_INIT, ("preparesort"));
preparesort(); preparesort();
#if CAP_CONFIG #if CAP_CONFIG
DEBB(DF_INIT, ("loadConfig"));
loadConfig(); loadConfig();
#endif #endif
#if CAP_ARCM #if CAP_ARCM
DEBB(DF_INIT, ("parse symbol"));
arcm::current.parse(); arcm::current.parse();
#endif #endif
if(mhybrid) geometry = hybrid::underlying; if(mhybrid) geometry = hybrid::underlying;
@ -1544,19 +1549,26 @@ EX void initialize_all() {
arg::read(2); arg::read(2);
#endif #endif
DEBB(DF_INIT | DF_GRAPH, ("init graph"));
init_graph(); init_graph();
DEBB(DF_INIT | DF_POLY, ("check CGI"));
check_cgi(); check_cgi();
DEBB(DF_INIT | DF_POLY, ("require basic"));
cgi.require_basics(); cgi.require_basics();
DEBB(DF_INIT | DF_GRAPH, ("init font"));
init_font(); init_font();
#if CAP_SDLJOY #if CAP_SDLJOY
initJoysticks(); initJoysticks_async();
#endif #endif
#if CAP_SDLAUDIO #if CAP_SDLAUDIO
DEBB(DF_INIT, ("init audio"));
initAudio(); initAudio();
#endif #endif
DEBB(DF_INIT, ("initialize_all done"));
} }
EX void quit_all() { EX void quit_all() {

View File

@ -1278,6 +1278,8 @@ EX void initConfig() {
-> help("Background particle effects, e.g., in the Blizzard."); -> help("Background particle effects, e.g., in the Blizzard.");
// control // 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.joyvalue, "vid.joyvalue", 4800);
param_i(vid.joyvalue2, "vid.joyvalue2", 5600); param_i(vid.joyvalue2, "vid.joyvalue2", 5600);
param_i(vid.joysmooth, "vid.joysmooth", 200); 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("second joystick: panning speed"), fts(vid.joypanspeed * 1000), 'd');
dialog::addSelItem(XLAT("smoothen"), its(vid.joysmooth) + " ms", 'e'); dialog::addSelItem(XLAT("smoothen"), its(vid.joysmooth) + " ms", 'e');
add_edit(joy_init);
dialog::addBreak(50); dialog::addBreak(50);
dialog::addBack(); dialog::addBack();
dialog::display(); dialog::display();

View File

@ -212,16 +212,30 @@ EX void mousemovement() {
EX SDL_Joystick* sticks[8]; EX SDL_Joystick* sticks[8];
EX int numsticks; EX int numsticks;
EX void initJoysticks() { EX bool joysticks_initialized;
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) #if HDR
{ enum eJoystickInit { jiNoJoystick, jiFast, jiWait };
printf("Failed to initialize joysticks.\n"); #endif
numsticks = 0; EX eJoystickInit joy_init = jiFast;
return;
#if CAP_THREAD
EX std::thread *joythread;
std::atomic<bool> 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(); numsticks = SDL_NumJoysticks();
if(numsticks > 8) numsticks = 8; if(numsticks > 8) numsticks = 8;
for(int i=0; i<numsticks; i++) { for(int i=0; i<numsticks; i++) {
@ -235,6 +249,22 @@ EX void initJoysticks() {
} }
} }
EX void initJoysticks() {
DEBBI(DF_INIT, ("init joystick"));
DEBB(DF_INIT, ("init joystick subsystem"));
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
{
printf("Failed to initialize joysticks.\n");
numsticks = 0;
return;
}
countJoysticks();
joysticks_initialized = true;
}
EX void closeJoysticks() { EX void closeJoysticks() {
DEBB(DF_INIT, ("close joysticks")); DEBB(DF_INIT, ("close joysticks"));
for(int i=0; i<numsticks; i++) { for(int i=0; i<numsticks; i++) {
@ -1000,6 +1030,7 @@ EX void mainloopiter() {
fix_mouseh(); fix_mouseh();
#if CAP_SDLJOY #if CAP_SDLJOY
if(joydir.d != -1) checkjoy(); if(joydir.d != -1) checkjoy();
if(joystick_done && joythread) { joythread->join(); delete joythread; joystick_done = false; }
#endif #endif
} }
@ -1015,8 +1046,7 @@ EX void handle_event(SDL_Event& ev) {
/* if(ev.type == SDL_JOYDEVICEADDED || ev.type == SDL_JOYDEVICEREMOVED) { /* if(ev.type == SDL_JOYDEVICEADDED || ev.type == SDL_JOYDEVICEREMOVED) {
joyx = joyy = 0; joyx = joyy = 0;
panjoyx = panjoyy = 0; panjoyx = panjoyy = 0;
closeJoysticks(); countJoysticks();
initJoysticks();
} */ } */
#if CAP_SDL2 #if CAP_SDL2