History

Fixed problem in idle(), causing events to stack up. The problem was that idle() was set on a zero-ms timer (using idleTimer->start(0)), and the time is then self-regulated by returning early if it's not time yet. Because of this, Qt stays perpetually in the timer servicing, instead of processing events. This causes keys and menu items to be delayed if the user drags the mouse before activating them, especially at low frame rates. It also causes very-delayed multitouch response.

The fix I've applied is to reset the idle timer after servicing the idle. I've set it to 2ms because I noticed that 1ms didn't always clear out all of the events. We can tune it to whatever we need, or even calculate it based on the time it took us to service the idle.

Eric Johnston committed 13 years ago

Commit 802abad1 parent 1d16df11 file · +5 −11Browse files

Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all

Unified · Split

interface/src/Application.cpp+5−11
@@ -82,6 +82,7 @@ const glm::vec3 START_LOCATION(4.f, 0.f, 5.f); // Where one's own node begins · 81 unmodified lines
82 82
83const int IDLE_SIMULATE_MSECS = 16; // How often should call simulate and other stuff83const int IDLE_SIMULATE_MSECS = 16; // How often should call simulate and other stuff
84 // in the idle loop? (60 FPS is default)84 // in the idle loop? (60 FPS is default)
85static QTimer* idleTimer = NULL;
85 86
86const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2;87const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2;
87 // Startup optimistically with small jitter buffer that 88 // Startup optimistically with small jitter buffer that
@@ -341,7 +342,7 @@ void Application::initializeGL() { · 253 unmodified lines
341 timer->start(1000);342 timer->start(1000);
342 343
343 // call our idle function whenever we can344 // call our idle function whenever we can
344 QTimer* idleTimer = new QTimer(this);345 idleTimer = new QTimer(this);
345 connect(idleTimer, SIGNAL(timeout()), SLOT(idle()));346 connect(idleTimer, SIGNAL(timeout()), SLOT(idle()));
346 idleTimer->start(0);347 idleTimer->start(0);
347 _idleLoopStdev.reset();348 _idleLoopStdev.reset();
@@ -973,19 +974,9 @@ void Application::idle() { · 625 unmodified lines
973 gettimeofday(&check, NULL);974 gettimeofday(&check, NULL);
974 975
975 // Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time we ran976 // Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time we ran
976 sendPostedEvents(NULL, QEvent::TouchBegin);
977 sendPostedEvents(NULL, QEvent::TouchUpdate);
978 sendPostedEvents(NULL, QEvent::TouchEnd);
979 977
980 double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check);978 double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check);
981 if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) {979 if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) {
982
983 // If we're using multi-touch look, immediately process any
984 // touch events, and no other events.
985 // This is necessary because id the idle() call takes longer than the
986 // interval between idle() calls, the event loop never gets to run,
987 // and touch events get delayed.
988
989 const float BIGGEST_DELTA_TIME_SECS = 0.25f;980 const float BIGGEST_DELTA_TIME_SECS = 0.25f;
990 update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS));981 update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS));
991 _glWidget->updateGL();982 _glWidget->updateGL();
@@ -998,6 +989,9 @@ void Application::idle() { · 6 unmodified lines
998 _idleLoopMeasuredJitter = _idleLoopStdev.getStDev();989 _idleLoopMeasuredJitter = _idleLoopStdev.getStDev();
999 _idleLoopStdev.reset();990 _idleLoopStdev.reset();
1000 }991 }
992
993 // After finishing all of the above work, restart the idle timer, allowing 2ms to process events.
994 idleTimer->start(2);
1001 }995 }
1002}996}
1003void Application::terminate() {997void Application::terminate() {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t