Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Moved] Timer used to repaint (advance) delayed by event flood processing
Forum Updated to NodeBB v4.3 + New Features

[Moved] Timer used to repaint (advance) delayed by event flood processing

Scheduled Pinned Locked Moved Mobile and Embedded
46 Posts 7 Posters 26.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DenisKormalev
    wrote on last edited by
    #9

    peppe, according to OP timer events are invoked once in 1-2 seconds.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #10

      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.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #11

        [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?

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #12

          Volker, exactly what I am saying :) Also I think not only ball, but bat calculations can be moved to background thread too.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #13

            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.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dflorin
              wrote on last edited by
              #14

              [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.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DenisKormalev
                wrote on last edited by
                #15

                peppe, at least OP can try it and maybe it will solve the problem.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dangelog
                  wrote on last edited by
                  #16

                  Wtf? Is this some kind of SERIOUS help or just "try this random thing"?

                  Software Engineer
                  KDAB (UK) Ltd., a KDAB Group company

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DenisKormalev
                    wrote on last edited by
                    #17

                    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.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dangelog
                      wrote on last edited by
                      #18

                      [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.

                      Software Engineer
                      KDAB (UK) Ltd., a KDAB Group company

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        DenisKormalev
                        wrote on last edited by
                        #19

                        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.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dflorin
                          wrote on last edited by
                          #20

                          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?

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            DenisKormalev
                            wrote on last edited by
                            #21

                            dflorin, looking at this measurement I think it is worth to try moving ball coordinates calculation into another thread.

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              dflorin
                              wrote on last edited by
                              #22

                              [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.

                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                DenisKormalev
                                wrote on last edited by
                                #23

                                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.

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  dflorin
                                  wrote on last edited by
                                  #24

                                  Ok, thanks. I will try that and get back with the result.

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    giesbert
                                    wrote on last edited by
                                    #25

                                    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.

                                    Nokia Certified Qt Specialist.
                                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      goetz
                                      wrote on last edited by
                                      #26

                                      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-qt

                                      I 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.

                                      http://www.catb.org/~esr/faqs/smart-questions.html

                                      1 Reply Last reply
                                      0
                                      • D Offline
                                        D Offline
                                        DenisKormalev
                                        wrote on last edited by
                                        #27

                                        Gerolf is right, full repaint is an overhead. Maybe you can try to make partial repaints (where it is needed)?

                                        1 Reply Last reply
                                        0
                                        • D Offline
                                          D Offline
                                          dangelog
                                          wrote on last edited by
                                          #28

                                          [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 :-)

                                          Software Engineer
                                          KDAB (UK) Ltd., a KDAB Group company

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved