From 49d8b9676844df2fbf3327de78ed1de8f96b2d7f Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Sun, 4 Mar 2012 08:33:21 +0100 Subject: [PATCH] Centralize osgDB::Option handling in SGReaderWriterOptions. --- projects/VC90/SimGear.vcproj | 8 ----- simgear/scene/sky/cloud.cxx | 9 ++--- simgear/scene/sky/moon.cxx | 9 ++--- simgear/scene/sky/newcloud.cxx | 9 ++--- simgear/scene/sky/oursun.cxx | 6 ++-- simgear/scene/util/CMakeLists.txt | 2 -- simgear/scene/util/PathOptions.cxx | 37 -------------------- simgear/scene/util/PathOptions.hxx | 31 ---------------- simgear/scene/util/SGReaderWriterOptions.hxx | 7 ++++ 9 files changed, 19 insertions(+), 99 deletions(-) delete mode 100644 simgear/scene/util/PathOptions.cxx delete mode 100644 simgear/scene/util/PathOptions.hxx diff --git a/projects/VC90/SimGear.vcproj b/projects/VC90/SimGear.vcproj index 535d027d..de01f387 100644 --- a/projects/VC90/SimGear.vcproj +++ b/projects/VC90/SimGear.vcproj @@ -1793,14 +1793,6 @@ RelativePath="..\..\simgear\scene\util\NodeAndDrawableVisitor.hxx" > - - - - diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index aeac58ff..5517cff9 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -43,12 +43,9 @@ #include #include #include -#if SG_OSG_MIN_VERSION_REQUIRED(2,9,5) -#include -#endif #include -#include +#include #include #include #include @@ -94,8 +91,8 @@ SGMakeState(const SGPath &path, const char* colorTexture, { osg::StateSet *stateSet = new osg::StateSet; - osg::ref_ptr options - = makeOptionsFromPath(path); + osg::ref_ptr options; + options = SGReaderWriterOptions::fromPath(path.str()); stateSet->setTextureAttribute(0, SGLoadTexture2D(colorTexture, options.get())); stateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON); diff --git a/simgear/scene/sky/moon.cxx b/simgear/scene/sky/moon.cxx index f6539309..1fa724ef 100644 --- a/simgear/scene/sky/moon.cxx +++ b/simgear/scene/sky/moon.cxx @@ -43,14 +43,11 @@ #include #include #include -#if SG_OSG_MIN_VERSION_REQUIRED(2,9,5) -#include -#endif #include #include #include -#include +#include #include "sphere.hxx" #include "moon.hxx" @@ -78,8 +75,8 @@ SGMoon::build( SGPath path, double moon_size ) { stateSet->setRenderBinDetails(-5, "RenderBin"); // set up the orb state - osg::ref_ptr options - = makeOptionsFromPath(path); + osg::ref_ptr options; + options = SGReaderWriterOptions::fromPath(path.str()); osg::Texture2D* texture = SGLoadTexture2D("moon.png", options.get()); stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); diff --git a/simgear/scene/sky/newcloud.cxx b/simgear/scene/sky/newcloud.cxx index 3dee4ab4..04fb2207 100644 --- a/simgear/scene/sky/newcloud.cxx +++ b/simgear/scene/sky/newcloud.cxx @@ -42,7 +42,6 @@ #include #include -#include #include #include #include @@ -110,11 +109,9 @@ SGNewCloud::SGNewCloud(const SGPath &texture_root, const SGPropertyNode *cld_def "texture"), "image"), texture); - ref_ptr options - = makeOptionsFromPath(texture_root); - ref_ptr sgOptions - = new SGReaderWriterOptions(*options.get()); - if ((effect = makeEffect(pcloudEffect, true, sgOptions.get()))) + ref_ptr options; + options = SGReaderWriterOptions::fromPath(texture_root.str()); + if ((effect = makeEffect(pcloudEffect, true, options.get()))) effectMap.insert(EffectMap::value_type(texture, effect)); } else { effect = iter->second.get(); diff --git a/simgear/scene/sky/oursun.cxx b/simgear/scene/sky/oursun.cxx index f2af25f8..f959200c 100644 --- a/simgear/scene/sky/oursun.cxx +++ b/simgear/scene/sky/oursun.cxx @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include #include "oursun.hxx" @@ -69,8 +69,8 @@ SGSun::build( SGPath path, double sun_size, SGPropertyNode *property_tree_Node ) env_node = property_tree_Node; - osg::ref_ptr options - = makeOptionsFromPath(path); + osg::ref_ptr options; + options = SGReaderWriterOptions::fromPath(path.str()); // build the ssg scene graph sub tree for the sky and connected // into the provide scene graph branch sun_transform = new osg::MatrixTransform; diff --git a/simgear/scene/util/CMakeLists.txt b/simgear/scene/util/CMakeLists.txt index 8d5e84a2..8ec8d119 100644 --- a/simgear/scene/util/CMakeLists.txt +++ b/simgear/scene/util/CMakeLists.txt @@ -22,7 +22,6 @@ set(HEADERS StateAttributeFactory.hxx UpdateOnceCallback.hxx VectorArrayAdapter.hxx - PathOptions.hxx project.hxx ) @@ -39,7 +38,6 @@ set(SOURCES SplicingVisitor.cxx StateAttributeFactory.cxx UpdateOnceCallback.cxx - PathOptions.cxx project.cxx ) diff --git a/simgear/scene/util/PathOptions.cxx b/simgear/scene/util/PathOptions.cxx deleted file mode 100644 index 711b04b2..00000000 --- a/simgear/scene/util/PathOptions.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// PathOptions.cxx -- make an osgDB Options object from a path -// Copyright (C) 2007 Tim Moore timoore@redhat.com -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id$ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "PathOptions.hxx" - -using namespace simgear; - -osgDB::Options* simgear::makeOptionsFromPath(const SGPath& path) -{ - using namespace osgDB; - Options *options - = new Options(*(Registry::instance()->getOptions())); - options->setDatabasePath(path.str()); - return options; -} diff --git a/simgear/scene/util/PathOptions.hxx b/simgear/scene/util/PathOptions.hxx deleted file mode 100644 index e1bc331b..00000000 --- a/simgear/scene/util/PathOptions.hxx +++ /dev/null @@ -1,31 +0,0 @@ -// PathOptions.hxx -- make an osgDB Options object from a path -// Copyright (C) 2007 Tim Moore timoore@redhat.com -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id$ - -#ifndef PATHOPTIONSHXX -#define PATHOPTIONSHXX 1 - -#include -#include - -namespace simgear -{ -osgDB::Options* makeOptionsFromPath(const SGPath&); -} - -#endif diff --git a/simgear/scene/util/SGReaderWriterOptions.hxx b/simgear/scene/util/SGReaderWriterOptions.hxx index ef7a5864..798c85fe 100644 --- a/simgear/scene/util/SGReaderWriterOptions.hxx +++ b/simgear/scene/util/SGReaderWriterOptions.hxx @@ -104,6 +104,13 @@ public: return new SGReaderWriterOptions(*static_cast(options)); } + static SGReaderWriterOptions* fromPath(const std::string& path) + { + SGReaderWriterOptions* options = copyOrCreate(0); + options->setDatabasePath(path); + return options; + } + protected: virtual ~SGReaderWriterOptions() {}