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):
|
StatsHandler::StatsHandler(bool offlineCollect, VFS::Manager* vfs):
|
||||||
_key(osgGA::GUIEventAdapter::KEY_F4),
|
_key(osgGA::GUIEventAdapter::KEY_F4),
|
||||||
_initialized(false),
|
_initialized(false),
|
||||||
|
@ -91,8 +111,7 @@ StatsHandler::StatsHandler(bool offlineCollect, VFS::Manager* vfs):
|
||||||
_offlineCollect(offlineCollect),
|
_offlineCollect(offlineCollect),
|
||||||
_statsWidth(1280.0f),
|
_statsWidth(1280.0f),
|
||||||
_statsHeight(1024.0f),
|
_statsHeight(1024.0f),
|
||||||
_characterSize(18.0f),
|
_characterSize(18.0f)
|
||||||
_VFS(vfs)
|
|
||||||
{
|
{
|
||||||
_camera = new osg::Camera;
|
_camera = new osg::Camera;
|
||||||
_camera->getOrCreateStateSet()->setGlobalDefaults();
|
_camera->getOrCreateStateSet()->setGlobalDefaults();
|
||||||
|
@ -100,29 +119,49 @@ StatsHandler::StatsHandler(bool offlineCollect, VFS::Manager* vfs):
|
||||||
_camera->setProjectionResizePolicy(osg::Camera::FIXED);
|
_camera->setProjectionResizePolicy(osg::Camera::FIXED);
|
||||||
|
|
||||||
_resourceStatsChildNum = 0;
|
_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):
|
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))
|
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);
|
setKeyEventTogglesOnScreenStats(osgGA::GUIEventAdapter::KEY_F3);
|
||||||
setupStatCollection();
|
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)
|
bool Profiler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
|
||||||
{
|
{
|
||||||
osgViewer::ViewerBase* viewer = nullptr;
|
osgViewer::ViewerBase* viewer = nullptr;
|
||||||
|
|
||||||
bool handled = StatsHandler::handle(ea, aa);
|
bool handled = StatsHandler::handle(ea, aa);
|
||||||
|
if (_initialized && !_initFonts)
|
||||||
|
setUpFonts();
|
||||||
|
|
||||||
auto* view = dynamic_cast<osgViewer::View*>(&aa);
|
auto* view = dynamic_cast<osgViewer::View*>(&aa);
|
||||||
if (view)
|
if (view)
|
||||||
|
@ -457,13 +496,10 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
|
||||||
statsText->setText("");
|
statsText->setText("");
|
||||||
statsText->setDrawCallback(new ResourceStatsTextDrawCallback(viewer->getViewerStats(), statNames));
|
statsText->setDrawCallback(new ResourceStatsTextDrawCallback(viewer->getViewerStats(), statNames));
|
||||||
|
|
||||||
if (osgDB::Registry::instance()->getReaderWriterForExtension("ttf") && _VFS->exists(sFontName))
|
if (_textFont)
|
||||||
{
|
{
|
||||||
Files::IStreamPtr streamPtr = _VFS->get(sFontName);
|
staticText->setFont(_textFont);
|
||||||
osg::ref_ptr<osgText::Font> font = osgText::readRefFontStream(*streamPtr.get());
|
statsText->setFont(_textFont);
|
||||||
|
|
||||||
staticText->setFont(font);
|
|
||||||
statsText->setFont(font);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,11 @@ namespace osg
|
||||||
class Switch;
|
class Switch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace osgText
|
||||||
|
{
|
||||||
|
class Font;
|
||||||
|
}
|
||||||
|
|
||||||
namespace VFS
|
namespace VFS
|
||||||
{
|
{
|
||||||
class Manager;
|
class Manager;
|
||||||
|
@ -27,7 +32,11 @@ namespace Resource
|
||||||
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) override;
|
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setUpFonts();
|
||||||
|
|
||||||
bool _offlineCollect;
|
bool _offlineCollect;
|
||||||
|
bool _initFonts;
|
||||||
|
osg::ref_ptr<osgText::Font> _textFont;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StatsHandler : public osgGA::GUIEventHandler
|
class StatsHandler : public osgGA::GUIEventHandler
|
||||||
|
@ -65,7 +74,7 @@ namespace Resource
|
||||||
|
|
||||||
int _resourceStatsChildNum;
|
int _resourceStatsChildNum;
|
||||||
|
|
||||||
VFS::Manager* _VFS;
|
osg::ref_ptr<osgText::Font> _textFont;
|
||||||
};
|
};
|
||||||
|
|
||||||
void CollectStatistics(osgViewer::ViewerBase* viewer);
|
void CollectStatistics(osgViewer::ViewerBase* viewer);
|
||||||
|
|
Loading…
Reference in a new issue