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:
parent
f7e378a05a
commit
a760730285
@ -762,8 +762,6 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, osg::ref_ptr<osg::Node> > tile_map;
|
|
||||||
|
|
||||||
osg::Node* load(const SGBucket& bucket, const osgDB::Options* opt)
|
osg::Node* load(const SGBucket& bucket, const osgDB::Options* opt)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<SGReaderWriterOptions> options;
|
osg::ref_ptr<SGReaderWriterOptions> options;
|
||||||
@ -822,18 +820,24 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string filename = "vpb/" + bucket.gen_vpb_base() + ".osgb";
|
std::string filename = "vpb/" + bucket.gen_vpb_base() + ".osgb";
|
||||||
if (tile_map.count(filename) == 0) {
|
|
||||||
vpb_node = osgDB::readRefNodeFile(filename, options);
|
// Lock for this scope
|
||||||
if (!vpb_node.valid()) {
|
{
|
||||||
SG_LOG(SG_TERRAIN, SG_WARN, "Failure to load: " <<filename);
|
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
|
// OBJECTs include airports
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#define _READERWRITERSTG_HXX
|
#define _READERWRITERSTG_HXX
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include <osgDB/ReaderWriter>
|
#include <osgDB/ReaderWriter>
|
||||||
#include <simgear/math/sg_types.hxx>
|
#include <simgear/math/sg_types.hxx>
|
||||||
@ -49,6 +50,10 @@ public:
|
|||||||
static void removeSTGObjectHandler(const std::string &token, STGObjectCallback callback);
|
static void removeSTGObjectHandler(const std::string &token, STGObjectCallback callback);
|
||||||
private:
|
private:
|
||||||
struct _ModelBin;
|
struct _ModelBin;
|
||||||
|
|
||||||
|
inline static std::map<std::string, osg::ref_ptr<osg::Node> > _tileMap;
|
||||||
|
inline static std::mutex _tileMapMutex; // protects the _lineFeatureLists;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user