www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - raylib-d Gamepad Detection Fails

reply jwatson-CO-edu <real.name colorado.edu> writes:
Hello,

I have this small [gamepad input test 
program](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_js
nput/source/app.d).  In the program, I poll the first 3 gamepad IDs, but all
detection attempts return `false`. I know that my gamepad is an Xinput model. 
I have tried starting the program before and after the gamepad is plugged in,
but there is no change.

Sample:
```d
bool GP0_found = IsGamepadAvailable(0); // false
bool GP1_found = IsGamepadAvailable(1); // false
bool GP2_found = IsGamepadAvailable(2); // false
```

Has anyone else experienced this and know the fix?
Nov 30 2022
parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Wednesday, 30 November 2022 at 22:46:52 UTC, jwatson-CO-edu 
wrote:
 Hello,

 I have this small [gamepad input test 
 program](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_js
nput/source/app.d).  In the program, I poll the first 3 gamepad IDs, but all
detection attempts return `false`. I know that my gamepad is an Xinput model. 
I have tried starting the program before and after the gamepad is plugged in,
but there is no change.

 Sample:
 ```d
 bool GP0_found = IsGamepadAvailable(0); // false
 bool GP1_found = IsGamepadAvailable(1); // false
 bool GP2_found = IsGamepadAvailable(2); // false
 ```

 Has anyone else experienced this and know the fix?
Which OS and wich controllers are you using? You might want to open an issue on the raylib-d repo: https://github.com/schveiguy/raylib-d/issues
Nov 30 2022
parent reply jwatson-CO-edu <real.name colorado.edu> writes:
On Wednesday, 30 November 2022 at 23:18:33 UTC, ryuukk_ wrote:
 On Wednesday, 30 November 2022 at 22:46:52 UTC, jwatson-CO-edu 
 wrote:
 Hello,

 I have this small [gamepad input test 
 program](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d).
Which OS and wich controllers are you using? You might want to open an issue on the raylib-d repo: https://github.com/schveiguy/raylib-d/issues
I tested on Ubuntu 22.04 and Linux Mint 20 with an older GameSir brand wired XBox controller. Built with Raylib 2.4.0 and raylib-d 2.4.1. I know that the author monitors the forum. So, I will open an issue if he does not point out something obvious that I missed.
Nov 30 2022
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 11/30/22 7:28 PM, jwatson-CO-edu wrote:
 On Wednesday, 30 November 2022 at 23:18:33 UTC, ryuukk_ wrote:
 On Wednesday, 30 November 2022 at 22:46:52 UTC, jwatson-CO-edu wrote:
 Hello,

 I have this small [gamepad input test 
 program](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d).
Which OS and wich controllers are you using? You might want to open an issue on the raylib-d repo: https://github.com/schveiguy/raylib-d/issues
I tested on Ubuntu 22.04 and Linux Mint 20 with an older GameSir brand wired XBox controller.  Built with Raylib 2.4.0 and raylib-d 2.4.1. I know that the author monitors the forum.  So, I will open an issue if he does not point out something obvious that I missed.
Do you have that version correct? I'm assuming you mean raylib 4.2.0 and raylib-d 4.2.1? Highly recommend to update to raylib-d 4.2.4, and use the the Linux raylib-d:install as that now works (and will properly grab the correct raylib library from the repository for you). For your specific problem, I would say that if it's not working, it's not a problem specifically with raylib-d, but with raylib. Such functions are just prototypes in raylib-d, the C library does the implementation. This would probably be best actually to discuss either on the raylib discord (there's a raylib-d channel) or open an issue in my repository. Raylib does a lot of logging things, you can probably see if your gamepad is detected. -Steve
Nov 30 2022
parent reply jwatson-CO-edu <real.name colorado.edu> writes:
On Thursday, 1 December 2022 at 01:12:17 UTC, Steven 
Schveighoffer wrote:
 On 11/30/22 7:28 PM, jwatson-CO-edu wrote:
 On Wednesday, 30 November 2022 at 23:18:33 UTC, ryuukk_ wrote:
 On Wednesday, 30 November 2022 at 22:46:52 UTC, 
 jwatson-CO-edu wrote:
 Hello,

 I have this small [gamepad input test 
 program](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d).
Which OS and wich controllers are you using? You might want to open an issue on the raylib-d repo: https://github.com/schveiguy/raylib-d/issues
I tested on Ubuntu 22.04 and Linux Mint 20 with an older GameSir brand wired XBox controller.  Built with Raylib 2.4.0 and raylib-d 2.4.1. I know that the author monitors the forum.  So, I will open an issue if he does not point out something obvious that I missed.
Do you have that version correct? I'm assuming you mean raylib 4.2.0 and raylib-d 4.2.1? Highly recommend to update to raylib-d 4.2.4, and use the the Linux raylib-d:install as that now works (and will properly grab the correct raylib library from the repository for you).
 -Steve
Yes, following your instructions I have raylib 4.2.0 and raylib-d 4.2.4 in the project directory. I am now using the latest version of raylib-d, but this did not resolve the gamepad issue. I can ask around on the raylib channels.
Nov 30 2022
next sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 11/30/22 8:49 PM, jwatson-CO-edu wrote:

 
 Yes, following your instructions I have raylib 4.2.0 and raylib-d 4.2.4 
 in the project directory.  I am now using the latest version of 
 raylib-d, but this did not resolve the gamepad issue. I can ask around 
 on the raylib channels.
Oh, I think I know the issue -- you need to check inside the loop. The way raylib works is that it polls events from the glfw library. So unless you are actually calling `BeginDrawing` and `EndDrawing`, those flags won't change. -Steve
Nov 30 2022
parent reply bauss <jacobbauss gmail.com> writes:
On Thursday, 1 December 2022 at 02:06:43 UTC, Steven 
Schveighoffer wrote:
 On 11/30/22 8:49 PM, jwatson-CO-edu wrote:

 
 Yes, following your instructions I have raylib 4.2.0 and 
 raylib-d 4.2.4 in the project directory.  I am now using the 
 latest version of raylib-d, but this did not resolve the 
 gamepad issue. I can ask around on the raylib channels.
Oh, I think I know the issue -- you need to check inside the loop. The way raylib works is that it polls events from the glfw library. So unless you are actually calling `BeginDrawing` and `EndDrawing`, those flags won't change. -Steve
But probably not on every frame, have a delay between checks.
Dec 01 2022
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 12/1/22 3:24 AM, bauss wrote:

 
 But probably not on every frame, have a delay between checks.
It's not anything controllable by the user. The library does the check every frame regardless of whether you use it or not. When you call the raylib function, you are not actually querying the device, you are checking a boolean in a struct. https://github.com/raysan5/raylib/blob/387c06000618ef0aa3b15c5e46d1c525ba194c50/src/rcore.c#L3567 -Steve
Dec 01 2022
parent bauss <jacobbauss gmail.com> writes:
On Thursday, 1 December 2022 at 15:35:37 UTC, Steven 
Schveighoffer wrote:
 On 12/1/22 3:24 AM, bauss wrote:

 
 But probably not on every frame, have a delay between checks.
It's not anything controllable by the user. The library does the check every frame regardless of whether you use it or not. When you call the raylib function, you are not actually querying the device, you are checking a boolean in a struct. https://github.com/raysan5/raylib/blob/387c06000618ef0aa3b15c5e46d1c525ba194c50/src/rcore.c#L3567 -Steve
Oh yeah then it's fine :)
Dec 01 2022
prev sibling parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Thursday, 1 December 2022 at 01:49:09 UTC, jwatson-CO-edu 
wrote:
 On Thursday, 1 December 2022 at 01:12:17 UTC, Steven 
 Schveighoffer wrote:
 On 11/30/22 7:28 PM, jwatson-CO-edu wrote:
 On Wednesday, 30 November 2022 at 23:18:33 UTC, ryuukk_ wrote:
 On Wednesday, 30 November 2022 at 22:46:52 UTC, 
 jwatson-CO-edu wrote:
 Hello,

 I have this small [gamepad input test 
 program](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d).
Which OS and wich controllers are you using? You might want to open an issue on the raylib-d repo: https://github.com/schveiguy/raylib-d/issues
I tested on Ubuntu 22.04 and Linux Mint 20 with an older GameSir brand wired XBox controller.  Built with Raylib 2.4.0 and raylib-d 2.4.1. I know that the author monitors the forum.  So, I will open an issue if he does not point out something obvious that I missed.
Do you have that version correct? I'm assuming you mean raylib 4.2.0 and raylib-d 4.2.1? Highly recommend to update to raylib-d 4.2.4, and use the the Linux raylib-d:install as that now works (and will properly grab the correct raylib library from the repository for you).
 -Steve
Yes, following your instructions I have raylib 4.2.0 and raylib-d 4.2.4 in the project directory. I am now using the latest version of raylib-d, but this did not resolve the gamepad issue. I can ask around on the raylib channels.
Can you try with this page: https://www.raylib.com/examples/core/loader.html?name=core_input_gamepad Does it detect your gamepad?
Dec 01 2022
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 12/1/22 11:10 AM, ryuukk_ wrote:
 Can you try with this page: 
 https://www.raylib.com/examples/core/loader.html?name=core_input_gamepad
 
 Does it detect your gamepad?
It should work because the `IsGamepadAvailable` function call is inside the loop. That's most certainly the problem with the OP code. -Steve
Dec 01 2022
parent reply jwatson-CO-edu <real.name colorado.edu> writes:
On Thursday, 1 December 2022 at 21:34:41 UTC, Steven 
Schveighoffer wrote:
 On 12/1/22 11:10 AM, ryuukk_ wrote:
 Can you try with this page: 
 https://www.raylib.com/examples/core/loader.html?name=core_input_gamepad
 
 Does it detect your gamepad?
It should work because the `IsGamepadAvailable` function call is inside the loop. That's most certainly the problem with the OP code. -Steve
That was the trick, [inside the loop it detects the gamepad](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInpu /source/app.d#L35). No other changes needed.
Dec 01 2022
parent reply jwatson-CO-edu <real.name colorado.edu> writes:
On Thursday, 1 December 2022 at 22:16:30 UTC, jwatson-CO-edu 
wrote:
 That was the trick, [inside the loop it detects the 
 gamepad](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInpu
/source/app.d#L35).  No other changes needed.
I have a new problem: Raylib-d [can see all 6 gamepad axes](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInpu /source/app.d#L44). However, they [all return 0](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInp t/source/app.d#L48) for all stick motion. Do I need to initialize the gamepad somehow?
Dec 01 2022
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 12/1/22 5:50 PM, jwatson-CO-edu wrote:
 On Thursday, 1 December 2022 at 22:16:30 UTC, jwatson-CO-edu wrote:
 That was the trick, [inside the loop it detects the 
 gamepad](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/
ource/app.d#L35).  No other changes needed.
I have a new problem: Raylib-d [can see all 6 gamepad axes](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/ ource/app.d#L44).  However, they [all return 0](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInp t/source/app.d#L48) for all stick motion. Do I need to initialize the gamepad somehow?
Looking at the example posted by ryuukk, you shouldn't have to. Does it detect the buttons? Does your gamepad actually have analog sticks? Do all 6 axes show no movement? I don't see anything inherently wrong with your code. I also don't have a gamepad to try with, plus even if I did, it's possible my setup would work while yours doesn't. It's important to remember that raylib-d doesn't do any special things with the raylib functions -- they are just straight calls into the library. -Steve
Dec 01 2022
parent jwatson-CO-edu <real.name colorado.edu> writes:
On Friday, 2 December 2022 at 01:03:47 UTC, Steven Schveighoffer 
wrote:
 It's important to remember that raylib-d doesn't do any special 
 things with the raylib functions -- they are just straight 
 calls into the library.

 -Steve
Indeed, I plugged a different gamepad into the same system running the same code, and it worked. My gamepad must not have been on the list of [gamepad input mappings](https://github.com/gabomdq/SDL_GameControllerDB/blob/master/g mecontrollerdb.txt) used by SDL2 --> GLFW --> Raylib --> raylib-d.
Dec 04 2022