Yet Another Joystick Thread


Eolair

I am become death, the destroyer of worlds
Joined
Apr 17, 2005
Messages
1,032
Location
Sweden
Website
Visit site
IMO, the biggest problem with the joystick is the detection of diagonals. More specific, left or right is often detected as diagonal up (left or right). I've taken a look at DaveC's suggested configs which are really great ideas. I would be interested to know what emus/games that uses the Case 2 configuration?


Does Frodo already use case 2? I have been testing some platform games on Frodo, where up is jump, and it's still very hard to move left or right without registering a diagonal (having the character make involuntary jumps). For some reason the same problem doesn't occur when you try to move up or down. (There's no accidental registrations of diagonals). So if Frodo is using case 2 it would seem to indicate that something is still not right. Could there be something wrong with the diagonal detection on a lower level of coding? On firmware level? It's almost like the stick is configurated like this:



One suggestion I have is to try to implement the following config with horizontal bias :


I also had the idea that it would be great if someone could make a joystick test program where you could pick different configs and test them. Like the t-mode in the settings menu only with DaveC's cases as different test choices.
 

jbb

Still Fresh
Joined
May 28, 2003
Messages
63
How do you actually detect those extra 8 directions?
Right now I'm having those dead spots between the diags and verts/horizs... Argh!

...in SDL it seems we have only 8 values to play with (according to the wiki)...
Not sure how you can do logical ANDs as they are decimal values, not binary? (short example of code would be brilliant!)

Cheers,
JBB
 

greven

Member
Joined
Feb 2, 2004
Messages
255
Age
34
Location
France (Grenoble)
Website
Visit site
I agree with Paradox, case 2 in the first image looks the best, because it seems to prevent you from going right+up instead of right alone, but you say there are still problems....
 

miq01

Member
Joined
Nov 27, 2005
Messages
259
Location
Barcelona, Catalonia
Website
Visit site
jbb posted on Dec 30 2005 at 05:14 PM said:
How do you actually detect those extra 8 directions?
Right now I'm having those dead spots between the diags and verts/horizs... Argh!

...in SDL it seems we have only 8 values to play with (according to the wiki)...
You're right: you can play with 8 values. But you can combine them. This is the way I do it:

I have a boolean flag for each possible key that tells if that key is being pressed or not. Having a boolean for each key is not optimal and it could be done using just one Uint8 or Uint16. But that's the way I have it now.

This function detects SDL_JOYBUTTONDOWN and SDL_JOYBUTTONUP events:
Code:
void HandleInput()
{
    SDL_Event event;

    while(SDL_PollEvent(&event))
    {
        switch(event.type)
        {
            case SDL_JOYBUTTONDOWN: KeyDown(event.jbutton.button); break;
            case SDL_JOYBUTTONUP: KeyUp(event.jbutton.button); break;
        }
    }
}
This one detects keyups:
Code:
void KeyUp(const Uint8& key)
{
    switch(key)
    {
        <...>
        case GP2X_BUTTON_UP: up=false; break;
        case GP2X_BUTTON_DOWN: down=false; break;
        case GP2X_BUTTON_LEFT: left=false; break;
        case GP2X_BUTTON_RIGHT: right=false; break;
        case GP2X_BUTTON_UPLEFT: upleft=false; break;
        case GP2X_BUTTON_UPRIGHT: upright=false; break;
        case GP2X_BUTTON_DOWNLEFT: downleft=false; break;
        case GP2X_BUTTON_DOWNRIGHT: downright=false; break;
        <...>
        default: break;
    }
}
KeyDown function is analogous to KeyUp, but settings boolean values to true instead of false.

Later, in the main loop:
Code:
    if (left || (left&&upleft) || (left&&downleft)) ship->Left();
    if (right || (right&&upright ) || (right&&downright )) ship->Right();
    if (up || (up&&upleft ) || (up&&upright)) ship->Up();
    if (down || (down&&downleft) || (down&&downright)) ship->Down();
    if (upleft && !left && !up) ship->UpLeft();
    if (downleft && !left && !down) ship->DownLeft();
    if (upright && !right && !up) ship->UpRight();
    if (downright && !right && !down) ship->DownRight();
So this one is using DaveC's case 2 (btw, great work, DaveC) and works great for a shooter I'm coding.

Hope it helps.
 
Last edited by a moderator:

jbb

Still Fresh
Joined
May 28, 2003
Messages
63
Brilliant! Will try right away...
Maybe you should add your own bit to the Wiki?

Sorry for the dev noise... this question should probably be part of the dev corner. Oh well,
JBB
 

Dryer Lint

Member
Joined
May 15, 2005
Messages
143
I think it would be best if emulators would allow the user to pick his favorite mode (possibly even for each game, just as you can have different settings for each game in emulators like DrMD).

Because clearly different games have different diagonal-needs. ;-)
 

