Results 1 to 13 of 13

Thread: Chrono

  1. #1
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Chrono

    Any idea why QTimer clashes with boost::chrono clock? When using both in the same function they cause undesired behavior such as locking part of the GUI making it not responsive or dead.

  2. #2
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Chrono

    I tried another timer, Intel TBB timer: tick_count::now() and the same is still there. Any idea about possible competing timer functions trying to access the same system resources/calls?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Chrono

    Hard to say without knowing how you use these classes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Chrono

    Qt Code:
    1. // Inside the main window class constructor
    2. ...
    3.  
    4. timer.setInterval(0);
    5.  
    6. connect(...)
    7.  
    8. t0 = tbb::tick_count::now();
    9.  
    10. ...
    11.  
    12. MyMainWindow::OnIdle()
    13. {
    14. t1 = tbb::tick_count::now();
    15. if ((t1 - t0).seconds() < ...) {
    16. // do nothing
    17. } else {
    18. // do something...
    19. }
    20. pApp->processEvents();
    21. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Chrono

    Is there any reason why you are using tbb::tick_count::now() instead of QDateTime, QTime or QElapsedTimer? Furthermore processing events from within the call to OnIdle() (which I assume is the result of the timer's timeout) doesn't make any sense since the events has just been processed. You might be falling into an endless loop here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Chrono

    Is there any reason why you are using tbb::tick_count::now() instead of QDateTime, QTime or QElapsedTimer?
    Good question since both are valid platform-portable solutions. The answer is framework portability. I'm intending to implement the entire game engine/logic as a decoupled module from the GUI/Qt framework so that I can just plug it into other frameworks more easily, such as SDL, Glut, or any other kits. I could just say: gameInstance->DoFrame(); from within OnIdle() function, which I assume in this case, works exactly like a idle event block in conventional win32 api non-blocking GetMessage even loop.

    Now my question, is there any strong argument why I should not use any other 3rd party libraries in Qt?

    Furthermore processing events from within the call to OnIdle() (which I assume is the result of the timer's timeout) doesn't make any sense since the events has just been processed.
    pApp->processEvents() was suggested by someone for solving the same issue, but it was a different thread.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Chrono

    Quote Originally Posted by qtoptus View Post
    Good question since both are valid platform-portable solutions. The answer is framework portability. I'm intending to implement the entire game engine/logic as a decoupled module from the GUI/Qt framework so that I can just plug it into other frameworks more easily, such as SDL, Glut, or any other kits. I could just say: gameInstance->DoFrame(); from within OnIdle() function, which I assume in this case, works exactly like a idle event block in conventional win32 api non-blocking GetMessage even loop.
    I don't think a game loop speed should depend on the number of idle calls of the machine. You should setup a proper timer with a predefined interval to get a constant iterations per second of the game loop. As for the timer itself, you can abstract it as well and have it implemented by the GUI framework.

    Now my question, is there any strong argument why I should not use any other 3rd party libraries in Qt?
    Right now I am trying to find the problem, not suggesting any permanent solutions. Try removing the boost call and see if it changes anything. There shouldn't be any clashes so first let's make sure this really is the problem.


    pApp->processEvents() was suggested by someone for solving the same issue, but it was a different thread.
    And obviously it didn't work

    How about you tell us what is the ultimate goal you are trying to achieve here and we suggest an approach for it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Chrono

    What I'm trying to achieve is simply a game loop. I could use a QTimer set to the desired frame rate. But I chosed to try existing approach I already use with Win32 API. I will post my code here so it can be tested:

    Qt Code:
    1. tbb::tick_count t0, t1;
    2.  
    3. MyGame2::MyGame2(QWidget *parent, Qt::WFlags flags)
    4. : QMainWindow(parent, flags)
    5. {
    6. ui.setupUi(this);
    7.  
    8. ui.textEditMainConsole->appendPlainText("Hello!");
    9. //ui.textEditMainConsole->setDisabled(true);
    10. //ui.textEditMainConsole->clear();
    11.  
    12. //hiResTimerStart = boost::chrono::steady_clock::now();
    13. t0 = tbb::tick_count::now();
    14.  
    15. timer.setInterval(0);
    16. timer.start();
    17.  
    18. connect(&timer, SIGNAL(timeout()), this, SLOT(OnIdle()));
    19. }
    20.  
    21. MyGame2::~MyGame2()
    22. {
    23. timer.stop();
    24. }
    25.  
    26. extern QApplication *pApp;
    27.  
    28. void MyGame2::OnIdle()
    29. {
    30. tbb::tick_count t1 = tbb::tick_count::now();
    31. float dt = (t1 - t0).seconds();
    32. //boost::chrono::steady_clock::time_point hiResTimerEnd = boost::chrono::steady_clock::now();
    33. //boost::chrono::microseconds msecs = boost::chrono::duration_cast<boost::chrono::microseconds>(hiResTimerEnd - hiResTimerStart);
    34.  
    35. //unsigned long p = 1000000/60;
    36. //unsigned long p = 1000000/85;
    37. //if (msecs.count() < p) {
    38. if (dt < 1.0f/60) {
    39.  
    40. } else {
    41. //============
    42.  
    43. std::stringstream ss;
    44. //ss << "~~~ dCount: " << msecs.count();
    45. ss << "~~~ dCount: " << dt;
    46. std::string s = ss.str();
    47.  
    48. //ui.textEditMainConsole->clear();
    49. //ui.textEditMainConsole->appendPlainText(s.c_str());
    50. ui.textEditMainConsole->setPlainText(s.c_str());
    51. //============
    52.  
    53. //hiResTimerStart = hiResTimerEnd;
    54. t0 = t1;
    55. }
    56.  
    57. pApp->processEvents();
    58. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Chrono

    Anybody tried this code and experienced the same problem? Any idea what the problem is?

    Thanks.

  10. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Chrono

    I have no idea what setting a timer interval to 0 will do, but since the docs say that it will cause the timer to fire immediately, this implies that the timer is choking the event loop with continuous timeout events. I think your assumption that a timeout slot for a timer with 0 interval is like a Windows idle loop might be a flawed assumption. Your OnIdle() slot isn't idling at all - it is constantly responding to timeout events.

  11. #11
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Chrono

    Well that's what they told me on this forum, that a substitution of Windows' on-idle would be a timer with interval set to 0.

    Anyway reading posts about timer, and after trying several approaches, I have suspicions that the QTimer has some issues in the current version. Hope they find it and fix it.

  12. #12
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Chrono

    Ok let me reword what I want to do. Simply a game loop using a 3rd party high frequency counter, such as Chrono or TBB's.

    QTimer is the only way I can do background work (as an idle event) but it does not really seem to like other counters...???

  13. #13
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Chrono

    Tried 4.8, did not solve the problem.

    Any thoughts on making a continuous rendering loop without using QTimer?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.