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

Author Topic: Polling for events drastically lowers frame rate  (Read 15396 times)

0 Members and 1 Guest are viewing this topic.

Ltp0wer

  • Newbie
  • *
  • Posts: 4
    • MSN Messenger - ltp0wer@hotmail.com
    • AOL Instant Messenger - ltp0wer
    • View Profile
    • http://www.ltp0wer.com
Polling for events drastically lowers frame rate
« on: October 14, 2011, 01:29:54 am »
I am having a strange problem.

Anytime I am polling for events, my frame rate drops incredibly. Even more so if I am moving the mouse while polling for events.

For example, with this code:
Code: [Select]

#include <SFML/Graphics.hpp>


int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 800), "SFML window");


    while (window.IsOpened())
    {
        window.Clear();


        /*
        sf::Event event;
        while (window.PollEvent(event))
        {
            if (event.Type == sf::Event::Closed)
                window.Close();

            if (event.Type == sf::Event::KeyPressed)
            {
                if (event.Key.Code == sf::Keyboard::Key::Escape)
                    window.Close();
            }
        }
        */

        window.Display();
    }

    return EXIT_SUCCESS;


I get well over 1000 FPS with this code. When I uncomment the block polling for events, I get around 50 fps, and if I move my mouse around the window (slowly or quickly), it drops to a range of 1-20.

My specs are:
Q6600 Intel Core2Quad 2.66ghz
Nvidia GeForce GTX 260
3.5GB of RAM

I am using SFML 2.0

I don't think this is an SFML problem, as old programs I made in SFML 1.6 on a different computer, run slow as well on this computer. Also, my friend who also uses SFML 2.0, sent me a program he made that just displays the FPS in the graphics window. As I expected, I get the same low fps problem.

Are there any known issues that would cause this? I've already tried updating my graphics card drivers, and it hasn't helped.

Thanks.

Edit:

Operating system is Windows 7 32bit

Also, I have tried compiling my programs in both debug and release mode, as well as both dynamic linking and static linking, and I have the same issue.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Polling for events drastically lowers frame rate
« Reply #1 on: October 14, 2011, 03:43:38 am »
That... is weird. It doesn't even sound like a driver issue. It sounds more like your computer is on the verge of imploding. Do you have anti-virus installed? What operating system?
I use the latest build of SFML2

Ltp0wer

  • Newbie
  • *
  • Posts: 4
    • MSN Messenger - ltp0wer@hotmail.com
    • AOL Instant Messenger - ltp0wer
    • View Profile
    • http://www.ltp0wer.com
Polling for events drastically lowers frame rate
« Reply #2 on: October 14, 2011, 04:06:49 am »
Quote from: "OniLink10"
That... is weird. It doesn't even sound like a driver issue. It sounds more like your computer is on the verge of imploding. Do you have anti-virus installed? What operating system?


No anti-virus, but I run Spybot S&D and Ad-aware SE Personal every once in awhile. I'll try doing that now.

Operating system is Windows 7 32bit (Can't believe I forgot to include that in the OP)

Also, I should mention that this doesn't happen with any other games I have played, but then again, most of those are Direct3D AAA titles.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Polling for events drastically lowers frame rate
« Reply #3 on: October 14, 2011, 07:46:47 am »
Can you try to comment the call to ProcessJoystickEvents in src/SFML/Window/Window.cpp?
Laurent Gomila - SFML developer

Ltp0wer

  • Newbie
  • *
  • Posts: 4
    • MSN Messenger - ltp0wer@hotmail.com
    • AOL Instant Messenger - ltp0wer
    • View Profile
    • http://www.ltp0wer.com
Polling for events drastically lowers frame rate
« Reply #4 on: October 14, 2011, 08:19:42 am »
Quote from: "Laurent"
Can you try to comment the call to ProcessJoystickEvents in src/SFML/Window/Window.cpp?


I commented out "ProcessJoystickEvents();" on line 121 and line 133 of src/SFML/Window/WindowImpl.cpp and recompiled.

It is working beautifully. :D

You are a god damn genius.

What does this mean though?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Polling for events drastically lowers frame rate
« Reply #5 on: October 14, 2011, 09:32:56 am »
Each time this function is called, it polls joysticks to see if they are connected/disconnected. Apparently this is a very slow operation.

Unfortunately, on Windows there's no asynchronous/callback system that would notify when a joystick is connected/disconnected, which would avoid this polling and save a lot of CPU. I still need to find a solution to this -- maybe just increase the polling interval.
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Polling for events drastically lowers frame rate
« Reply #6 on: October 14, 2011, 09:45:56 am »
Quote from: "Laurent"
Can you try to comment the call to ProcessJoystickEvents in src/SFML/Window/Window.cpp?


Laurent is this an issue that anyone who doesnt use a joystick should also comment out from the code?
SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Polling for events drastically lowers frame rate
« Reply #7 on: October 14, 2011, 09:51:06 am »
Quote
Laurent is this an issue that anyone who doesnt use a joystick should also comment out from the code?

Until it's fixed, yes, it is a potential problem.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Polling for events drastically lowers frame rate
« Reply #8 on: October 14, 2011, 12:05:30 pm »
Is this function only needed to recognize the plugging-in of a joystick while SFML is running or does it poll the actual joystick events? In the first case, SFML could do it at startup and provide a function in sf::Joystick to call manually later. It's not beautiful however, and I would only do it if the automatic recognition is a severe performance issue.

By the way, are the IsConnected() and Update() functions of sf::Joystick somehow related to this?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Polling for events drastically lowers frame rate
« Reply #9 on: October 14, 2011, 12:13:33 pm »
In fact the guilty one is JoystickImpl::IsConnected, which is called by JoystickManager::Update, which is called by WindowImpl::ProcessJoystickEvents.

A simple workaround would be to call JoystickManager::Update only once per second (for example) instead of everytime PollEvent is called.
Laurent Gomila - SFML developer

mbro2k

  • Newbie
  • *
  • Posts: 7
    • View Profile
Polling for events drastically lowers frame rate
« Reply #10 on: October 17, 2011, 12:04:35 am »
Hey I tried Laurent's suggestion and only called IsConnected every few seconds and it solved my problem!
(my problem was a choppy framerate when running with a newly connected xbox controller for the first time).

Actually I had to keep JoystickManager::Update running normally, because my joystick would not work properly.
I actually put the timer before the IsConnected function itself within
JoystickManager::Update

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Polling for events drastically lowers frame rate
« Reply #11 on: October 17, 2011, 08:00:03 am »
Yes, that was the right thing to do, my previous message was incorrect :)
Laurent Gomila - SFML developer

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Polling for events drastically lowers frame rate
« Reply #12 on: November 05, 2011, 03:27:20 am »
Wouldn't it be possible to run that method on a separate thread, and every frame just check if the thread had finished, re-launching it if it had?

Felheart

  • Newbie
  • *
  • Posts: 23
    • View Profile
Polling for events drastically lowers frame rate
« Reply #13 on: November 05, 2011, 07:01:05 am »
I think a seperate thread would be acceptable untill there is a better solution.
In my game I need those functions (the easy access to gamepads / joysticks is one of the reasons I switched to SFML).
If you increase the polling intervall, wouldn't the input-delay rise with it?
That would be horrible :(

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Polling for events drastically lowers frame rate
« Reply #14 on: November 05, 2011, 03:14:10 pm »
If it have a delay high enough to damage FPS, then it will be always bad to put it in the same thread as the game loop. If it is in a separate thread, it will not damage FPS and will be called right when it is ready to be called, without waiting for seconds or so.

 

anything