Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Announcement] New support for joysticks  (Read 9387 times)

0 Members and 1 Guest are viewing this topic.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Announcement] New support for joysticks
« on: May 08, 2011, 12:59:42 pm »
Hey!

I'm happy to announce you that joysticks are now managed by SFML on Mac OS X too!

We need you to test this out! Please report me any strange behaviour.

Only POV axes are not (yet) supported. I don't have any joystick with POV to test and implement so if anyone can help me out here I'll be very thankful!  :wink:

You can add this code to your event loop and adapt it to your own application :
Code: [Select]
           //*
            if (Event.Type == sf::Event::JoyMoved) {
                std::cout << "sf::Event::JoyMoved" << std::endl;
                std::cout << "\tEvent.JoyMove.JoystickId" << Event.JoyMove.JoystickId << std::endl;
                std::cout << "\tEvent.JoyMove.Axis" << toString(Event.JoyMove.Axis) << std::endl;
                std::cout << "\tEvent.JoyMove.Position" << Event.JoyMove.Position << std::endl;
            }
            //*/
           
            //*
            if (Event.Type == sf::Event::JoyButtonPressed) {
                std::cout << "sf::Event::JoyButtonPressed" << std::endl;
                std::cout << "\tEvent.JoyButton.JoystickId" << Event.JoyButton.JoystickId << std::endl;
                std::cout << "\tEvent.JoyButton.Button" << Event.JoyButton.Button << std::endl;
            }
            //*/
           
           
            //*
            if (Event.Type == sf::Event::JoyButtonReleased) {
                std::cout << "sf::Event::JoyButtonReleased" << std::endl;
                std::cout << "\tEvent.JoyButton.JoystickId" << Event.JoyButton.JoystickId << std::endl;
                std::cout << "\tEvent.JoyButton.Button" << Event.JoyButton.Button << std::endl;
            }
            //*/


where the toString function only a big switch :
Code: [Select]
std::string toString(sf::Joy::Axis axis) {
    switch (axis) {
        case sf::Joy::AxisPOV:
            return "POV";
           
        case sf::Joy::AxisR:
            return "R";
           
        case sf::Joy::AxisU:
            return "U";
           
        case sf::Joy::AxisV:
            return "V";
           
        case sf::Joy::AxisX:
            return "X";
           
        case sf::Joy::AxisY:
            return "Y";
           
        case sf::Joy::AxisZ:
            return "Z";
           
        default:
            return "???";
    }
}


Have Fun!  :)
SFML / OS X developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Announcement] New support for joysticks
« Reply #1 on: May 14, 2011, 04:00:31 pm »
No one to try it out ?  :?
SFML / OS X developer

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
[Announcement] New support for joysticks
« Reply #2 on: May 14, 2011, 04:07:41 pm »
Nope, no joystick :?
Want to play movies in your SFML application? Check out sfeMovie!

Sui

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://www.suisoft.co.uk/
[Announcement] New support for joysticks
« Reply #3 on: July 10, 2011, 11:53:54 am »
I have a few different USB gamepads knocking around. I thought I had a Microsoft Flightstick somewhere but maybe it was binned off when I downsized my office.

I'll try to have a play at some point. I'm building against 1.6 at the moment.

Is the 2.0 joystick interface very similar to the 1.6 version?

I'm wondering if it might be easy to put the new joystick code into the 1.6 codebase.
Gary Marples, Developer of games and other stuff.
www.suisoft.co.uk/games/BlogTwitter

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Announcement] New support for joysticks
« Reply #4 on: July 10, 2011, 12:59:00 pm »
There is no joystick support on Mac with SFML 1.6 as far as I remember.

The current Joystick input has just changed the past week (see http://www.sfml-dev.org/forum/viewtopic.php?t=5250 ) and is not available on Mac yet. However, it should be ready next week.
SFML / OS X developer

Sui

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://www.suisoft.co.uk/
[Announcement] New support for joysticks
« Reply #5 on: July 10, 2011, 06:11:51 pm »
Yes, you're right - the joystick code in 1.6 is only for PC.

I wondered if I could easily integrate the Mac joystick code from 2.0 into the 1.6 codebase myself, as I want to build my game against the 1.6 (final) build initially.

Sounds like it has changed quite a lot, though. I'll take a look.

Great job with the SFML library by the way.

I've been working with it for a few weeks now. It is very neat and enabled me to get something working on the Mac very quickly (I have minimal Mac experience).

Is there a what's new list somewhere for 2.0?

Thanks.
Gary Marples, Developer of games and other stuff.
www.suisoft.co.uk/games/BlogTwitter

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Announcement] New support for joysticks
« Reply #6 on: July 10, 2011, 10:07:32 pm »
Quote from: "Sui"
I wondered if I could easily integrate the Mac joystick code from 2.0 into the 1.6 codebase myself, as I want to build my game against the 1.6 (final) build initially.
In fact, the previous implementation of joysticks in SFML2 should works in SFML1.6 too. You can copy these three file to 1.6 sources (with the same name except OSX folder was called Cocoa at that time).

https://github.com/SFML/SFML/blob/efd97597bfbb7d38ce9308242bdf03d79f1eafc4/src/SFML/Window/Joystick.hpp
https://github.com/SFML/SFML/blob/efd97597bfbb7d38ce9308242bdf03d79f1eafc4/src/SFML/Window/OSX/Joystick.cpp
https://github.com/SFML/SFML/blob/efd97597bfbb7d38ce9308242bdf03d79f1eafc4/src/SFML/Window/OSX/Joystick.hpp

