From f48541961d461cc8eca524f18e1228c778de23d5 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 18 Apr 2016 17:26:29 -0700 Subject: [PATCH] Expose Rates to JS/QML --- interface/src/Application.cpp | 28 ++++++++++++++++++++++++++++ interface/src/Application.h | 1 + 2 files changed, 29 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 41eb7a305d..5383d130ab 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -508,6 +508,26 @@ Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context); Setting::Handle sessionRunTime{ "sessionRunTime", 0 }; +class Rates : public QObject { + Q_OBJECT + + Q_PROPERTY(float render READ getRenderRate) + Q_PROPERTY(float present READ getPresentRate) + Q_PROPERTY(float newFrame READ getNewFrameRate) + Q_PROPERTY(float dropped READ getDropRate) + Q_PROPERTY(float simulation READ getSimulationRate) + Q_PROPERTY(float avatar READ getAvatarRate) + +public: + Rates(QObject* parent) : QObject(parent) {} + float getRenderRate() { return qApp->getFps(); } + float getPresentRate() { return qApp->getActiveDisplayPlugin()->presentRate(); } + float getNewFrameRate() { return qApp->getActiveDisplayPlugin()->newFramePresentRate(); } + float getDropRate() { return qApp->getActiveDisplayPlugin()->droppedFrameRate(); } + float getSimulationRate() { return qApp->getAverageSimsPerSecond(); } + float getAvatarRate() { return qApp->getAvatarSimrate(); } +}; + Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : QApplication(argc, argv), _window(new MainWindow(desktop())), @@ -531,6 +551,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : _notifiedPacketVersionMismatchThisDomain(false), _maxOctreePPS(maxOctreePacketsPerSecond.get()), _lastFaceTrackerUpdate(0) + { // FIXME this may be excessively conservative. On the other hand // maybe I'm used to having an 8-core machine @@ -766,6 +787,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : ResourceCache::setRequestLimit(3); + _rates = new Rates(this); + _glWidget = new GLCanvas(); getApplicationCompositor().setRenderingWidget(_glWidget); _window->setCentralWidget(_glWidget); @@ -1390,6 +1413,7 @@ void Application::initializeUi() { rootContext->setContextProperty("Preferences", DependencyManager::get().data()); rootContext->setContextProperty("AddressManager", DependencyManager::get().data()); rootContext->setContextProperty("FrameTimings", &_frameTimingsScriptingInterface); + rootContext->setContextProperty("Rates", _rates); rootContext->setContextProperty("TREE_SCALE", TREE_SCALE); rootContext->setContextProperty("Quat", new Quat()); @@ -4443,6 +4467,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri // AvatarManager has some custom types AvatarManager::registerMetaTypes(scriptEngine); + scriptEngine->registerGlobalObject("Rates", _rates); + // hook our avatar and avatar hash map object into this script engine scriptEngine->registerGlobalObject("MyAvatar", getMyAvatar()); qScriptRegisterMetaType(scriptEngine, audioListenModeToScriptValue, audioListenModeFromScriptValue); @@ -5270,3 +5296,5 @@ void Application::showDesktop() { CompositorHelper& Application::getApplicationCompositor() const { return *DependencyManager::get(); } + +#include "Application.moc" diff --git a/interface/src/Application.h b/interface/src/Application.h index 6bfad21525..78424d0f57 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -399,6 +399,7 @@ private: uint32_t _frameCount { 0 }; // Frame Rate Measurement + QObject* _rates; RateCounter<> _frameCounter; RateCounter<> _avatarSimCounter; RateCounter<> _simCounter;