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

Author Topic: [Linux] pollEvent is slow / disable joystick  (Read 2279 times)

0 Members and 1 Guest are viewing this topic.

pyhax

  • Newbie
  • *
  • Posts: 2
    • View Profile
[Linux] pollEvent is slow / disable joystick
« on: August 21, 2012, 08:53:44 pm »
Hi,

I just wrote a little program using SFML and profiled it, because it was lagging a bit. The profiler said the 20% of the time is spent in sf::Window::pollEvent. I found out that the slow part of it is in sf::prov::JoystickImpl::isConnected. In that function, there is an ostringstream created everytime it is called (42% of the time in that function is spent in std::basic_ios<>::init), so I tried replacing JoystickImpl::isConnected with the following code:
bool JoystickImpl::isConnected(unsigned int index)
{
    char filename[13 /* For /dev/input/js */ + std::numeric_limits<unsigned int>::digits10 + 1 /* Null termination */];
    std::sprintf(filename + 13, "/dev/input/js%u", index);

    struct stat info;
    return stat(filename, &info) == 0;
}
 

With this modification the lags disappeared. But with that change, the user would have to install the sfml libraries with the changed code too. So, is there any way to just disable joystick support in SFML? I don't need it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [Linux] pollEvent is slow / disable joystick
« Reply #1 on: August 21, 2012, 09:03:02 pm »
There's no way to disable joystick handling without recompiling SFML. But I can apply this patch before the final release of SFML 2.0 :)

Thanks.
Laurent Gomila - SFML developer

pyhax

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: [Linux] pollEvent is slow / disable joystick
« Reply #2 on: August 21, 2012, 09:40:15 pm »
Woops, sry, in the posted code is an error:
 char filename[13 /* For /dev/input/js */ + std::numeric_limits<unsigned int>::digits10 + 1 /* Null termination */];
 std::sprintf(filename + 13, "/dev/input/js%u", index);
must be
 char filename[13 /* For /dev/input/js */ + std::numeric_limits<unsigned int>::digits10 + 2 /* Null termination */];
 std::sprintf(filename, "/dev/input/js%u", index);
 

The + 13 was left over from some experiments. +2 instead of +1 for array size is because of http://stackoverflow.com/a/5926044 (See comments),
« Last Edit: August 21, 2012, 09:57:22 pm by pyhax »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [Linux] pollEvent is slow / disable joystick
« Reply #3 on: August 26, 2012, 02:54:43 pm »
Patch applied. Thanks for your help :)
Laurent Gomila - SFML developer