You'll need to add IOKit framework to the linker too.

Have fun! :wink:

Quote from: "Sui"
Is there a what's new list somewhere for 2.0?
No yet, however, I think, Laurent will give such list when SFML2 is finalized (no due date). But if you really want to know what has changed you can look at some topic in the 'general discussions' forum. Laurent put some news there, from time to time.
SFML / OS X developer

Sui

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://www.suisoft.co.uk/
[Announcement] New support for joysticks
« Reply #7 on: July 10, 2011, 10:17:56 pm »
Nice one. Thanks a lot.

I'll give them a shot.

Need to figure out how to install a gamepad on Mac first (assuming it doesn't magically download a driver - I can hope!)
Gary Marples, Developer of games and other stuff.
www.suisoft.co.uk/games/BlogTwitter

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[Announcement] New support for joysticks
« Reply #8 on: July 10, 2011, 10:40:36 pm »
With this implementation you don't need any driver I think. It use standardized usb specification.

At least I don't need any driver to use my PS3 controller.
SFML / OS X developer

Sui

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://www.suisoft.co.uk/
[Announcement] New support for joysticks
« Reply #9 on: July 23, 2011, 09:32:59 pm »
Haven't forgotten about this... just finishing some other bits off on my arcade game engine first.

Not had any problems getting my code to work on Mac & PC. Just a few minor niggles with subtle C++ compiler differences.
Gary Marples, Developer of games and other stuff.
www.suisoft.co.uk/games/BlogTwitter

capz

  • Newbie
  • *
  • Posts: 29
    • View Profile
[Announcement] New support for joysticks
« Reply #10 on: December 19, 2011, 10:21:02 pm »
sorry about the bump, but I'm running into some issues with controllers here and this seemed like the best topic to address it : )

I've recently been working on a project with SFML, and converted over from SFML to SFML 2 due to the lack of Controller/Joystick support for 1.6.

Having finally gotten everything updated to work with SFML 2, I discovered that my Xbox 360 controller (with HID driver from tattiebogle (google it)) refused to work on my mac. My Gamecube to USB adapter, supporting HID out of the box on Mac OS X, works just fine.

The 360 joystick works fine in any piece of software, such as emulators. SDL even, but not in SFML 2.

Also, I tried removing the driver as you mentioned your PS3 controller worked without one, but that definetely stops it from functioning in the other software, and doesn't change the fact that SFML 2 just isn't picking it up.

I have no clue what's going on and being able to use the 360 controller would be really nice seeing as I bought the thing specifically for use with my project..

It might be the driver, though, but I just don't know.
I've fired up IORegistryExplorer and it shows the following info about the controllers [ link ]

Would it be possible to sort out this issue?

PS. I was using sf::Joystick::IsConnected to test for joypads

Edit:

I can confirm that the PS3 controller is indeed picked up as a HID device out of the box on Mac OS X Lion, but I know for sure that it wasn't on Snow Leopard because it, too required special drivers to function on that OS. Apple must have added support for it :O

Edit2:

Actually, I've been digging through the source of SFML2, IOKit documentation, and whatnot, and I noticed the following:

in SFML/Window/OSX/HIDJoystickManager.cpp:
Line 78:    

Code: [Select]
CFDictionaryRef mask = HIDInputManager::CopyDevicesMask(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick);
Looks to me like HID devices are filtered in the constructor of HIDJoystickManager, by kHIDUsage_GD_Joystick

I found in the SDL implementation of OSX Joysticks that they actually filter on kHIDUsage_GD_Joystick and kHIDUsage_GD_Gamepad

Now, using Apple's HID_Dumper example project, I printed a dump of info about my HID Devices.

Code: [Select]
Device: 0x332340 = { ©Microsoft Corporation - Controller, vendorID: 0x045E, productID: 0x028E, usage: 0x0001:0x0005, "Generic Desktop GamePad", Transport: "USB", SerialNumber: "05B528B", locationID: 0xFD130000, MaxInputReportSize: 14, ReportInterval: 8000, }

Device: 0x332fb0 = { Sony - PLAYSTATION(R)3 Controller, vendorID: 0x054C, productID: 0x0268, usage: 0x0001:0x0004, "Generic Desktop Joystick", Transport: "Bluetooth", VendorIDSource: 2, version: 256, SerialNumber: "00-1b-fb-a3-90-f9", CountryCode: 33, locationID: 0x7BA390F9, MaxInputReportSize: 49, MaxOutputReportSize: 49, MaxFeatureReportSize: 49, ReportInterval: 11250, }

Device: 0x332ad0 = { WiseGroup.,Ltd - GameCube to USB box 1, vendorID: 0x0926, productID: 0x8888, usage: 0x0001:0x0004, "Generic Desktop Joystick", Transport: "USB", version: 648, locationID: 0xFA120000, MaxInputReportSize: 8, MaxOutputReportSize: 7, ReportInterval: 8000, }



You'll notice that the 360 controller shows up as a Gamepad, and it doesn't work with SFML. the PS3 and GC adapters show up as Joysticks, and they DO work.

In other words, I don't know how to include Gamepads in the HID devices filtering code (I tried, but it didn't produce anything functional), but simply adding them may very well resolve this issue. (which would make me eternally grateful)