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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - asdftest

Pages: [1]
1
General / pollEvent slows down game loop
« on: May 18, 2019, 02:02:54 pm »
Hi,

I'm having trouble with SFML's pollEvent on my system. When I'm moving my mouse around, the pollEvent-while-loop takes longer to compute (I can even stretch the processing time of the loop arbitrary long by continuously moving the mouse). I suspect that the event queue gathers more elements than can be processed.

Is there a fix for this problem? This problem only occurs on my laptop (specs below). However, I'm able to play other (more demanding) games with ease and therefore think this empty (!) while-loop shouldn't be a problem at all.

#include <SFML/Graphics.hpp>
#include <chrono>
#include <iostream>

int main(int argc, char** argv)
{
   sf::RenderWindow window(sf::VideoMode(300, 300, 32), "Hello");

   while (window.isOpen()) {
      auto start = std::chrono::system_clock::now();

      sf::Event event;
      while (window.pollEvent(event)) {
         if (event.type == sf::Event::Closed) {
            window.close();
         }
      }

      window.clear();
      window.display();

      auto end = std::chrono::system_clock::now();
      std::chrono::duration<double, std::milli> duration = end - start;
      std::cout << duration.count() << std::endl;
   }

   return 0;
}
 

Output:
23.2476
37.9425
31.6247
38.5042
44.0676
57.304
31.7052
24.3704
39.865
28.6723
146.977 <-- short mouse movement
28.2425
67.8935
1059.84 <-- heavy mouse movement
2356.55 <-- heavy mouse movement
 

My specs:
  • SFML 2.1
  • OS: Debian 8.11 jessie
  • CPU: Intel Core i5-2450M CPU @ 3.1GHz
  • GPU: GeForce GT 540M
  • RAM: 7856MB

Pages: [1]
anything