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
8282
8383 const int IDLE_SIMULATE_MSECS = 16; // How often should call simulate and other stuff
8484 // in the idle loop? (60 FPS is default)
85+static QTimer* idleTimer = NULL;
8586
8687 const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2;
8788 // Startup optimistically with small jitter buffer that
@@ -341,7 +342,7 @@ void Application::initializeGL() { · 253 unmodified lines
341342 timer->start(1000);
342343
343344 // call our idle function whenever we can
344− QTimer* idleTimer = new QTimer(this);
345+ idleTimer = new QTimer(this);
345346 connect(idleTimer, SIGNAL(timeout()), SLOT(idle()));
346347 idleTimer->start(0);
347348 _idleLoopStdev.reset();
@@ -973,19 +974,9 @@ void Application::idle() { · 625 unmodified lines
973974 gettimeofday(&check, NULL);
974975
975976 // 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);
979977
980978 double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check);
981979 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−
989980 const float BIGGEST_DELTA_TIME_SECS = 0.25f;
990981 update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS));
991982 _glWidget->updateGL();
@@ -998,6 +989,9 @@ void Application::idle() { · 6 unmodified lines
998989 _idleLoopMeasuredJitter = _idleLoopStdev.getStDev();
999990 _idleLoopStdev.reset();
1000991 }
992+
993+ // After finishing all of the above work, restart the idle timer, allowing 2ms to process events.
994+ idleTimer->start(2);
1001995 }
1002996 }
1003997 void 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