[Moved] Timer used to repaint (advance) delayed by event flood processing
-
peppe, I think if all work about ball and about bat moving will be moved away from main thread (i.e. we will have only painting and catching events, all calculations will be done in background) then it will help.
-
How can it help if the main thread's event loop is flooded by those mouse/touch events? Even supposing that you can pick the data from the main thread, do your math in 1 millionth of a second, and schedule an update() for your item, the QPaintEvent for the QGV will be sitting in the main thread's event queue and will actually be delivered after 1-2s (according to OP).
-
peppe, according to OP timer events are invoked once in 1-2 seconds.
-
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 author="Denis Kormalev" date="1293486729"]peppe, according to OP timer events are invoked once in 1-2 seconds.[/quote]
Instead of the desidered 30 updates per second.
[quote]“background” thread does all the ball calculations and sends a signal to the main thread which in turn does the graphics update.[/quote]
Again, HOW does the main thread update the view if the main event loop is flooded by input events?
-
Volker, exactly what I am saying :) Also I think not only ball, but bat calculations can be moved to background thread too.
-
I did not say, it solves the problem. I did say, it is possible to do it this way without violating the gui-update-only-in-main-thread rule.
-
[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.