From 2c78d530a273e20e3e8e57e53145caaabe25f2c6 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 17 Mar 2019 19:45:54 +0300 Subject: [PATCH] Use static vector to store stat names --- components/resource/stats.cpp | 47 +++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/components/resource/stats.cpp b/components/resource/stats.cpp index 0a70d75ab..b23558e99 100644 --- a/components/resource/stats.cpp +++ b/components/resource/stats.cpp @@ -197,14 +197,14 @@ class ResourceStatsTextDrawCallback : public osg::Drawable::DrawCallback { public: ResourceStatsTextDrawCallback(osg::Stats* stats, const std::vector& statNames) - : _stats(stats) - , _statNames(statNames) + : mStats(stats) + , mStatNames(statNames) { } virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const { - if (!_stats) return; + if (!mStats) return; osgText::Text* text = (osgText::Text*)(drawable); @@ -218,14 +218,14 @@ public: unsigned int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber()-1; - for (std::vector::const_iterator it = _statNames.begin(); it != _statNames.end(); ++it) + for (const auto& statName : mStatNames.get()) { - if (it->empty()) + if (statName.empty()) viewStr << std::endl; else { double value = 0.0; - if (_stats->getAttribute(frameNumber, *it, value)) + if (mStats->getAttribute(frameNumber, statName, value)) viewStr << std::setw(8) << value << std::endl; else viewStr << std::setw(8) << "." << std::endl; @@ -237,8 +237,8 @@ public: text->drawImplementation(renderInfo); } - osg::ref_ptr _stats; - std::vector _statNames; + osg::ref_ptr mStats; + std::reference_wrapper> mStatNames; }; void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer) @@ -269,9 +269,30 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer) _resourceStatsChildNum = _switch->getNumChildren(); _switch->addChild(group, false); - const char* statNames[] = {"Compiling", "WorkQueue", "WorkThread", "", "Texture", "StateSet", "Node", "Node Instance", "Shape", "Shape Instance", "Image", "Nif", "Keyframe", "", "Terrain Chunk", "Terrain Texture", "Land", "Composite", "", "UnrefQueue"}; + static const std::vector statNames({ + "Compiling", + "WorkQueue", + "WorkThread", + "", + "Texture", + "StateSet", + "Node", + "Node Instance", + "Shape", + "Shape Instance", + "Image", + "Nif", + "Keyframe", + "", + "Terrain Chunk", + "Terrain Texture", + "Land", + "Composite", + "", + "UnrefQueue", + }); - int numLines = sizeof(statNames) / sizeof(statNames[0]); + const int numLines = statNames.size(); group->addChild(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, _characterSize + backgroundMargin, 0), 10 * _characterSize + 2 * backgroundMargin, @@ -289,9 +310,9 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer) viewStr.clear(); viewStr.setf(std::ios::left, std::ios::adjustfield); viewStr.width(14); - for (size_t i = 0; isetText(viewStr.str()); @@ -311,7 +332,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer) statsText->setCharacterSize(_characterSize); statsText->setPosition(pos); statsText->setText(""); - statsText->setDrawCallback(new ResourceStatsTextDrawCallback(viewer->getViewerStats(), std::vector(statNames, statNames + numLines))); + statsText->setDrawCallback(new ResourceStatsTextDrawCallback(viewer->getViewerStats(), statNames)); } }