fgviewer: Update to current initialization structure.
Improove argument parsing. Reorder initialization.
This commit is contained in:
parent
1ddb658a70
commit
d2411199e8
1 changed files with 56 additions and 39 deletions
|
@ -41,8 +41,9 @@
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/scene/material/EffectCullVisitor.hxx>
|
#include <simgear/scene/material/EffectCullVisitor.hxx>
|
||||||
#include <simgear/scene/material/matlib.hxx>
|
#include <simgear/scene/material/matlib.hxx>
|
||||||
#include <simgear/scene/util/OsgMath.hxx>
|
|
||||||
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
|
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
|
||||||
|
#include <simgear/scene/util/SGSceneFeatures.hxx>
|
||||||
|
#include <simgear/scene/util/SGUpdateVisitor.hxx>
|
||||||
#include <simgear/scene/tgdb/userdata.hxx>
|
#include <simgear/scene/tgdb/userdata.hxx>
|
||||||
#include <simgear/scene/model/ModelRegistry.hxx>
|
#include <simgear/scene/model/ModelRegistry.hxx>
|
||||||
#include <simgear/scene/model/modellib.hxx>
|
#include <simgear/scene/model/modellib.hxx>
|
||||||
|
@ -50,14 +51,60 @@
|
||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
// use an ArgumentParser object to manage the program arguments.
|
||||||
|
osg::ArgumentParser arguments(&argc, argv);
|
||||||
|
|
||||||
|
std::string fg_root;
|
||||||
|
if (arguments.read("--fg-root", fg_root)) {
|
||||||
|
} else if (const char *fg_root_env = std::getenv("FG_ROOT")) {
|
||||||
|
fg_root = fg_root_env;
|
||||||
|
} else {
|
||||||
|
fg_root = PKGLIBDIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string fg_scenery;
|
||||||
|
if (arguments.read("--fg-scenery", fg_scenery)) {
|
||||||
|
} else if (const char *fg_scenery_env = std::getenv("FG_SCENERY")) {
|
||||||
|
fg_scenery = fg_scenery_env;
|
||||||
|
} else {
|
||||||
|
SGPath path(fg_root);
|
||||||
|
path.append("Scenery");
|
||||||
|
fg_scenery = path.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
SGSharedPtr<SGPropertyNode> props = new SGPropertyNode;
|
||||||
|
try {
|
||||||
|
SGPath preferencesFile = fg_root;
|
||||||
|
preferencesFile.append("preferences.xml");
|
||||||
|
readProperties(preferencesFile.str(), props);
|
||||||
|
} catch (...) {
|
||||||
|
// In case of an error, at least make summer :)
|
||||||
|
props->getNode("sim/startup/season", true)->setStringValue("summer");
|
||||||
|
|
||||||
|
std::cerr << "Problems loading FlightGear preferences.\n"
|
||||||
|
<< "Probably FG_ROOT is not properly set." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string config;
|
||||||
|
while (arguments.read("--config", config)) {
|
||||||
|
try {
|
||||||
|
readProperties(config, props);
|
||||||
|
} catch (...) {
|
||||||
|
std::cerr << "Problems loading config file \"" << config
|
||||||
|
<< "\" given on the command line." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string prop, value;
|
||||||
|
while (arguments.read("--prop", prop, value)) {
|
||||||
|
props->setStringValue(prop, value);
|
||||||
|
}
|
||||||
|
|
||||||
// Just reference simgears reader writer stuff so that the globals get
|
// Just reference simgears reader writer stuff so that the globals get
|
||||||
// pulled in by the linker ...
|
// pulled in by the linker ...
|
||||||
// FIXME: make that more explicit clear and call an initialization function
|
// FIXME: make that more explicit clear and call an initialization function
|
||||||
simgear::ModelRegistry::instance();
|
simgear::ModelRegistry::instance();
|
||||||
|
|
||||||
// use an ArgumentParser object to manage the program arguments.
|
|
||||||
osg::ArgumentParser arguments(&argc, argv);
|
|
||||||
|
|
||||||
// construct the viewer.
|
// construct the viewer.
|
||||||
osgViewer::Viewer viewer(arguments);
|
osgViewer::Viewer viewer(arguments);
|
||||||
|
|
||||||
|
@ -99,41 +146,8 @@ main(int argc, char** argv)
|
||||||
fog->setDensity(1e-6);
|
fog->setDensity(1e-6);
|
||||||
camera->getOrCreateStateSet()->setAttribute(fog);
|
camera->getOrCreateStateSet()->setAttribute(fog);
|
||||||
|
|
||||||
std::string fg_root;
|
|
||||||
if (arguments.read("--fg-root", fg_root)) {
|
|
||||||
} else if (const char *fg_root_env = std::getenv("FG_ROOT")) {
|
|
||||||
fg_root = fg_root_env;
|
|
||||||
} else {
|
|
||||||
#if defined(PKGLIBDIR)
|
|
||||||
fg_root = PKGLIBDIR;
|
|
||||||
#else
|
|
||||||
fg_root = ".";
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string fg_scenery;
|
|
||||||
if (arguments.read("--fg-scenery", fg_scenery)) {
|
|
||||||
} else if (const char *fg_scenery_env = std::getenv("FG_SCENERY")) {
|
|
||||||
fg_scenery = fg_scenery_env;
|
|
||||||
} else {
|
|
||||||
SGPath path(fg_root);
|
|
||||||
path.append("Scenery");
|
|
||||||
fg_scenery = path.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
SGSharedPtr<SGPropertyNode> props = new SGPropertyNode;
|
|
||||||
sgUserDataInit(props.get());
|
sgUserDataInit(props.get());
|
||||||
try {
|
SGSceneFeatures::instance()->setTextureCompression(SGSceneFeatures::DoNotUseCompression);
|
||||||
SGPath preferencesFile = fg_root;
|
|
||||||
preferencesFile.append("preferences.xml");
|
|
||||||
readProperties(preferencesFile.str(), props);
|
|
||||||
} catch (...) {
|
|
||||||
// In case of an error, at least make summer :)
|
|
||||||
props->getNode("sim/startup/season", true)->setStringValue("summer");
|
|
||||||
|
|
||||||
std::cerr << "Problems loading FlightGear preferences.\n"
|
|
||||||
<< "Probably FG_ROOT is not properly set." << std::endl;
|
|
||||||
}
|
|
||||||
SGMaterialLib* ml = new SGMaterialLib;
|
SGMaterialLib* ml = new SGMaterialLib;
|
||||||
SGPath mpath(fg_root);
|
SGPath mpath(fg_root);
|
||||||
mpath.append("materials.xml");
|
mpath.append("materials.xml");
|
||||||
|
@ -156,7 +170,10 @@ main(int argc, char** argv)
|
||||||
options->setMaterialLib(ml);
|
options->setMaterialLib(ml);
|
||||||
options->setPropertyNode(props);
|
options->setPropertyNode(props);
|
||||||
options->setPluginStringData("SimGear::FG_ROOT", fg_root);
|
options->setPluginStringData("SimGear::FG_ROOT", fg_root);
|
||||||
osgDB::Registry::instance()->setOptions(options.get());
|
// We have some problems here, rethink them at some time
|
||||||
|
options->setPluginStringData("SimGear::PARTICLESYSTEM", "OFF");
|
||||||
|
// Omit building bounding volume trees, as the viewer will not run a simulation
|
||||||
|
options->setPluginStringData("SimGear::BOUNDINGVOLUMES", "OFF");
|
||||||
|
|
||||||
// Here, all arguments are processed
|
// Here, all arguments are processed
|
||||||
arguments.reportRemainingOptionsAsUnrecognized();
|
arguments.reportRemainingOptionsAsUnrecognized();
|
||||||
|
|
Loading…
Reference in a new issue