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

Author Topic: Speed issues with Joystick event processing  (Read 10440 times)

0 Members and 1 Guest are viewing this topic.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Speed issues with Joystick event processing
« Reply #15 on: May 11, 2012, 10:30:41 am »
Have you tried to play with setJoystickThreshold?
Whoops, that will probably be the issue. :-[ I get an event for every minor movement of a joystick axis, and it's probably because I did not define a treshold. Kinda forgot about this, thanks!
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32503
    • View Profile
    • SFML's website
    • Email
Re: Speed issues with Joystick event processing
« Reply #16 on: May 11, 2012, 10:36:04 am »
Quote
I get an event for every minor movement of a joystick axis, and it's probably because I did not define a treshold.
This is potentially an issue, because the default threshold (0.1) is supposed to be ok.
Laurent Gomila - SFML developer

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Speed issues with Joystick event processing
« Reply #17 on: May 11, 2012, 01:46:37 pm »
If I quickly move around the analog stick using the default treshold of 0.1, I usually get up to 3 events per frame, which is perfectly bearable. However, at times, I get way more than 100 per frame, and that's when it starts to hang badly (not a constantly low FPS, but sudden short freezes like every second or so).

I'll be observing this and see if I can find a possible cause. It mostly happened after other XBox controllers (I have 4) disconnected, maybe that's related somehow.
JSFML - The Java binding to SFML.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Speed issues with Joystick event processing
« Reply #18 on: May 11, 2012, 02:26:32 pm »
OK, I can definitely confirm it now.
It's all OK until controllers disconnect.

I waited for a while until they were all disconnected. Now I connected the first one again, and now the event handler seems to stop whenever I move the analog stick. The event handler (pollEvent) stops until I stop moving the sticks, as if it is locked. If I'm not moving the sticks, it all runs smoothly.

Altering the joystick treshold does not help here.

I'll try creating a minimal example in C++ soon.

Note that since it cannot be fixed until I restart my computer (simply re-plugging the adapter does not fix it), it might as well be an issue with the XBox adapter driver.
« Last Edit: May 11, 2012, 02:33:53 pm by pdinklag »
JSFML - The Java binding to SFML.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Speed issues with Joystick event processing
« Reply #19 on: May 17, 2012, 11:10:10 am »
The code below lets me reproduce the problem I had using XBox 360 controllers. It would be good if somebody could try it with others. I am not sure whether it can be reproduced with only one controller, but it's probably worth a try as well.

Steps to reproduce:
  • Connect one or more controllers and start the application, it should tell you how many controllers ("joysticks") it detected.
  • Play around with the Joystick axes so the application receives joystick movement events. It should tell you how many it received per frame. The usual value using one controller and moving one axis should be like 3 per frame max.
  • Exit the application, disconnect one or more controllers and repeat steps 1 and 2.
    Now suddenly, while you are moving the joystick axis, the current frame should be locked until you stop moving, yielding many events received during a single frame and making the frame last for a long time ( = frame rate drop).

This keeps happening everytime you restart the application now until the system is restarted, so I guess it might be a driver issue related to the XBox 360 controller adapter.

This is the code in question:
#include <stdio.h>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main() {
        //Create window
        sf::RenderWindow window(sf::VideoMode(200, 150), "Joystick Test");
        window.setFramerateLimit(60);
       
        //Detect joysticks
        printf("Detecting joysticks... ");
       
        int numJoysticks = 0;
        while(sf::Joystick::isConnected(numJoysticks))
                numJoysticks++;

        printf("%d joystick(s) detected!\n", numJoysticks);
       
        //Blah
        sf::Text text("See console output...");
        text.setCharacterSize(16);
        text.setPosition(sf::Vector2f(5, 5));
       
        //Main loop
        printf("Listening for joystick move events...");
       
        sf::Clock clock;
       
        sf::Event event;
        while(window.isOpen()) {
                int numJoystickMoved = 0;
       
                while(window.pollEvent(event)) {
                        switch(event.type) {
                                case sf::Event::Closed:
                                        window.close();
                                        break;
                               
                                case sf::Event::JoystickMoved:
                                        numJoystickMoved++;
                                        break;
                       
                                default:
                                        break;
                        }
                }
               
                if(numJoystickMoved)
                        printf("Received %d joystick movement events this frame!\n", numJoystickMoved);
               
                float frameTime = clock.restart().asSeconds();
                if(frameTime > 0.25f)
                        printf("This frame took %0.2f seconds!\n", frameTime);
       
                window.clear();
                window.draw(text);
                window.display();
        }
}
 
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32503
    • View Profile
    • SFML's website
    • Email
Re: Speed issues with Joystick event processing
« Reply #20 on: May 17, 2012, 03:34:04 pm »
Have you tried the same steps with another program (game) that uses a joystick, to see whether it's specific to SFML or not?
Laurent Gomila - SFML developer

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Speed issues with Joystick event processing
« Reply #21 on: May 17, 2012, 04:37:39 pm »
I don't have too many Joystick related applications, but I just tried it in Project64 (Nintendo 64 emulator) and it does not have this problem, neither does the Windows gamepad calibration window.

After I ran those, the problem didn't occur in that SFML application again. Weird.  :-\
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32503
    • View Profile
    • SFML's website
    • Email
Re: Speed issues with Joystick event processing
« Reply #22 on: May 17, 2012, 04:50:31 pm »
Have you tried the latest sources?
Laurent Gomila - SFML developer

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Speed issues with Joystick event processing
« Reply #23 on: May 17, 2012, 04:59:44 pm »
The version I'm using now is from Saturday (May 12), I see you applied some changes on May 13. Talk about bad timing. :) Trying the latest version now...
JSFML - The Java binding to SFML.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Speed issues with Joystick event processing
« Reply #24 on: May 17, 2012, 05:26:05 pm »
Same setup, latest SFML snapshot.
sf::Joystick::isConnected(0) (and probably all other indices) always returns "false" for me now, even though the controller is connected.

However, the input events for it are received properly and I could not reproduce the problem I had before so far.
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32503
    • View Profile
    • SFML's website
    • Email
Re: Speed issues with Joystick event processing
« Reply #25 on: May 17, 2012, 05:41:05 pm »
Quote
sf::Joystick::isConnected(0) (and probably all other indices) always returns "false" for me now, even though the controller is connected.
There's an update delay now, so if you check directly at startup, the result will most likely be wrong.
Laurent Gomila - SFML developer

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Speed issues with Joystick event processing
« Reply #26 on: May 17, 2012, 08:14:40 pm »
There's an update delay now, so if you check directly at startup, the result will most likely be wrong.
Indeed, after a while (first few frames) I get a joystick conncetion event. ;)
JSFML - The Java binding to SFML.