Hi friends!
I think I found a way. just a WHILE(1) and use qApp->processEvents() to avoid a blocked UI. This code is executed when PLAY is pressed. There are no timers.
// simulate it for 10 seconds
m_rendered_frames=0;
m_time.start();
while (m_time.elapsed()<=10000) {
now.start();
qApp->processEvents();
m_current_level->Update(0);
m_gl_drawer->updateGL();
m_rendered_frames++;
// sleep a while
if (SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed()>0) {
QTest::qSleep(SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed());
}
}
// info
float fps=m_rendered_frames/10.0;
QString m
=QString("FPS: %1. rendered frames: %2. Timer interval (ms): %3.").
arg(fps
).
arg(m_rendered_frames
).
arg(SIMULATION_UPDATE_INTERVAL_IN_MS
);
// simulate it for 10 seconds
m_rendered_frames=0;
m_time.start();
while (m_time.elapsed()<=10000) {
QTime now;
now.start();
qApp->processEvents();
m_current_level->Update(0);
m_gl_drawer->updateGL();
m_rendered_frames++;
// sleep a while
if (SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed()>0) {
QTest::qSleep(SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed());
}
}
// info
float fps=m_rendered_frames/10.0;
QString m=QString("FPS: %1. rendered frames: %2. Timer interval (ms): %3.").arg(fps).arg(m_rendered_frames).arg(SIMULATION_UPDATE_INTERVAL_IN_MS);
QMessageBox::warning(this, "Warning", m);
To copy to clipboard, switch view to plain text mode
It works properly. What do you think?
Bookmarks