stg: Add flag to load only specific parts of the stg files.

The flags are meant to be used for fgelev and for an ai
module that will probably only need ground elevation queries
in those reagions where the aircraft simulated there will roll
that is on airports.
This commit is contained in:
Mathias Froehlich
2012-08-25 08:47:09 +02:00
parent 2129cf5aa6
commit 68dd50ecbc
+84 -51
View File
@@ -49,6 +49,24 @@
using namespace simgear; using namespace simgear;
/// Ok, this is a hack - we do not exactly know if it's an airport or not.
/// This feature might also vanish again later. This is currently to
/// support testing an external ai component that just loads the the airports
/// and supports ground queries on only these areas.
static bool isAirportBtg(const std::string& name)
{
if (name.size() < 8)
return false;
if (name.substr(4, 8) != ".btg")
return false;
for (unsigned i = 0; i < 4; ++i) {
if (name[i] < 'A' || 'Z' < name[i])
continue;
return true;
}
return false;
}
static SGBucket bucketIndexFromFileName(const std::string& fileName) static SGBucket bucketIndexFromFileName(const std::string& fileName)
{ {
// Extract the bucket from the filename // Extract the bucket from the filename
@@ -194,7 +212,12 @@ ReaderWriterSTG::readStgFile(const std::string& absoluteFileName,
sharedOptions->getDatabasePathList().push_back(path.str()); sharedOptions->getDatabasePathList().push_back(path.str());
std::string fg_root = options->getPluginStringData("SimGear::FG_ROOT"); std::string fg_root = options->getPluginStringData("SimGear::FG_ROOT");
sharedOptions->getDatabasePathList().push_back(fg_root); sharedOptions->getDatabasePathList().push_back(fg_root);
// do only load airport btg files.
bool onlyAirports = options->getPluginStringData("SimGear::FG_ONLY_AIRPORTS") == "ON";
// do only load terrain btg files
bool onlyTerrain = options->getPluginStringData("SimGear::FG_ONLY_TERRAIN") == "ON";
simgear::AirportSignBuilder signBuilder(staticOptions->getMaterialLib(), bucket.get_center()); simgear::AirportSignBuilder signBuilder(staticOptions->getMaterialLib(), bucket.get_center());
bool has_base = false; bool has_base = false;
@@ -221,23 +244,28 @@ ReaderWriterSTG::readStgFile(const std::string& absoluteFileName,
SG_LOG( SG_TERRAIN, SG_BULK, " " << token << " " << name ); SG_LOG( SG_TERRAIN, SG_BULK, " " << token << " " << name );
has_base = true; has_base = true;
node = osgDB::readRefNodeFile(path.str(),
staticOptions.get()); if (!onlyAirports || isAirportBtg(name)) {
node = osgDB::readRefNodeFile(path.str(),
staticOptions.get());
if (!node.valid()) { if (!node.valid()) {
SG_LOG( SG_TERRAIN, SG_ALERT, absoluteFileName SG_LOG( SG_TERRAIN, SG_ALERT, absoluteFileName
<< ": Failed to load OBJECT_BASE '" << ": Failed to load OBJECT_BASE '"
<< name << "'" ); << name << "'" );
}
} }
} else if ( token == "OBJECT" ) { } else if ( token == "OBJECT" ) {
node = osgDB::readRefNodeFile(path.str(), if (!onlyAirports || isAirportBtg(name)) {
staticOptions.get()); node = osgDB::readRefNodeFile(path.str(),
staticOptions.get());
if (!node.valid()) { if (!node.valid()) {
SG_LOG( SG_TERRAIN, SG_ALERT, absoluteFileName SG_LOG( SG_TERRAIN, SG_ALERT, absoluteFileName
<< ": Failed to load OBJECT '" << ": Failed to load OBJECT '"
<< name << "'" ); << name << "'" );
}
} }
} else { } else {
@@ -246,46 +274,50 @@ ReaderWriterSTG::readStgFile(const std::string& absoluteFileName,
// Always OK to load // Always OK to load
if ( token == "OBJECT_STATIC" ) { if ( token == "OBJECT_STATIC" ) {
osg::ref_ptr<SGReaderWriterOptions> opt; if (!onlyTerrain) {
opt = new SGReaderWriterOptions(*staticOptions); osg::ref_ptr<SGReaderWriterOptions> opt;
osg::ProxyNode* proxyNode = new osg::ProxyNode; opt = new SGReaderWriterOptions(*staticOptions);
proxyNode->setLoadingExternalReferenceMode(osg::ProxyNode::DEFER_LOADING_TO_DATABASE_PAGER); osg::ProxyNode* proxyNode = new osg::ProxyNode;
/// Hmm, the findDataFile should happen downstream proxyNode->setLoadingExternalReferenceMode(osg::ProxyNode::DEFER_LOADING_TO_DATABASE_PAGER);
std::string absName = osgDB::findDataFile(name, opt.get()); /// Hmm, the findDataFile should happen downstream
proxyNode->setFileName(0, absName); std::string absName = osgDB::findDataFile(name, opt.get());
if (SGPath(absName).lower_extension() == "ac") proxyNode->setFileName(0, absName);
{ if (SGPath(absName).lower_extension() == "ac")
proxyNode->setNodeMask( ~simgear::MODELLIGHT_BIT ); {
opt->setInstantiateEffects(true); proxyNode->setNodeMask( ~simgear::MODELLIGHT_BIT );
} opt->setInstantiateEffects(true);
else }
opt->setInstantiateEffects(false); else
proxyNode->setDatabaseOptions(opt.get()); opt->setInstantiateEffects(false);
node = proxyNode; proxyNode->setDatabaseOptions(opt.get());
node = proxyNode;
if (!node.valid()) {
SG_LOG( SG_TERRAIN, SG_ALERT, absoluteFileName if (!node.valid()) {
<< ": Failed to load OBJECT_STATIC '" SG_LOG( SG_TERRAIN, SG_ALERT, absoluteFileName
<< name << "'" ); << ": Failed to load OBJECT_STATIC '"
<< name << "'" );
}
} }
} else if ( token == "OBJECT_SHARED" ) { } else if ( token == "OBJECT_SHARED" ) {
osg::ref_ptr<SGReaderWriterOptions> opt; if (!onlyTerrain) {
opt = new SGReaderWriterOptions(*sharedOptions); osg::ref_ptr<SGReaderWriterOptions> opt;
/// Hmm, the findDataFile should happen in the downstream readers opt = new SGReaderWriterOptions(*sharedOptions);
std::string absName = osgDB::findDataFile(name, opt.get()); /// Hmm, the findDataFile should happen in the downstream readers
if (SGPath(absName).lower_extension() == "ac") std::string absName = osgDB::findDataFile(name, opt.get());
opt->setInstantiateEffects(true); if (SGPath(absName).lower_extension() == "ac")
else opt->setInstantiateEffects(true);
opt->setInstantiateEffects(false); else
node = osgDB::readRefNodeFile(absName, opt.get()); opt->setInstantiateEffects(false);
if (SGPath(absName).lower_extension() == "ac") node = osgDB::readRefNodeFile(absName, opt.get());
node->setNodeMask( ~simgear::MODELLIGHT_BIT ); if (SGPath(absName).lower_extension() == "ac")
node->setNodeMask( ~simgear::MODELLIGHT_BIT );
if (!node.valid()) {
SG_LOG( SG_TERRAIN, SG_ALERT, absoluteFileName if (!node.valid()) {
<< ": Failed to load OBJECT_SHARED '" SG_LOG( SG_TERRAIN, SG_ALERT, absoluteFileName
<< name << "'" ); << ": Failed to load OBJECT_SHARED '"
<< name << "'" );
}
} }
} else if ( token == "OBJECT_SIGN" ) { } else if ( token == "OBJECT_SIGN" ) {
@@ -294,7 +326,8 @@ ReaderWriterSTG::readStgFile(const std::string& absoluteFileName,
if ( hasOptionalValue(in) ){ if ( hasOptionalValue(in) ){
in >> size; in >> size;
} }
signBuilder.addSign(SGGeod::fromDegM(lon, lat, elev), hdg, name, size); if (!onlyTerrain)
signBuilder.addSign(SGGeod::fromDegM(lon, lat, elev), hdg, name, size);
} else { } else {
SG_LOG( SG_TERRAIN, SG_ALERT, absoluteFileName SG_LOG( SG_TERRAIN, SG_ALERT, absoluteFileName
<< ": Unknown token '" << token << "'" ); << ": Unknown token '" << token << "'" );