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

Author Topic: Can't get SFML 1.4 to work properly!  (Read 10690 times)

0 Members and 1 Guest are viewing this topic.

Joh

  • Newbie
  • *
  • Posts: 6
    • View Profile
Can't get SFML 1.4 to work properly!
« Reply #15 on: May 13, 2009, 03:55:55 am »
Some experimenting with modifying the Joystick::Initialize function and I found some weird output. The modified method is at the end of the post. This is the output it gives me:

Code: [Select]
Entered Joystick::Initialize(0)
ERROR: JOYERR_PARMS on index '0'.

Entered Joystick::Initialize(1)
For Joystick::Initialize(0)
Not the requested index: '0'. '1' requested.
ERROR: JOYERR_PARMS on index '1'.


So basically, when the method is run with 0 as parameter, joyGetPosEx instantly returns JOYERR_PARMS. When Initialize is run with 1 as index however, it finds one joystick with index 0, but since the requested index was 1 it chooses to ignore this. Quite odd. :?


Code: [Select]
void Joystick::Initialize(unsigned int Index)
{
    // Reset state
    myIndex     = JOYSTICKID1;
    myNbAxes    = 0;
    myNbButtons = 0;

    std::cout << "Entered Joystick::Initialize(" << Index << ")" << std::endl;

    // Get the Index-th connected joystick
    MMRESULT Error;
    JOYINFOEX JoyInfo;
    unsigned int NbFound = 0;
    for (NbFound = 0; (Error = joyGetPosEx(myIndex, &JoyInfo)) != JOYERR_PARMS; myIndex++)
    {
    std::cout << "For Joystick::Initialize(" << NbFound << ")" << std::endl;
        // Check if the current joystick is connected
        if (Error == JOYERR_NOERROR)
        {
            // Check if it's the required index
            if (NbFound == Index)
            {
                // Ok : store its parameters and return
                JOYCAPS Caps;
                joyGetDevCaps(myIndex, &Caps, sizeof(Caps));
                myNbAxes    = Caps.wNumAxes;
                myNbButtons = Caps.wNumButtons;
                if (myNbButtons > JoystickState::MaxButtons)
                    myNbButtons = JoystickState::MaxButtons;

                return;
            }
            else
            {
            std::cout << "Not the requested index: '" << NbFound << "'. '" << Index << "' requested." << std::endl;
            }

            // Go to the next valid joystick
            ++NbFound;
        }
    }
    std::cout << "ERROR: " << (Error == JOYERR_PARMS ? "JOYERR_PARMS" : "NONE") << " on index '" << NbFound << "'. " << std::endl << std::endl;
}

Joh

  • Newbie
  • *
  • Posts: 6
    • View Profile
Can't get SFML 1.4 to work properly!
« Reply #16 on: May 13, 2009, 04:14:07 am »
UPDATE: MSDN says this about the JOYINFOEX pointer:
Quote
Pointer to a JOYINFOEX structure that contains extended position information and button status of the joystick. You must set the dwSize and dwFlags members or joyGetPosEx will fail. The information returned from joyGetPosEx depends on the flags you specify in dwFlags.


I added them to the JoyInfo structure (sizeof(JoyInfo) and JOY_RETURNALL, respectively) and my gamepad works now. Might be a good idea to update the SVN version to do that as well.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Can't get SFML 1.4 to work properly!
« Reply #17 on: May 13, 2009, 07:43:57 am »
Great job :)

Thanks a lot, I'll update the code as soon as possible.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Can't get SFML 1.4 to work properly!
« Reply #18 on: May 13, 2009, 08:12:37 pm »
I've updated the SVN, can you confirm that it's ok?
Laurent Gomila - SFML developer

Joh

  • Newbie
  • *
  • Posts: 6
    • View Profile
Can't get SFML 1.4 to work properly!
« Reply #19 on: May 13, 2009, 10:41:45 pm »
Having downloaded and compiled the new SVN version with newest MinGW again gives me the bug that used to be issued where the entire app freezes on launch, before even entering the main function. Seeing as there's been no change between r1089 and r1890 other than those two lines though, which are the exact same I added yesterday, and it didn't freeze when I ran it then, the issue might be something else. I'll keep investigating and report back if I find something.

EDIT: My mistake, it works fine now. I had the joystick threshold set to 0, so my event loop was endless. Thanks for the help.

 

anything