]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/SGPagedLOD.cxx
Merge branch 'next' of git.gitorious.org:fg/simgear into next
[simgear.git] / simgear / scene / model / SGPagedLOD.cxx
index 541c635085e8ad1858ad49f50fa092cb509706bc..b44019b7ec5ada7b3168f8cee6b6af4ce48d3508 100644 (file)
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
 #include <osgDB/ReadFile>
+#include <osgDB/Input>
+#include <osgDB/ParameterOutput>
+#include <osgDB/DatabasePager>
 
 #include <simgear/debug/logstream.hxx>
 #include <simgear/structure/OSGVersion.hxx>
 #include "SGReaderWriterXMLOptions.hxx"
 #include "SGPagedLOD.hxx"
 
+#include <simgear/math/SGMath.hxx>
+
 using namespace osg;
 using namespace simgear;
 
+bool SGPagedLOD::_cache = true;
+
 SGPagedLOD::SGPagedLOD()
         : PagedLOD()
 {
@@ -37,40 +48,76 @@ SGPagedLOD::~SGPagedLOD()
 }
 
 SGPagedLOD::SGPagedLOD(const SGPagedLOD& plod,const CopyOp& copyop)
-        : osg::PagedLOD(plod, copyop),
-        _readerWriterOptions(plod._readerWriterOptions)
+        : osg::PagedLOD(plod, copyop)
+#if !SG_PAGEDLOD_HAS_OPTIONS
+        ,  _readerWriterOptions(plod._readerWriterOptions)
+#endif
 {
 }
 
+void
+SGPagedLOD::setReaderWriterOptions(osgDB::ReaderWriter::Options *options)
+{
+    if (_cache)
+        options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL);
+    else
+        options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_NONE);
+#if SG_PAGEDLOD_HAS_OPTIONS
+    setDatabaseOptions(options);
+#else
+    _readerWriterOptions = options;
+#endif
+}
+
 bool SGPagedLOD::addChild(osg::Node *child)
 {
-    //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::addChild(" << getFileName(getNumChildren()) << ")");
     if (!PagedLOD::addChild(child))
         return false;
 
     setRadius(getBound().radius());
     setCenter(getBound().center());
-    SGReaderWriterXMLOptions* opts;
-    opts = dynamic_cast<SGReaderWriterXMLOptions*>(_readerWriterOptions.get());
-    if(opts)
-    {
-        osg::ref_ptr<SGModelData> d = opts->getModelData();
-        if(d.valid())
-            d->modelLoaded(getFileName(getNumChildren()-1), d->getProperties(),
-                           this);
-    }
     return true;
 }
 
-void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp)
+// Work around interface change in osgDB::DatabasePager::requestNodeFile
+struct NodePathProxy
+{
+    NodePathProxy(NodePath& nodePath)
+        : _nodePath(nodePath)
+    {
+    }
+    operator Group* () { return static_cast<Group*>(_nodePath.back()); }
+    operator NodePath& () { return _nodePath; }
+    NodePath& _nodePath;
+};
+
+void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp, FrameStamp* framestamp,
+                           NodePath& path)
 {
     //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::forceLoad(" <<
     //getFileName(getNumChildren()) << ")");
     unsigned childNum = getNumChildren();
     setTimeStamp(childNum, 0);
     double priority=1.0;
-    dbp->requestNodeFile(getFileName(childNum),this,priority,0,
+    dbp->requestNodeFile(getFileName(childNum), NodePathProxy(path),
+                         priority, framestamp,
                          getDatabaseRequest(childNum),
-                         _readerWriterOptions.get());
+                         getReaderWriterOptions());
 }
 
+bool SGPagedLOD_writeLocalData(const Object& obj, osgDB::Output& fw)
+{
+    return true;
+}
+
+namespace
+{
+osgDB::RegisterDotOsgWrapperProxy sgPagedLODProxy
+(
+    new SGPagedLOD,
+    "simgear::SGPagedLOD",
+    "Object Node LOD PagedLOD SGPagedLOD Group",
+    0,
+    &SGPagedLOD_writeLocalData
+    );
+}