Hi wysota.
After implementing an adaptative timer as you told to me, I get some good results but also a strange result.
3 Tests (3 times each one). 10 seconds every one:
Code:
void CEditor::TimerFired() {
if (m_time.elapsed()>10000) {
ChangeEditorState(EDITING);
} else {
now.start();
m_current_level->Update(0);
m_gl_drawer->updateGL();
m_rendered_frames++;
int next_shot;
if (SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed()<0) {
next_shot=0;
} else {
next_shot=SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed();
}
QTimer::singleShot(next_shot,
this,
SLOT(TimerFired
()));
}
}
// Start button
m_time.start();
m_rendered_frames=0;
QTimer::singleShot(0,
this,
SLOT(TimerFired
()));
// When ChangeEditorState(EDITING);
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
);
void CEditor::TimerFired() {
if (m_time.elapsed()>10000) {
ChangeEditorState(EDITING);
} else {
QTime now;
now.start();
m_current_level->Update(0);
m_gl_drawer->updateGL();
m_rendered_frames++;
int next_shot;
if (SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed()<0) {
next_shot=0;
} else {
next_shot=SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed();
}
QTimer::singleShot(next_shot, this, SLOT(TimerFired()));
}
}
// Start button
m_time.start();
m_rendered_frames=0;
QTimer::singleShot(0, this, SLOT(TimerFired()));
// When ChangeEditorState(EDITING);
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
Results under the same conditions (3 times each one, 9 tests):
If SIMULATION_UPDATE_INTERVAL_IN_MS=10. FPS: 92.7. Expected 100 FPS.
If SIMULATION_UPDATE_INTERVAL_IN_MS=20. FPS: 32. Expected 50 FPS.
If SIMULATION_UPDATE_INTERVAL_IN_MS=30. FPS: 32. Expected 33.3 FPS.
What is really strange is when SIMULATION_UPDATE_INTERVAL_IN_MS=20. I don't understand why I don't get 50 FPS.
Any idea? Is my adaptative timer implemented properly? Should I use high res windows timer and round its result or QTime is fine?
Thanks a lot, very helpful your help.
EDIT: I realised (SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed()<0) never happens, so I'm still more disconcerted about interval=20, and next_shot is usually 20, so my computer updates and render it ultra fast. My conclusion is that Qt is taking a lot of time for it. Does anyone know anything about this? Thanks.
Bookmarks