Expose Rates to JS/QML

This commit is contained in:
Zach Pomerantz 2016-04-18 17:26:29 -07:00
parent 6d7f8f4a6f
commit f48541961d
2 changed files with 29 additions and 0 deletions

View file

@ -508,6 +508,26 @@ Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context);
Setting::Handle<int> 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<Preferences>().data());
rootContext->setContextProperty("AddressManager", DependencyManager::get<AddressManager>().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<CompositorHelper>();
}
#include "Application.moc"

View file

@ -399,6 +399,7 @@ private:
uint32_t _frameCount { 0 };
// Frame Rate Measurement
QObject* _rates;
RateCounter<> _frameCounter;
RateCounter<> _avatarSimCounter;
RateCounter<> _simCounter;