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.
This commit is contained in:
Stuart Buchanan 2021-10-08 20:55:06 +01:00
parent f7e378a05a
commit a760730285
2 changed files with 22 additions and 13 deletions

View File

@ -762,8 +762,6 @@ struct ReaderWriterSTG::_ModelBin {
return true;
}
std::map<std::string, osg::ref_ptr<osg::Node> > tile_map;
osg::Node* load(const SGBucket& bucket, const osgDB::Options* opt)
{
osg::ref_ptr<SGReaderWriterOptions> 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: " <<filename);
// Lock for this scope
{
const std::lock_guard<std::mutex> 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: " <<filename);
}
else {
terrainGroup->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

View File

@ -23,6 +23,7 @@
#define _READERWRITERSTG_HXX
#include <functional>
#include <mutex>
#include <osgDB/ReaderWriter>
#include <simgear/math/sg_types.hxx>
@ -49,6 +50,10 @@ public:
static void removeSTGObjectHandler(const std::string &token, STGObjectCallback callback);
private:
struct _ModelBin;
inline static std::map<std::string, osg::ref_ptr<osg::Node> > _tileMap;
inline static std::mutex _tileMapMutex; // protects the _lineFeatureLists;
};
}