mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 19:45:40 +00:00
Rework Profiler to work with VFS
This commit is contained in:
parent
59c4ea014d
commit
d83382d236
2 changed files with 60 additions and 15 deletions
|
@ -84,6 +84,26 @@ static void setupStatCollection()
|
|||
}
|
||||
}
|
||||
|
||||
class SetFontVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
SetFontVisitor(osgText::Font* font)
|
||||
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
||||
, mFont(font)
|
||||
{}
|
||||
|
||||
void apply(osg::Drawable& node) override
|
||||
{
|
||||
if (osgText::Text* text = dynamic_cast<osgText::Text*>(&node))
|
||||
{
|
||||
text->setFont(mFont);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
osgText::Font* mFont;
|
||||
};
|
||||
|
||||
StatsHandler::StatsHandler(bool offlineCollect, VFS::Manager* vfs):
|
||||
_key(osgGA::GUIEventAdapter::KEY_F4),
|
||||
_initialized(false),
|
||||
|
@ -91,8 +111,7 @@ StatsHandler::StatsHandler(bool offlineCollect, VFS::Manager* vfs):
|
|||
_offlineCollect(offlineCollect),
|
||||
_statsWidth(1280.0f),
|
||||
_statsHeight(1024.0f),
|
||||
_characterSize(18.0f),
|
||||
_VFS(vfs)
|
||||
_characterSize(18.0f)
|
||||
{
|
||||
_camera = new osg::Camera;
|
||||
_camera->getOrCreateStateSet()->setGlobalDefaults();
|
||||
|
@ -100,29 +119,49 @@ StatsHandler::StatsHandler(bool offlineCollect, VFS::Manager* vfs):
|
|||
_camera->setProjectionResizePolicy(osg::Camera::FIXED);
|
||||
|
||||
_resourceStatsChildNum = 0;
|
||||
|
||||
if (osgDB::Registry::instance()->getReaderWriterForExtension("ttf") && vfs->exists(sFontName))
|
||||
{
|
||||
Files::IStreamPtr streamPtr = vfs->get(sFontName);
|
||||
_textFont = osgText::readRefFontStream(*streamPtr.get());
|
||||
}
|
||||
}
|
||||
|
||||
Profiler::Profiler(bool offlineCollect, VFS::Manager* vfs):
|
||||
_offlineCollect(offlineCollect)
|
||||
_offlineCollect(offlineCollect),
|
||||
_initFonts(false)
|
||||
{
|
||||
_characterSize = 18;
|
||||
_font.clear();
|
||||
|
||||
if (osgDB::Registry::instance()->getReaderWriterForExtension("ttf") && vfs->exists(sFontName))
|
||||
{
|
||||
_font = vfs->getAbsoluteFileName(sFontName);
|
||||
Files::IStreamPtr streamPtr = vfs->get(sFontName);
|
||||
_textFont = osgText::readRefFontStream(*streamPtr.get());
|
||||
}
|
||||
else
|
||||
_font.clear();
|
||||
|
||||
_characterSize = 18;
|
||||
|
||||
setKeyEventTogglesOnScreenStats(osgGA::GUIEventAdapter::KEY_F3);
|
||||
setupStatCollection();
|
||||
}
|
||||
|
||||
void Profiler::setUpFonts()
|
||||
{
|
||||
if (_textFont != nullptr)
|
||||
{
|
||||
SetFontVisitor visitor(_textFont);
|
||||
_switch->accept(visitor);
|
||||
}
|
||||
|
||||
_initFonts = true;
|
||||
}
|
||||
|
||||
bool Profiler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
|
||||
{
|
||||
osgViewer::ViewerBase* viewer = nullptr;
|
||||
|
||||
bool handled = StatsHandler::handle(ea, aa);
|
||||
if (_initialized && !_initFonts)
|
||||
setUpFonts();
|
||||
|
||||
auto* view = dynamic_cast<osgViewer::View*>(&aa);
|
||||
if (view)
|
||||
|
@ -457,13 +496,10 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
|
|||
statsText->setText("");
|
||||
statsText->setDrawCallback(new ResourceStatsTextDrawCallback(viewer->getViewerStats(), statNames));
|
||||
|
||||
if (osgDB::Registry::instance()->getReaderWriterForExtension("ttf") && _VFS->exists(sFontName))
|
||||
if (_textFont)
|
||||
{
|
||||
Files::IStreamPtr streamPtr = _VFS->get(sFontName);
|
||||
osg::ref_ptr<osgText::Font> font = osgText::readRefFontStream(*streamPtr.get());
|
||||
|
||||
staticText->setFont(font);
|
||||
statsText->setFont(font);
|
||||
staticText->setFont(_textFont);
|
||||
statsText->setFont(_textFont);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,11 @@ namespace osg
|
|||
class Switch;
|
||||
}
|
||||
|
||||
namespace osgText
|
||||
{
|
||||
class Font;
|
||||
}
|
||||
|
||||
namespace VFS
|
||||
{
|
||||
class Manager;
|
||||
|
@ -27,7 +32,11 @@ namespace Resource
|
|||
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) override;
|
||||
|
||||
private:
|
||||
void setUpFonts();
|
||||
|
||||
bool _offlineCollect;
|
||||
bool _initFonts;
|
||||
osg::ref_ptr<osgText::Font> _textFont;
|
||||
};
|
||||
|
||||
class StatsHandler : public osgGA::GUIEventHandler
|
||||
|
@ -65,7 +74,7 @@ namespace Resource
|
|||
|
||||
int _resourceStatsChildNum;
|
||||
|
||||
VFS::Manager* _VFS;
|
||||
osg::ref_ptr<osgText::Font> _textFont;
|
||||
};
|
||||
|
||||
void CollectStatistics(osgViewer::ViewerBase* viewer);
|
||||
|
|
Loading…
Reference in a new issue