From 42fb9b8e9f95b1f3a0b9b1c45b6b02c62bb588ed Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Sat, 12 Nov 2011 19:45:20 +0100 Subject: [PATCH] Consolidate the different ReaderWriterOptions classes. --- src/Airports/groundnetwork.cxx | 1 + src/Main/fgviewer.cxx | 13 +++++----- src/Scenery/tilemgr.cxx | 43 ++++------------------------------ src/Scenery/tilemgr.hxx | 11 ++------- utils/fgviewer/fgviewer.cxx | 11 +++++---- 5 files changed, 20 insertions(+), 59 deletions(-) diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index f817e3035..d722b86ab 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -26,6 +26,7 @@ #include #include +#include #include diff --git a/src/Main/fgviewer.cxx b/src/Main/fgviewer.cxx index e7f46005b..99bdd8e65 100644 --- a/src/Main/fgviewer.cxx +++ b/src/Main/fgviewer.cxx @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -223,15 +223,14 @@ fgviewerMain(int argc, char** argv) // The file path list must be set in the registry. osgDB::Registry::instance()->getDataFilePathList() = filePathList; - SGReaderWriterBTGOptions* btgOptions = new SGReaderWriterBTGOptions; - btgOptions->getDatabasePathList() = filePathList; - btgOptions->setMatlib(globals->get_matlib()); - btgOptions->setUseRandomObjects(fgGetBool("/sim/rendering/random-objects", false)); - btgOptions->setUseRandomVegetation(fgGetBool("/sim/rendering/random-vegetation", false)); + simgear::SGReaderWriterOptions* options = new simgear::SGReaderWriterOptions; + options->getDatabasePathList() = filePathList; + options->setMaterialLib(globals->get_matlib()); + options->setPropertyNode(globals->get_props()); // read the scene from the list of file specified command line args. osg::ref_ptr loadedModel; - loadedModel = osgDB::readNodeFiles(dataFiles, btgOptions); + loadedModel = osgDB::readNodeFiles(dataFiles, options); // if no model has been successfully loaded report failure. if (!loadedModel.valid()) { diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index bfd3c9de0..363ea858b 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include
@@ -55,33 +55,11 @@ using simgear::TileEntry; using simgear::TileCache; -// helper: listen to property changes affecting tile loading -class LoaderPropertyWatcher : public SGPropertyChangeListener -{ -public: - LoaderPropertyWatcher(FGTileMgr* pTileMgr) : - _pTileMgr(pTileMgr) - { - } - - virtual void valueChanged(SGPropertyNode*) - { - _pTileMgr->configChanged(); - } - -private: - FGTileMgr* _pTileMgr; -}; - - FGTileMgr::FGTileMgr(): state( Start ), vis( 16000 ), - _terra_sync(NULL), - _propListener(new LoaderPropertyWatcher(this)) + _terra_sync(NULL) { - _randomObjects = fgGetNode("/sim/rendering/random-objects", true); - _randomVegetation = fgGetNode("/sim/rendering/random-vegetation", true); _maxTileRangeM = fgGetNode("/sim/rendering/static-lod/bare", true); } @@ -91,8 +69,6 @@ FGTileMgr::~FGTileMgr() // remove all nodes we might have left behind osg::Group* group = globals->get_scenery()->get_terrain_branch(); group->removeChildren(0, group->getNumChildren()); - delete _propListener; - _propListener = NULL; // clear OSG cache osgDB::Registry::instance()->clearObjectCache(); } @@ -102,12 +78,9 @@ FGTileMgr::~FGTileMgr() void FGTileMgr::init() { SG_LOG( SG_TERRAIN, SG_INFO, "Initializing Tile Manager subsystem." ); - _options = new SGReaderWriterBTGOptions; - _options->setMatlib(globals->get_matlib()); - - _randomObjects.get()->addChangeListener(_propListener, false); - _randomVegetation.get()->addChangeListener(_propListener, false); - configChanged(); + _options = new simgear::SGReaderWriterOptions; + _options->setMaterialLib(globals->get_matlib()); + _options->setPropertyNode(globals->get_props()); osgDB::FilePathList &fp = _options->getDatabasePathList(); const string_list &sc = globals->get_fg_scenery(); @@ -153,12 +126,6 @@ void FGTileMgr::reinit() update(0.0); } -void FGTileMgr::configChanged() -{ - _options->setUseRandomObjects(_randomObjects.get()->getBoolValue()); - _options->setUseRandomVegetation(_randomVegetation.get()->getBoolValue()); -} - /* schedule a tile for loading, keep request for given amount of time. * Returns true if tile is already loaded. */ bool FGTileMgr::sched_tile( const SGBucket& b, double priority, bool current_view, double duration) diff --git a/src/Scenery/tilemgr.hxx b/src/Scenery/tilemgr.hxx index 25e965a52..7a51f161e 100644 --- a/src/Scenery/tilemgr.hxx +++ b/src/Scenery/tilemgr.hxx @@ -31,8 +31,6 @@ #include #include -class SGReaderWriterBTGOptions; - namespace osg { class Node; @@ -41,6 +39,7 @@ class Node; namespace simgear { class SGTerraSync; +class SGReaderWriterOptions; } class FGTileMgr : public SGSubsystem, public simgear::ModelLoadHelper { @@ -65,7 +64,7 @@ private: SGBucket previous_bucket; SGBucket current_bucket; SGBucket pending; - osg::ref_ptr _options; + osg::ref_ptr _options; // x and y distance of tiles to load/draw float vis; @@ -89,9 +88,6 @@ private: static void refresh_tile(void* tileMgr, long tileIndex); SGPropertyNode* _visibilityMeters; - SGPropertyChangeListener* _propListener; - SGPropertyNode_ptr _randomObjects; - SGPropertyNode_ptr _randomVegetation; SGPropertyNode_ptr _maxTileRangeM; public: @@ -105,9 +101,6 @@ public: virtual void update(double dt); - // update loader configuration options - void configChanged(); - int schedule_tiles_at(const SGGeod& location, double rangeM); diff --git a/utils/fgviewer/fgviewer.cxx b/utils/fgviewer/fgviewer.cxx index a09cdf781..222bb9ded 100644 --- a/utils/fgviewer/fgviewer.cxx +++ b/utils/fgviewer/fgviewer.cxx @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -151,9 +151,10 @@ main(int argc, char** argv) // The file path list must be set in the registry. osgDB::Registry::instance()->getDataFilePathList() = filePathList; - SGReaderWriterBTGOptions* btgOptions = new SGReaderWriterBTGOptions; - btgOptions->getDatabasePathList() = filePathList; - btgOptions->setMatlib(ml); + simgear::SGReaderWriterOptions* options = new simgear::SGReaderWriterOptions; + options->getDatabasePathList() = filePathList; + options->setMaterialLib(ml); + options->setPropertyNode(props); // Here, all arguments are processed arguments.reportRemainingOptionsAsUnrecognized(); @@ -161,7 +162,7 @@ main(int argc, char** argv) // read the scene from the list of file specified command line args. osg::ref_ptr loadedModel; - loadedModel = osgDB::readNodeFiles(arguments, btgOptions); + loadedModel = osgDB::readNodeFiles(arguments, options); // if no model has been successfully loaded report failure. if (!loadedModel.valid()) {