From dc0d6fe31d48e5d51c13ded97260a9f9c447ac2a Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 17 Jul 2022 23:59:35 +0400 Subject: [PATCH] Avoid code duplication --- components/resource/stats.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/components/resource/stats.cpp b/components/resource/stats.cpp index 863429d600..a204bf61f8 100644 --- a/components/resource/stats.cpp +++ b/components/resource/stats.cpp @@ -104,6 +104,17 @@ private: osgText::Font* mFont; }; +osg::ref_ptr getMonoFont(VFS::Manager* vfs) +{ + if (osgDB::Registry::instance()->getReaderWriterForExtension("ttf") && vfs->exists(sFontName)) + { + Files::IStreamPtr streamPtr = vfs->get(sFontName); + return osgText::readRefFontStream(*streamPtr.get()); + } + + return nullptr; +} + StatsHandler::StatsHandler(bool offlineCollect, VFS::Manager* vfs): _key(osgGA::GUIEventAdapter::KEY_F4), _initialized(false), @@ -120,11 +131,7 @@ StatsHandler::StatsHandler(bool offlineCollect, VFS::Manager* vfs): _resourceStatsChildNum = 0; - if (osgDB::Registry::instance()->getReaderWriterForExtension("ttf") && vfs->exists(sFontName)) - { - Files::IStreamPtr streamPtr = vfs->get(sFontName); - _textFont = osgText::readRefFontStream(*streamPtr.get()); - } + _textFont = getMonoFont(vfs); } Profiler::Profiler(bool offlineCollect, VFS::Manager* vfs): @@ -134,11 +141,7 @@ Profiler::Profiler(bool offlineCollect, VFS::Manager* vfs): _characterSize = 18; _font.clear(); - if (osgDB::Registry::instance()->getReaderWriterForExtension("ttf") && vfs->exists(sFontName)) - { - Files::IStreamPtr streamPtr = vfs->get(sFontName); - _textFont = osgText::readRefFontStream(*streamPtr.get()); - } + _textFont = getMonoFont(vfs); setKeyEventTogglesOnScreenStats(osgGA::GUIEventAdapter::KEY_F3); setupStatCollection();