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.
Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all
Unified · Split
| @@ -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 | |
| 83 | 83 | const int IDLE_SIMULATE_MSECS = 16; // How often should call simulate and other stuff |
| 84 | 84 | // in the idle loop? (60 FPS is default) |
| 85 | +static QTimer* idleTimer = NULL; | |
| 85 | 86 | |
| 86 | 87 | const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2; |
| 87 | 88 | // Startup optimistically with small jitter buffer that |
| @@ -341,7 +342,7 @@ void Application::initializeGL() { · 253 unmodified lines | ||
| 341 | 342 | timer->start(1000); |
| 342 | 343 | |
| 343 | 344 | // call our idle function whenever we can |
| 344 | − QTimer* idleTimer = new QTimer(this); | |
| 345 | + idleTimer = new QTimer(this); | |
| 345 | 346 | connect(idleTimer, SIGNAL(timeout()), SLOT(idle())); |
| 346 | 347 | idleTimer->start(0); |
| 347 | 348 | _idleLoopStdev.reset(); |
| @@ -973,19 +974,9 @@ void Application::idle() { · 625 unmodified lines | ||
| 973 | 974 | gettimeofday(&check, NULL); |
| 974 | 975 | |
| 975 | 976 | // 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 | 978 | double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check); |
| 981 | 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 | 980 | const float BIGGEST_DELTA_TIME_SECS = 0.25f; |
| 990 | 981 | update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS)); |
| 991 | 982 | _glWidget->updateGL(); |
| @@ -998,6 +989,9 @@ void Application::idle() { · 6 unmodified lines | ||
| 998 | 989 | _idleLoopMeasuredJitter = _idleLoopStdev.getStDev(); |
| 999 | 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 | } |
| 1003 | 997 | void Application::terminate() { |