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

Author Topic: Fix for joystick performance issues on Windows  (Read 4936 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Fix for joystick performance issues on Windows
« on: May 13, 2012, 10:19:23 pm »
I've implemented a workaround for this bug:
http://en.sfml-dev.org/forums/index.php?topic=6793.0
http://en.sfml-dev.org/forums/index.php?topic=6079.0

It would be great if you could test it, and confirm that it solves the performance problem and doesn't break anything :)
Laurent Gomila - SFML developer

Kai

  • Guest
Re: Fix for joystick performance issues on Windows
« Reply #1 on: June 05, 2012, 12:41:56 am »
My game isn't lagging from WindowImpl::processJoystickEvents() any more (it hasn't for a while, actually).

However, I am finding that the majority of SFML time is still being spent in JoystickImpl::isConnected() and specifically inside the call to ClockImpl::getCurrentTime(). I haven't used joysticks at all yet, I'm just polling a RenderWindow in a loop.

This is what my stack looks like 20~30% of the time when I pause the game:

>       sfml-system-d-2.dll!sf::priv::ClockImpl::getCurrentTime()  Line 63 + 0x10 bytes
        sfml-system-d-2.dll!sf::Clock::getElapsedTime()  Line 49 + 0x13 bytes
        sfml-window-d-2.dll!sf::priv::JoystickImpl::isConnected(unsigned int index)  Line 58 + 0x22 bytes
        sfml-window-d-2.dll!sf::priv::JoystickManager::update()  Line 80 + 0x9 bytes
        sfml-window-d-2.dll!sf::priv::WindowImpl::processJoystickEvents()  Line 150
        sfml-window-d-2.dll!sf::priv::WindowImpl::popEvent(sf::Event & event, bool block)  Line 106
        sfml-window-d-2.dll!sf::Window::pollEvent(sf::Event & event)  Line 183 + 0x1a bytes
 

The variable Joystick::Count is 7 on my computer. That means that JoystickImpl::isConnected() would be called 7 times for each call to JoystickManager::update().
« Last Edit: June 05, 2012, 12:47:34 am by Kai »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Fix for joystick performance issues on Windows
« Reply #2 on: June 05, 2012, 07:48:35 am »
Quote
I'm just polling a RenderWindow in a loop
Time has to be spent somewhere, and in an empty program I'm not surprised that it is in such a function. It would be more interesting to do a profiling test in a real application.
Laurent Gomila - SFML developer

Kai

  • Guest
Re: Fix for joystick performance issues on Windows
« Reply #3 on: June 05, 2012, 09:03:15 pm »
Quote
I'm just polling a RenderWindow in a loop
Time has to be spent somewhere, and in an empty program I'm not surprised that it is in such a function. It would be more interesting to do a profiling test in a real application.

Sorry, I wasn't being clear.

This is a real application -- it's a multiplayer platforming game that I've been developing full time for the last 6 months. I just meant that my game doesn't have joystick support currently, so it's clear that the large percentage of runtime is not due to using joysticks.

The other 70~80% of the game time is being spent in rendering, physics, scripting and sleeping.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Fix for joystick performance issues on Windows
« Reply #4 on: June 05, 2012, 09:07:26 pm »
I can definitely confirm that the framerate issues are fixed now, BUT there seems to be a little problem with initial Joystick detection now.

It is, as you told me in another thread, delayed now. So instead of getting the connected joysticks right after the creation of the window, I wait for joystick connection events in the main loop instead. However, those do not always occur even if a joystick is connected initially.

Note the "not always" - most of the time it works, I just had several cases where it didn't. Maybe you should force an initial poll for joysticks when a window is being created (and fire the respective connection events), and after that use the lower frequency which you implemented in this fix?

In my opinion, by the way, the sf::Joystick::isConnected method is now obsolete, since most of the time you will use it for initial polling, which apparently is not recommended anymore (on Windows at least). Connection and disconnection events are enough for people to manage their own "is connected" list of sorts.
« Last Edit: June 05, 2012, 09:10:17 pm by pdinklag »
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Fix for joystick performance issues on Windows
« Reply #5 on: June 05, 2012, 10:51:16 pm »
Yeah, a cleaner and more efficient solution will probably be implemented later, all I wanted to do before releasing SFML 2.0 was to avoid the initial major issue.
Laurent Gomila - SFML developer

 

anything