Jubatian wrote: ↑Mon Sep 18, 2017 8:31 pm
Artcfox wrote: ↑Mon Sep 18, 2017 8:26 pmBoth my code, and your code breaks the d-pad function completely on an XBox 360 controller, which has both a digital d-pad and analog axes.
I knew this wouldn't work, but I didn't know there were actually any controller which had both digital and analog X & Y movement axes (why would one have, thought I). I will fix it proper.
Could you experiment some more with those environment variables? If you are using a Bash shell and you are just trying to set them, remember that it matters which shell process actually gets the variables (use "export" as appropriate). It should work, at least I could influence SDL by environment variables some time ago when I needed it for a game.
EDIT: I created the fix, now you should be able to use both.
Your fix doesn't work, because you need to add another dimension to your static arrays and use the player variable to keep them separate.
Edit: I tried using export, but the call to
Code: Select all
SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG);
still returns NULL. The only way I can get that function to return the hint is if I call
Code: Select all
SDL_SetHint(SDL_HINT_GAMECONTROLLERCONFIG, "03000000830500006020000010010000,2-axis 8-button gamepad,platform:Linux,x:b3,a:b1,b:b0,y:b2,back:b6,start:b7,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,");
before SDL_Init() is called, at which point, we should just use the proper
function, which can be called any time.
Here is a fix to your fix:
Code: Select all
diff --git a/ginput.c b/ginput.c
index 9281bf5..db0e4ed 100644
--- a/ginput.c
+++ b/ginput.c
@@ -46,10 +46,10 @@ static SDL_GameController* ginput_gamectr[2] = {NULL, NULL};
static auint ginput_gamectr_id[2] = {0U, 0U};
/* Directional moves collected from digital inputs */
-static boole ginput_gamectr_ddig[4] = {FALSE, FALSE, FALSE, FALSE};
+static boole ginput_gamectr_ddig[2][4] = {FALSE, FALSE, FALSE, FALSE};
/* Directional moves collected from analog inputs */
-static boole ginput_gamectr_dana[4] = {FALSE, FALSE, FALSE, FALSE};
+static boole ginput_gamectr_dana[2][4] = {FALSE, FALSE, FALSE, FALSE};
/* Controller name when no name string is available */
static const char ginput_ctr_noname[] = "<no name>";
@@ -143,6 +143,7 @@ void ginput_init(void)
#ifndef USE_SDL1
/* Open game controller or controllers */
+ SDL_GameControllerAddMapping("03000000830500006020000010010000,iBuffalo USB 2-axis 8-button Gamepad,platform:Linux,x:b3,a:b1,b:b0,y:b2,back:b6,start:b7,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,");
j = 0U;
for (i = 0U; i < SDL_NumJoysticks(); i++){
@@ -222,28 +223,28 @@ void ginput_sendevent(SDL_Event const* ev)
switch (ev->key.keysym.sym){
case SDLK_LEFT:
#ifndef USE_SDL1
- ginput_gamectr_ddig[0] = press;
+ ginput_gamectr_ddig[0][0] = press;
#else
cu_ctr_setsnes_single(player, CU_CTR_SNES_LEFT, press);
#endif
break;
case SDLK_RIGHT:
#ifndef USE_SDL1
- ginput_gamectr_ddig[1] = press;
+ ginput_gamectr_ddig[0][1] = press;
#else
cu_ctr_setsnes_single(player, CU_CTR_SNES_RIGHT, press);
#endif
break;
case SDLK_UP:
#ifndef USE_SDL1
- ginput_gamectr_ddig[2] = press;
+ ginput_gamectr_ddig[0][2] = press;
#else
cu_ctr_setsnes_single(player, CU_CTR_SNES_UP, press);
#endif
break;
case SDLK_DOWN:
#ifndef USE_SDL1
- ginput_gamectr_ddig[3] = press;
+ ginput_gamectr_ddig[0][3] = press;
#else
cu_ctr_setsnes_single(player, CU_CTR_SNES_DOWN, press);
#endif
@@ -304,16 +305,16 @@ void ginput_sendevent(SDL_Event const* ev)
switch (ev->cbutton.button){
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
- ginput_gamectr_ddig[0] = press;
+ ginput_gamectr_ddig[player][0] = press;
break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
- ginput_gamectr_ddig[1] = press;
+ ginput_gamectr_ddig[player][1] = press;
break;
case SDL_CONTROLLER_BUTTON_DPAD_UP:
- ginput_gamectr_ddig[2] = press;
+ ginput_gamectr_ddig[player][2] = press;
break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
- ginput_gamectr_ddig[3] = press;
+ ginput_gamectr_ddig[player][3] = press;
break;
case SDL_CONTROLLER_BUTTON_Y: /* X-Y swapped due to SDL2 layout corresponding to XBox360 */
cu_ctr_setsnes_single(player, CU_CTR_SNES_X, press);
@@ -359,24 +360,24 @@ void ginput_sendevent(SDL_Event const* ev)
if ((ev->jaxis.axis) == 0U){ /* X axis: Left and Right */
press = ((ev->jaxis.value) <= -16384);
- ginput_gamectr_dana[0] = press;
+ ginput_gamectr_dana[player][0] = press;
press = ((ev->jaxis.value) >= 16384);
- ginput_gamectr_dana[1] = press;
+ ginput_gamectr_dana[player][1] = press;
}
if ((ev->jaxis.axis) == 1U){ /* Y axis: Up and Down */
press = ((ev->jaxis.value) <= -16384);
- ginput_gamectr_dana[2] = press;
+ ginput_gamectr_dana[player][2] = press;
press = ((ev->jaxis.value) >= 16384);
- ginput_gamectr_dana[3] = press;
+ ginput_gamectr_dana[player][3] = press;
}
}
- cu_ctr_setsnes_single(player, CU_CTR_SNES_LEFT, ginput_gamectr_ddig[0] || ginput_gamectr_dana[0]);
- cu_ctr_setsnes_single(player, CU_CTR_SNES_RIGHT, ginput_gamectr_ddig[1] || ginput_gamectr_dana[1]);
- cu_ctr_setsnes_single(player, CU_CTR_SNES_UP, ginput_gamectr_ddig[2] || ginput_gamectr_dana[2]);
- cu_ctr_setsnes_single(player, CU_CTR_SNES_DOWN, ginput_gamectr_ddig[3] || ginput_gamectr_dana[3]);
+ cu_ctr_setsnes_single(player, CU_CTR_SNES_LEFT, ginput_gamectr_ddig[player][0] || ginput_gamectr_dana[player][0]);
+ cu_ctr_setsnes_single(player, CU_CTR_SNES_RIGHT, ginput_gamectr_ddig[player][1] || ginput_gamectr_dana[player][1]);
+ cu_ctr_setsnes_single(player, CU_CTR_SNES_UP, ginput_gamectr_ddig[player][2] || ginput_gamectr_dana[player][2]);
+ cu_ctr_setsnes_single(player, CU_CTR_SNES_DOWN, ginput_gamectr_ddig[player][3] || ginput_gamectr_dana[player][3]);
#endif