SFML community forums

Help => Window => Topic started by: anthnich on June 12, 2014, 08:03:15 pm

Title: A Concern About Joystick Axises
Post by: anthnich on June 12, 2014, 08:03:15 pm
Hi.

I have a tiny concern that I want to put forward, just to clear up if I am screwing something up or I found a quirk.

I have a Playstation 2 -> USB converter and your standard dual shock plugged into it.

In a game I am programming, I have an InputManager written which loads binds and the like and handles all input. The InputManager is initialized before anything happens in the engine. So, since there is no window created yet, I need to call sf::Joystick::update() to update the joystick first. Here is where I found a problem.

In my gamepad, it detect all axises (using hasAxis()) as available, although my pad uses only 4 of them. The axises that are "unavailable" have a constant position value of either -100 or 100. No big deal, I just check to see if those values are constant when setting up binds and disallow use of those axises. With that workaround, everything works fine. Now, here is where I have run into a quirk.

Axis::U is one axis that is unavailable to me. So, if I call sf::Joystick::update(), that axis should give back a value of either 100 or -100 on getAxisPosition(). Except, this axis returns the value of Axis::R UNTIL I create a window and update the joystick again.

Here is the test code that demonstrates. It may or may not work for you, depending on which axis does this for you.

int main() {

        // no window, so update joystick.
        sf::Joystick::update();

        // U is "(un)available" on my pad, so check value. value will be the same as Axis::R, which is a problem.
        std::cout << "Axis U Value:" << sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::U) << std::endl;

        // now, we'll open a window --
        sf::RenderWindow window;
        window.create(sf::VideoMode(640, 480), "A Window", sf::Style::Close);

        // -- and reupdate the joystick. If I don't reupdate, the value will be the same as above.
        sf::Joystick::update();

        // value is now -100, since it's technically not available to me.
        std::cout << "Axis U Value:" << sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::U) << std::endl;

        bool done = false;

        while (!done) {

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
                        done = true;

        }

}

It is my understanding that once I call the first sf::Joystick::update(), the joystick should be ready to go, but it isn't.

EDIT: This is the build I am using: https://github.com/SFML/SFML/tree/265c411c39f498f95a03517818167b47b754c440 (https://github.com/SFML/SFML/tree/265c411c39f498f95a03517818167b47b754c440)
Title: Re: A Concern About Joystick Axises
Post by: anthnich on June 14, 2014, 05:42:33 pm
Can anyone reproduce this on their end with their gamepad axises?
Title: Re: A Concern About Joystick Axises
Post by: Hiura on June 14, 2014, 07:09:10 pm
OS?
Title: Re: A Concern About Joystick Axises
Post by: anthnich on June 15, 2014, 01:57:32 am
Windows 7.
Title: Re: A Concern About Joystick Axises
Post by: Jesper Juhl on June 15, 2014, 09:19:30 pm
Although you are not on Linux I feel the following may be relevant to this (or other people reading this) thread, so I'm just going to leave it here (my point is the Sony ps4 bits): http://www.phoronix.com/scan.php?page=news_item&px=MTY1MjQ
Title: Re: A Concern About Joystick Axises
Post by: anthnich on September 05, 2014, 09:19:21 pm
Sorry about the necro-bump, but I was curious if there is any updates on this? I still have the problem.

While rewriting portions of my engine, I changed around Init() order, so I just open the window before handling Input initialization. But, I figure the parent post will still be a problem if someone uses SFML & a gamepad w/o a window.
Title: Re: A Concern About Joystick Axises
Post by: Tank on September 06, 2014, 09:29:03 am
I will try to reproduce this with my Logitech game pad and see what I can do next week.
Title: Re: A Concern About Joystick Axises
Post by: anthnich on September 09, 2014, 05:57:04 pm
Thanks. Hopefully it's not too large of a problem.