mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-01 10:09:48 +00:00
Use static vector to store stat names
This commit is contained in:
parent
ab69ad65ed
commit
2c78d530a2
1 changed files with 34 additions and 13 deletions
|
@ -197,14 +197,14 @@ class ResourceStatsTextDrawCallback : public osg::Drawable::DrawCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ResourceStatsTextDrawCallback(osg::Stats* stats, const std::vector<std::string>& statNames)
|
ResourceStatsTextDrawCallback(osg::Stats* stats, const std::vector<std::string>& statNames)
|
||||||
: _stats(stats)
|
: mStats(stats)
|
||||||
, _statNames(statNames)
|
, mStatNames(statNames)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const
|
virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const
|
||||||
{
|
{
|
||||||
if (!_stats) return;
|
if (!mStats) return;
|
||||||
|
|
||||||
osgText::Text* text = (osgText::Text*)(drawable);
|
osgText::Text* text = (osgText::Text*)(drawable);
|
||||||
|
|
||||||
|
@ -218,14 +218,14 @@ public:
|
||||||
|
|
||||||
unsigned int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber()-1;
|
unsigned int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber()-1;
|
||||||
|
|
||||||
for (std::vector<std::string>::const_iterator it = _statNames.begin(); it != _statNames.end(); ++it)
|
for (const auto& statName : mStatNames.get())
|
||||||
{
|
{
|
||||||
if (it->empty())
|
if (statName.empty())
|
||||||
viewStr << std::endl;
|
viewStr << std::endl;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double value = 0.0;
|
double value = 0.0;
|
||||||
if (_stats->getAttribute(frameNumber, *it, value))
|
if (mStats->getAttribute(frameNumber, statName, value))
|
||||||
viewStr << std::setw(8) << value << std::endl;
|
viewStr << std::setw(8) << value << std::endl;
|
||||||
else
|
else
|
||||||
viewStr << std::setw(8) << "." << std::endl;
|
viewStr << std::setw(8) << "." << std::endl;
|
||||||
|
@ -237,8 +237,8 @@ public:
|
||||||
text->drawImplementation(renderInfo);
|
text->drawImplementation(renderInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<osg::Stats> _stats;
|
osg::ref_ptr<osg::Stats> mStats;
|
||||||
std::vector<std::string> _statNames;
|
std::reference_wrapper<const std::vector<std::string>> mStatNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
|
void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
|
||||||
|
@ -269,9 +269,30 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
|
||||||
_resourceStatsChildNum = _switch->getNumChildren();
|
_resourceStatsChildNum = _switch->getNumChildren();
|
||||||
_switch->addChild(group, false);
|
_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<std::string> 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),
|
group->addChild(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, _characterSize + backgroundMargin, 0),
|
||||||
10 * _characterSize + 2 * backgroundMargin,
|
10 * _characterSize + 2 * backgroundMargin,
|
||||||
|
@ -289,9 +310,9 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
|
||||||
viewStr.clear();
|
viewStr.clear();
|
||||||
viewStr.setf(std::ios::left, std::ios::adjustfield);
|
viewStr.setf(std::ios::left, std::ios::adjustfield);
|
||||||
viewStr.width(14);
|
viewStr.width(14);
|
||||||
for (size_t i = 0; i<sizeof(statNames)/sizeof(statNames[0]); ++i)
|
for (const auto& statName : statNames)
|
||||||
{
|
{
|
||||||
viewStr << statNames[i] << std::endl;
|
viewStr << statName << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
staticText->setText(viewStr.str());
|
staticText->setText(viewStr.str());
|
||||||
|
@ -311,7 +332,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
|
||||||
statsText->setCharacterSize(_characterSize);
|
statsText->setCharacterSize(_characterSize);
|
||||||
statsText->setPosition(pos);
|
statsText->setPosition(pos);
|
||||||
statsText->setText("");
|
statsText->setText("");
|
||||||
statsText->setDrawCallback(new ResourceStatsTextDrawCallback(viewer->getViewerStats(), std::vector<std::string>(statNames, statNames + numLines)));
|
statsText->setDrawCallback(new ResourceStatsTextDrawCallback(viewer->getViewerStats(), statNames));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue