1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-28 19:10:35 +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"));
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() {

View File

@ -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();

View File

@ -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<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();
if(numsticks > 8) numsticks = 8;
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() {
DEBB(DF_INIT, ("close joysticks"));
for(int i=0; i<numsticks; i++) {
@ -1000,6 +1030,7 @@ EX void mainloopiter() {
fix_mouseh();
#if CAP_SDLJOY
if(joydir.d != -1) checkjoy();
if(joystick_done && joythread) { joythread->join(); 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