Merge pull request #6283 from hyperlogic/tony/one-update-for-every-render

Remove idleTimer and call idle directly from paintGL.
This commit is contained in:
Brad Hefta-Gaub 2015-11-03 16:38:43 -08:00
commit 71e4092276
2 changed files with 31 additions and 24 deletions

View file

@ -159,8 +159,7 @@ static QTimer locationUpdateTimer;
static QTimer balanceUpdateTimer;
static QTimer identityPacketTimer;
static QTimer billboardPacketTimer;
static QTimer checkFPStimer;
static QTimer idleTimer;
static QTimer pingTimer;
static const QString SNAPSHOT_EXTENSION = ".jpg";
static const QString SVO_EXTENSION = ".svo";
@ -184,9 +183,7 @@ static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS
static const QString INFO_HELP_PATH = "html/interface-welcome.html";
static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html";
static const unsigned int TARGET_SIM_FRAMERATE = 60;
static const unsigned int THROTTLED_SIM_FRAMERATE = 15;
static const int TARGET_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / TARGET_SIM_FRAMERATE;
static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE;
#ifndef __APPLE__
@ -843,8 +840,7 @@ void Application::cleanupBeforeQuit() {
balanceUpdateTimer.stop();
identityPacketTimer.stop();
billboardPacketTimer.stop();
checkFPStimer.stop();
idleTimer.stop();
pingTimer.stop();
QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection);
// save state
@ -979,12 +975,9 @@ void Application::initializeGL() {
_entityEditSender.initialize(_enableProcessOctreeThread);
// call our timer function every second
connect(&checkFPStimer, &QTimer::timeout, this, &Application::checkFPS);
checkFPStimer.start(1000);
connect(&pingTimer, &QTimer::timeout, this, &Application::ping);
pingTimer.start(1000);
// call our idle function whenever we can
connect(&idleTimer, &QTimer::timeout, this, &Application::idle);
idleTimer.start(TARGET_SIM_FRAME_PERIOD_MS);
_idleLoopStdev.reset();
// update before the first render
@ -1048,6 +1041,26 @@ void Application::initializeUi() {
}
void Application::paintGL() {
_frameCount++;
// update fps moving average
uint64_t now = usecTimestampNow();
static uint64_t lastPaintBegin{ now };
uint64_t diff = now - lastPaintBegin;
if (diff != 0) {
_framesPerSecond.updateAverage((float)USECS_PER_SECOND / (float)diff);
}
lastPaintBegin = now;
// update fps once a second
if (now - _lastFramesPerSecondUpdate > USECS_PER_SECOND) {
_fps = _framesPerSecond.getAverage();
_lastFramesPerSecondUpdate = now;
}
idle(now);
PROFILE_RANGE(__FUNCTION__);
PerformanceTimer perfTimer("paintGL");
@ -1314,7 +1327,6 @@ void Application::paintGL() {
{
PerformanceTimer perfTimer("makeCurrent");
_offscreenContext->makeCurrent();
_frameCount++;
Stats::getInstance()->setRenderDetails(renderArgs._details);
// Reset the gpu::Context Stages
@ -2087,20 +2099,14 @@ bool Application::acceptSnapshot(const QString& urlString) {
return true;
}
// Every second, check the frame rates and other stuff
void Application::checkFPS() {
// Every second, send a ping, if menu item is checked.
void Application::ping() {
if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) {
DependencyManager::get<NodeList>()->sendPingPackets();
}
float diffTime = (float)_timerStart.nsecsElapsed() / 1000000000.0f;
_fps = (float)_frameCount / diffTime;
_frameCount = 0;
_timerStart.start();
}
void Application::idle() {
void Application::idle(uint64_t now) {
if (_aboutToQuit) {
return; // bail early, nothing to do here.
}
@ -2123,7 +2129,6 @@ void Application::idle() {
{
PROFILE_RANGE(__FUNCTION__);
uint64_t now = usecTimestampNow();
static uint64_t lastIdleStart{ now };
uint64_t idleStartToStartDuration = now - lastIdleStart;
if (idleStartToStartDuration != 0) {

View file

@ -306,8 +306,8 @@ public slots:
private slots:
void clearDomainOctreeDetails();
void checkFPS();
void idle();
void ping();
void idle(uint64_t now);
void aboutToQuit();
void handleScriptEngineLoaded(const QString& scriptFilename);
@ -541,6 +541,8 @@ private:
EntityItemID _keyboardFocusedItem;
quint64 _lastAcceptedKeyPress = 0;
SimpleMovingAverage _framesPerSecond{10};
quint64 _lastFramesPerSecondUpdate = 0;
SimpleMovingAverage _simsPerSecond{10};
int _simsPerSecondReport = 0;
quint64 _lastSimsPerSecondUpdate = 0;