From 2c2234d68bfa0c68790cb282188e85f9d04f924a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 14 Jun 2011 16:50:40 +0000 Subject: [PATCH] Improved the handling of command line parameters --- .../osgocclusionquery/osgocclusionquery.cpp | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/examples/osgocclusionquery/osgocclusionquery.cpp b/examples/osgocclusionquery/osgocclusionquery.cpp index 5ec08ff55..09403f9fc 100644 --- a/examples/osgocclusionquery/osgocclusionquery.cpp +++ b/examples/osgocclusionquery/osgocclusionquery.cpp @@ -537,10 +537,10 @@ public: } else if (ea.getKey()=='o') { - if (osgDB::writeNodeFile( _node, "saved_model.osg" )) - osg::notify( osg::ALWAYS ) << "osgOQ: Wrote scene graph to \"saved_model.osg\"" << std::endl; + if (osgDB::writeNodeFile( _node, "saved_model.osgt" )) + osg::notify( osg::ALWAYS ) << "osgOQ: Wrote scene graph to \"saved_model.osgt\"" << std::endl; else - osg::notify( osg::ALWAYS ) << "osgOQ: Wrote failed for \"saved_model.osg\"" << std::endl; + osg::notify( osg::ALWAYS ) << "osgOQ: Wrote failed for \"saved_model.osgt\"" << std::endl; return true; } return false; @@ -744,28 +744,35 @@ int main(int argc, char** argv) // add the help handler viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); + bool optimize = arguments.read( "--opt" ); // load the specified model - osg::ref_ptr root = osgDB::readNodeFiles( arguments ); - if (!root) + osg::ref_ptr root = 0; + + if (arguments.argc()>1) + { + root = osgDB::readNodeFiles( arguments ); + if (root.valid()) + { + // Run a NodeVisitor to insert OcclusionQueryNodes in the scene graph. + OcclusionQueryVisitor oqv; + root->accept( oqv ); + } + else + { + std::cout << arguments.getApplicationName() <<": unable to load specified data." << std::endl; + return 1; + } + } + else { - std::cout << arguments.getApplicationName() <<": No files specified, or can't load them." << std::endl; root = createStockScene().get(); if (!root) { std::cout << arguments.getApplicationName() <<": Failed to create stock scene." << std::endl; return 1; } - std::cout << "Using stock scene instead." << std::endl; } - else - { - // Run a NodeVisitor to insert OcclusionQueryNodes in the scene graph. - OcclusionQueryVisitor oqv; - root->accept( oqv ); - } - - bool optimize = arguments.read( "--opt" ); // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized();