|
Using Joystick(s) DAllegro 5.2 code (dlang) |
Joel Christensen
Member #5,103
October 2004
|
I'm trying to get a game pad working (360 game pad compatible): void process() { I get this error: P.S. I got father with both: Pygame, and DSFML (simple fast media library), though this is my first crack at it using Allegro.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
It needs to be jstate[STICK][AXIS]. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Audric
Member #907
January 2001
|
I'm not a D programmer, but this part is suspicious: ALLEGRO_JOYSTICK_STATE* jstate; al_get_joystick_state(_joy, jstate); In the C API, you need to allocate a struct, and pass its address. If you pass an uninitialized pointer, you will (try) write in a random part of memory, with horrific results. /* C */ ALLEGRO_JOYSTICK_STATE jstate; al_get_joystick_state(_joy, &jstate);
|
Chris Katko
Member #1,881
January 2002
|
Yep. Pointers are the same in D. If you have a pointer, you have to create something to go in it. It should probably be: ALLEGRO_JOYSTICK_STATE jstate; //no pointer al_get_joystick_state(_joy, &jstate); //give address of non-pointer with & And that still allocates a new joystick state struct every time, you could have just one and re-use it over and over. Like this //outside your loop, like in your initialize/setup routine that is called once ALLEGRO_JOYSTICK_STATE jstate; //later in your game loop function al_get_joystick_state(_joy, &jstate); //re-use it without creating a new one every time But that's a tiny speed issue compared to "not working at all" / leaking memory. -----sig: |
Joel Christensen
Member #5,103
October 2004
|
ALLEGRO_JOYSTICK* _joy; Ok, got it working, yay! Thanks everyone.:D (I actually looked up the source code, from DAllegro5, to help work it out).
|
Audric
Member #907
January 2001
|
I suspect you will still have an issue with how you use _id twice for different things. (The '360 has two analogic sticks) You should really use the functions al_get_joystick_num_axes(), al_get_joystick_num_sticks(), al_get_joystick_num_buttons() etc., to test what allegro detects. It's a very bad idea to read ".stick[n]" where n is greater than the number of detected sticks on this joystick. |
|