From a760730285f57b4e6dae28ca16f77639539e094e Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Fri, 8 Oct 2021 20:55:06 +0100 Subject: [PATCH] WS30: +50% fps by not loading tiles every loader Previously the STG Loader had a class member keeping track of each WS30 tile that had been loaded, to ensure the terrain was only loaded once. However, this was a class member on a loader, and we have multiple OSG loading threads. So the WS30 terrain was loaded ~6 times. Change to a static, protected with a mutex so we only load the tile once. 50% improvement in fps from the reduction in vertices, and an improvement in loading. --- simgear/scene/tgdb/ReaderWriterSTG.cxx | 30 +++++++++++++++----------- simgear/scene/tgdb/ReaderWriterSTG.hxx | 5 +++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/simgear/scene/tgdb/ReaderWriterSTG.cxx b/simgear/scene/tgdb/ReaderWriterSTG.cxx index 82a69d27..75ca6a30 100644 --- a/simgear/scene/tgdb/ReaderWriterSTG.cxx +++ b/simgear/scene/tgdb/ReaderWriterSTG.cxx @@ -762,8 +762,6 @@ struct ReaderWriterSTG::_ModelBin { return true; } - std::map > tile_map; - osg::Node* load(const SGBucket& bucket, const osgDB::Options* opt) { osg::ref_ptr options; @@ -822,18 +820,24 @@ struct ReaderWriterSTG::_ModelBin { } std::string filename = "vpb/" + bucket.gen_vpb_base() + ".osgb"; - if (tile_map.count(filename) == 0) { - vpb_node = osgDB::readRefNodeFile(filename, options); - if (!vpb_node.valid()) { - SG_LOG(SG_TERRAIN, SG_WARN, "Failure to load: " < lock(ReaderWriterSTG::_tileMapMutex); + + if (_tileMap.count(filename) == 0) { + vpb_node = osgDB::readRefNodeFile(filename, options); + if (!vpb_node.valid()) { + SG_LOG(SG_TERRAIN, SG_WARN, "Failure to load: " <addChild(vpb_node); + _tileMap[filename] = vpb_node; + SG_LOG(SG_TERRAIN, SG_INFO, "Loading: " << filename); + } + } else { + vpb_node = _tileMap[filename]; } - else { - terrainGroup->addChild(vpb_node); - tile_map[filename] = vpb_node; - SG_LOG(SG_TERRAIN, SG_INFO, "Loading: " << filename); - } - } else { - vpb_node = tile_map[filename]; } // OBJECTs include airports diff --git a/simgear/scene/tgdb/ReaderWriterSTG.hxx b/simgear/scene/tgdb/ReaderWriterSTG.hxx index 74b6c77b..9fa1354d 100644 --- a/simgear/scene/tgdb/ReaderWriterSTG.hxx +++ b/simgear/scene/tgdb/ReaderWriterSTG.hxx @@ -23,6 +23,7 @@ #define _READERWRITERSTG_HXX #include +#include #include #include @@ -49,6 +50,10 @@ public: static void removeSTGObjectHandler(const std::string &token, STGObjectCallback callback); private: struct _ModelBin; + + inline static std::map > _tileMap; + inline static std::mutex _tileMapMutex; // protects the _lineFeatureLists; + }; }