7
\$\begingroup\$

I've tested the cross platform joystick support features on GLFW, SDL2 and SFML. SDL2 appears to be the most complete, but it can't detect when joysticks have been unplugged on OSX. To me, this is a fundamental feature.

Joystick detection support appears to be much weaker on the Mac than in Windows. What can I do to overcome this?

\$\endgroup\$
15
  • 1
    \$\begingroup\$ The help center explains very clearly what questions are considered off topic (as does Game Development Meta). "Lists-of" and "what-library-should-I-use" ("Are there any cross platform C++ libraries...") questions, as well as broad and opinion-oriented questions ("what makes this hotplugging hard...?") are off-topic. You appear to have misunderstood the goal of a StackExchange site, which is to archive concrete objective questions and answers and not to "appeal to developers in a similar position" necessarily. Fortunately the help center also includes a list of places you can ask off-topic questions. \$\endgroup\$
    – user1430
    Commented Apr 9, 2014 at 15:04
  • 1
    \$\begingroup\$ What are you suggesting? That there's no technical question to answer? It's certainly not a subjective question. \$\endgroup\$
    – Charlie
    Commented Apr 9, 2014 at 16:48
  • 3
    \$\begingroup\$ This is not a 'which tech to use?' question. I'm trying to understand why OSX has such a large problem with USB devices, and how one might approach the hotplugging problem in particular. If you knew the answer, or had anything to add, then you should just share it or move on and allow someone else to answer, as that is what the Stackexchange is primarily... A way for people to help others. I shan't post on this board again. A small loss I guess, but you'll understand why. I've had 4 answers to my question, and none of them are at all relevant. Or even helpful. \$\endgroup\$
    – Charlie
    Commented Apr 9, 2014 at 17:24
  • 1
    \$\begingroup\$ @Charlie, I voted for reopening. I almost always try to explain these votes, and yours is one of the first votes where I get explain why it gets the affirmative. The reason that "which tech" questions are off-topic is that they can only be answered based on specific project requirements, which usually means they can't be answered correctly. In your case, where you have a very specific feature requirement, I feel that the question is answerable and useful. Good luck in getting the rest of your votes. I also edited your question again; feel free to revert or reedit as you see fit. \$\endgroup\$ Commented Apr 10, 2014 at 0:05
  • 1
    \$\begingroup\$ I'd argue that "Is there a specific reason that joystick detection support is weaker for OSX" is completely off-topic here. The "What can be done" question is better. Maybe something like: "How can I detect a USB gamepad being disconnected during gameplay on OSX, using SDL2?", removing the first paragraph entirely. That phrasing seems like it'd be beyond reproach. \$\endgroup\$ Commented Apr 10, 2014 at 4:30

1 Answer 1

4
\$\begingroup\$

Using the latest SFML from github (2.1 should also work but I didn't test with it) you can listen for the sf::Event::JoystickConnected and sf::Event::JoystickDisconnected events as described in the SFML Events Tutorial. I've tested the events and they are both fired on Mac and Windows.

A sample program to test this would look like:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML Joystick Events!");


    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event:: JoystickConnected)
            {
                std::cout << "joystick connected: " << event.joystickConnect.joystickId << std::endl;
            }
            else if (event.type == sf::Event::JoystickDisconnected)
            {
                std::cout << "joystick disconnected: " << event.joystickConnect.joystickId << std::endl;
            }
            else if (event.type == sf::Event::Closed)
            {
                window.close();
            }
        }
    }

    return 0;
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .