[Moved] Timer used to repaint (advance) delayed by event flood processing
-
[quote author="Volker" date="1293486907"]Main thread does all the GUI stuff.
"background" thread does all the ball calculations and sends a signal to the main thread which in turn does the graphics update.
[/quote]Calculating the next ball position is just x=x+1. The problem is that the timer's timeout() is not triggered as expected (30 times a second), because the main thread is busy handling the mouse/touch events.
-
peppe, at least OP can try it and maybe it will solve the problem.
-
Wtf? Is this some kind of SERIOUS help or just "try this random thing"?
-
peppe, forum is "try this thing" at 85% of questions.
dflorin, try to count how often paintEvent is invoked. If it invoked in good frequency then using background thread will help. -
[quote]peppe, forum is “try this thing” at 85% of questions. [/quote]
This dramatically makes a forum a low-quality forum.Still, after 10 posts, noone managed to explain me WHY your suggestion should work.
-
peppe, I don't know forum where you can ask any question you have stucked with and receive answer correctly and quickly. And this discussion is offtopic. If you have something to add about subj of topic then add.
-
Back to the subject. I made some measurements:
When not moving the bat:
- Bat::paint() called 30 times (how many times the bat is repainted as a result of setPos() called from the event() method)
- Ball::advance() called 30 times (this is called by the timer and should be 30 calls instead) - this will trigger paint()
NOTE: the Bat is also repainted because I use:
view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
This should not have any impact on my problem.When moving the bat as fast as I can using touch events:
- Scene::event() called 47 times (this is how fast I move the bat by touching the screen)
- Bat::paint() called 50 times (how many times the bat is repainted as a result of setPos() called from the event() method and as a result of paint() done for the ball)
- Ball::advance() called 13 times (this is called by the timer and should be 30 calls instead) - this is my problem: the ball has slowed down at less than half speed.
And one more thing: this is noticeable on a Symbian device. Running it in the simulator on Windows and using mouse events instead of touch events does not slow down the ball. Should the post be moved to Mobile and Embedded?
-
dflorin, looking at this measurement I think it is worth to try moving ball coordinates calculation into another thread.
-
[quote author="Denis Kormalev" date="1293490361"]dflorin, looking at this measurement I think it is worth to try moving ball coordinates calculation into another thread.[/quote]
Even if the advance() only does x=x+1?
Please note my comment related to reproducibility on Symbian only.
-
dflorin, problem is not in calculation complexity, problem is in a big count of mouse and paint events which don't allow your timer to work in needed frequency.
-
Ok, thanks. I will try that and get back with the result.
-
But what is done inside this events.
If I countthe events you tell, it is about 110 evnts, that's not much work. But what is done inside Scene::event? Why is bat painted 50 times? that means 50 times a complete viewport repaint? That is overhead.
If Ball::advance initiates an update, which results in a full repaint, that means in your example 63 times a full repaint with all items / elemnts. I'm not sure how fast you processor is (as it's an embedded device I think). On a PC, it wouldn't be problematic.
What do you do in the touch events? Is this time consuming?
All this were just ideas, that came into my mind.
-
On one of the last DevDays there was talk about speeding up QGraphicsView. Here are some of the presentations that might help you:
"Graphics View (2007) ":http://qt.nokia.com/developer/learning/online/talks/archive/developerdays2007/graphics-view
"Optimizing Performance in Qt-Based Applications (2009) ":http://qt.nokia.com/developer/learning/online/talks/developerdays2009/tech-talks/optimizing-performance-in-qt-based-applications
"Beautiful and Blazing-Fast Graphics with Qt (2008) ":http://qt.nokia.com/developer/learning/online/talks/archive/developerdays2008/beautiful-and-blazing-fast-graphics-with-qtI did not review the videos, so it could also be that they fail the topic completely.
I do remember that some issues can be solved by setting the proper caching strategy to avoid complete repaints of the graphics scene.
-
Gerolf is right, full repaint is an overhead. Maybe you can try to make partial repaints (where it is needed)?
-
[quote author="dflorin" date="1293490166"]
When moving the bat as fast as I can using touch events:- Scene::event() called 47 times (this is how fast I move the bat by touching the screen)
- Bat::paint() called 50 times (how many times the bat is repainted as a result of setPos() called from the event() method and as a result of paint() done for the ball)
- Ball::advance() called 13 times (this is called by the timer and should be 30 calls instead) - this is my problem: the ball has slowed down at less than half speed.
[/quote]
Are these values per second? Can you monitor the CPU usage while moving the bat and/or profile? This doesn't seem to be a flood of events (47+50+13 = 120), rather it seems you're wasting CPU somewhere (for processing events, drawing, etc.) and not returning to the event loop so often like you should; especially, a full viewport update seems to be an overkill. Is there any reason why you chose to do so?
[quote] And one more thing: this is noticeable on a Symbian device. Running it in the simulator on Windows and using mouse events instead of touch events does not slow down the ball. Should the post be moved to Mobile and Embedded?[/quote]
Perhaps the Symbian device hasn't the needed CPU power, or there's a bug somewhere. I'll leave the decision about moving the post to admins :-)
-
As Volker told, there were topics on repainting the QGraphicsView, also on 2010. They showed the difference between Raster painting, open GL etc. I think, it was this:
"Performance: Do Graphics the Right Way ":http://qt.nokia.com/developer/learning/online/talks/developerdays2010/tech-talks/performance-do-graphics-the-right-way
-
YESSS! Gerolf, you are a truffle pig :-)
-
[quote author="peppe" date="1293492647"]
Perhaps the Symbian device hasn't the needed CPU power, or there's a bug somewhere. I'll leave the decision about moving the post to admins :-)[/quote]I'll leave it here for some time. Maybe some Troll can confirm that it is related only to mobile (or even only to symbian).
-
Some more measurements.
This is how it looks before moving the bat:
bq. [Qt Message] "13:29:53.620" Scene::event() ENTER
[Qt Message] "13:29:53.621" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.624" Bat::paint() - paintCount: 63
[Qt Message] "13:29:53.627" Ball::paint() ENTER
[Qt Message] "13:29:53.630" Ball::paint() EXIT
[Qt Message] "13:29:53.647" Ball::advance() - ENTER
[Qt Message] "13:29:53.649" Ball::advance() - advanceCount: 63
[Qt Message] "13:29:53.650" Ball::advance() - EXIT
[Qt Message] "13:29:53.652" Scene::event() ENTER
[Qt Message] "13:29:53.653" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.656" Bat::paint() - paintCount: 64
[Qt Message] "13:29:53.660" Ball::paint() ENTER
[Qt Message] "13:29:53.663" Ball::paint() EXIT
[Qt Message] "13:29:53.678" Ball::advance() - ENTER
[Qt Message] "13:29:53.680" Ball::advance() - advanceCount: 64
[Qt Message] "13:29:53.681" Ball::advance() - EXIT
[Qt Message] "13:29:53.683" Scene::event() ENTER
[Qt Message] "13:29:53.684" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.688" Bat::paint() - paintCount: 65
[Qt Message] "13:29:53.692" Ball::paint() ENTER
[Qt Message] "13:29:53.695" Ball::paint() EXIT
[Qt Message] "13:29:53.711" Ball::advance() - ENTER
[Qt Message] "13:29:53.713" Ball::advance() - advanceCount: 65
[Qt Message] "13:29:53.714" Ball::advance() - EXIT
[Qt Message] "13:29:53.716" Scene::event() ENTER
[Qt Message] "13:29:53.718" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.722" Bat::paint() - paintCount: 66
[Qt Message] "13:29:53.725" Ball::paint() ENTER
[Qt Message] "13:29:53.728" Ball::paint() EXITThis is how it looks after I start touching the screen and moving the bat as fast as I can:
bq. Qt Message] "13:29:53.732" Scene::event() ENTER
[Qt Message] "13:29:53.733" Scene::event() - touchCount: 1
[Qt Message] "13:29:53.737" Scene::event() EXIT - touch event processed
[Qt Message] "13:29:53.738" Scene::event() ENTER
[Qt Message] "13:29:53.740" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.742" Scene::event() ENTER
[Qt Message] "13:29:53.744" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.746" Ball::advance() - ENTER
[Qt Message] "13:29:53.748" Ball::advance() - advanceCount: 66
[Qt Message] "13:29:53.751" Ball::advance() - EXIT
[Qt Message] "13:29:53.753" Scene::event() ENTER
[Qt Message] "13:29:53.754" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.757" Bat::paint() - paintCount: 67
[Qt Message] "13:29:53.760" Ball::paint() ENTER
[Qt Message] "13:29:53.763" Ball::paint() EXIT
[Qt Message] "13:29:53.778" Ball::advance() - ENTER
[Qt Message] "13:29:53.780" Ball::advance() - advanceCount: 67
[Qt Message] "13:29:53.783" Ball::advance() - EXIT
[Qt Message] "13:29:53.785" Scene::event() ENTER
[Qt Message] "13:29:53.786" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.789" Bat::paint() - paintCount: 68
[Qt Message] "13:29:53.791" Ball::paint() ENTER
[Qt Message] "13:29:53.794" Ball::paint() EXIT
[Qt Message] "13:29:53.809" Ball::advance() - ENTER
[Qt Message] "13:29:53.812" Ball::advance() - advanceCount: 68
[Qt Message] "13:29:53.815" Ball::advance() - EXIT
[Qt Message] "13:29:53.816" Scene::event() ENTER
[Qt Message] "13:29:53.818" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.821" Bat::paint() - paintCount: 69
[Qt Message] "13:29:53.824" Ball::paint() ENTER
[Qt Message] "13:29:53.827" Ball::paint() EXIT
[Qt Message] "13:29:53.838" Scene::event() ENTER
[Qt Message] "13:29:53.840" Scene::event() - touchCount: 2
[Qt Message] "13:29:53.842" Scene::event() EXIT - touch event processed
[Qt Message] "13:29:53.846" Scene::event() ENTER
[Qt Message] "13:29:53.848" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.851" Scene::event() ENTER
[Qt Message] "13:29:53.852" Scene::event() - touchCount: 3
[Qt Message] "13:29:53.854" Scene::event() EXIT - touch event processed
[Qt Message] "13:29:53.855" Scene::event() ENTER
[Qt Message] "13:29:53.857" Scene::event() EXIT - NO touch event
[Qt Message] "13:29:53.858" Ball::advance() - ENTER
[Qt Message] "13:29:53.860" Ball::advance() - advanceCount: 69
[Qt Message] "13:29:53.862" Ball::advance() - EXITAs you can see from the traces, when no touch, the interval between 2 consecutive advance() calls is 30ms. After the first touch it raises to 49ms while touch 2 and 3 are processed.
Here is the processing inside the event() method:
@bool MyGraphicsScene::event(QEvent *event)
{
qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "Scene::event() ENTER";
switch (event->type()) {
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);if (touchEvent->touchPoints().count() == 1) { const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first(); QGraphicsItem *bat = items().at(4); qreal p = touchPoint1.scenePos().y(); qreal lp = touchPoint1.lastScenePos().y(); qreal dY = p - lp; bat->setPos(bat->pos().x(), bat->pos().y() + dY/4); } break; } default: qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "Scene::event() EXIT - NO touch event"; return QGraphicsScene::event(event); } touchCount++; qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "Scene::event() - touchCount: " << touchCount; qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "Scene::event() EXIT - touch event processed"; return true;
}@
-
I've moved the thread to the Mobile and Embedded forum, as the problem only occurs on the Symbian platform.