WS30 Move VPB tile loading to the tile manager

Previously VPB tiles were loaded by the STG file handler.
Now they are loaded directly by the tile manager, allowing
better management of tile loading.
This commit is contained in:
Stuart Buchanan 2021-10-20 23:37:59 +01:00
parent fc1d02110c
commit 7916dfb61d
3 changed files with 14 additions and 26 deletions

View File

@ -182,6 +182,20 @@ public:
return ((lon + 180) << 14) + ((lat + 90) << 6) + static_cast<unsigned char>(y << 3) + x; return ((lon + 180) << 14) + ((lat + 90) << 6) + static_cast<unsigned char>(y << 3) + x;
} }
/**
* Generate a tile index for this bucket shared with all other buckets with the same lat/lon.
* Used as an index for VPB tiles, which are 1x1 in size.
*
* The index is constructed as follows:
*
* 9 bits - to represent 360 degrees of longitude (-180 to 179)
* 8 bits - to represent 180 degrees of latitude (-90 to 89)
* @return tile index
*/
inline long int gen_vpb_index() const {
return ((lon + 180) << 8) + (lat + 90);
}
/** /**
* Generate the unique scenery tile index for this bucket in ascii * Generate the unique scenery tile index for this bucket in ascii
* string form. * string form.

View File

@ -765,7 +765,6 @@ struct ReaderWriterSTG::_ModelBin {
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;
osg::ref_ptr<osg::Node> vpb_node;
options = SGReaderWriterOptions::copyOrCreate(opt); options = SGReaderWriterOptions::copyOrCreate(opt);
float pagedLODExpiry = atoi(options->getPluginStringData("SimGear::PAGED_LOD_EXPIRY").c_str()); float pagedLODExpiry = atoi(options->getPluginStringData("SimGear::PAGED_LOD_EXPIRY").c_str());
@ -819,27 +818,6 @@ struct ReaderWriterSTG::_ModelBin {
VPBTechnique::addCoastlineList(bucket, coastFeatures); VPBTechnique::addCoastlineList(bucket, coastFeatures);
} }
std::string filename = "vpb/" + bucket.gen_vpb_base() + ".osgb";
// 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];
}
}
// OBJECTs include airports // OBJECTs include airports
for (auto stgObject : _objectList) { for (auto stgObject : _objectList) {
osg::ref_ptr<osg::Node> node; osg::ref_ptr<osg::Node> node;

View File

@ -50,10 +50,6 @@ 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;
}; };
} }