reallynotnick

The smartest newb
Joined
Aug 20, 2005
Messages
871
Website
Visit site
Case 2 is pretty much the best for about 90% of all games. I really recomned devs look at this and really thing about it. The last time I tried to play super nintendo on my gp2x (like a month ago) it was totally unplayable because of the controls.
 

DaveC

Internal Development
Joined
Mar 4, 2004
Messages
9,208
I had the same problem with Frodo. I asked Snaff about it and he says that he is using case 2. It doesn't seem right though as you say, maybe he thinks he is doing case 2 but there is a bug somewhere.

DrMD gives the same trouble. If I try to play Frogger pressing left or right gives an "up" many times instead. In that game that kind of thing makes it unplayable. For 4-way games a case 5 option should be given.

I think case 2 is as good as we will get for general emulator use.

I agree with DL though in that an option menu for each case would be best. For example Q*bert is pretty unplayable in MAME because of the controls.

Frogger and pac-man would use case 5, Q*bert would use case 6, analog/mouse simulation would use case 1 (centipede, Missile command) , most others case 2.

A test program would be cool. This way you could see how each case works in the real world. I would think that would be pretty easy for a coder to hack up.
 

miq01

Member
Joined
Nov 27, 2005
Messages
259
Location
Barcelona, Catalonia
Website
Visit site
DaveC posted on Dec 31 2005 at 03:02 AM said:
A test program would be cool. This way you could see how each case works in the real world. I would think that would be pretty easy for a coder to hack up.
Here it is. :)

As soon as I translate code variables and functions into english I'll release the source so that you can add other settings.

Press START to exit and move the stick to see the results.
 
Last edited by a moderator:

Eolair

I am become death, the destroyer of worlds
Joined
Apr 17, 2005
Messages
1,032
Location
Sweden
Website
Visit site
Wow! I didn't think someone would address this so fast. Thanks a lot! I'll try the program ASAP. It would be awesome if coders could turn this program into a joystick setup in their emus/games and let the users choose the config they want.

DaveC posted on Dec 31 2005 at 02:02 AM said:
I had the same problem with Frodo.  I asked Snaff about it and he says that he is using case 2.  It doesn't seem right though as you say, maybe he thinks he is doing case 2 but there is a bug somewhere.

DrMD gives the same trouble.  If I try to play Frogger pressing left or right gives an "up" many times instead.  In that game that kind of thing makes it unplayable.  For 4-way games a case 5 option should be given.
Yeah, it would appear something is not right with the implementation. Could the problem be a detection issue? How the logical (AND) connections are detected? I have a suspicion that the hardware connectors have to be hit at exactly the same time (simultaneously) for it to work. There's no room for a slight time difference.

But in the t-mode (settings menu) I have noticed that a simultaneous hit isn't always what happens. More often you seem to hit first one connector and then another, in rapid sucession. In that case maybe the action is incorrectly interpreted as two seperate ones, first a horizontal move and then a diagonal one?

I'm not sure how to fix this though. How to make the code know when you intend to make one move rather than two seperate ones?
 
Last edited by a moderator:

miq01

Member
Joined
Nov 27, 2005
Messages
259
Location
Barcelona, Catalonia
Website
Visit site
Eolair posted on Dec 31 2005 at 04:42 PM said:
Wow! I didn't think someone would address this so fast. Thanks a lot! I'll try the program ASAP. It would be awesome if coders could turn this program into a joystick setup in their emus/games and let the users choose the config they want.
I had to do that anyway, because I wanted to try those different configurations in my game. Also, it was fast to code. As I said, I'll release the source once I translate it and clean it up.
 
Last edited by a moderator:

Leshrac

Still Fresh
Joined
Oct 8, 2005
Messages
84
miq01 posted on Dec 31 2005 at 06:03 PM said:
Eolair posted on Dec 31 2005 at 04:42 PM said:
Wow! I didn't think someone would address this so fast. Thanks a lot! I'll try the program ASAP. It would be awesome if coders could turn this program into a joystick setup in their emus/games and let the users choose the config they want.
I had to do that anyway, because I wanted to try those different configurations in my game. Also, it was fast to code. As I said, I'll release the source once I translate it and clean it up.
You said you didn't have time, so I uploaded it to the file archive and added it to the wiki: Wiki Page
 
Last edited by a moderator:
Top