]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/SGPagedLOD.cxx
model paging patch from Till Busch
[simgear.git] / simgear / scene / model / SGPagedLOD.cxx
1 // Copyright (C) 2008 Till Busch buti@bux.at
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16
17 #include <osgDB/ReadFile>
18
19 #include <simgear/debug/logstream.hxx>
20
21 #include "modellib.hxx"
22 #include "SGReaderWriterXMLOptions.hxx"
23 #include "SGPagedLOD.hxx"
24
25 using namespace osg;
26 using namespace simgear;
27
28 SGPagedLOD::SGPagedLOD()
29         : PagedLOD()
30 {
31 }
32
33 SGPagedLOD::~SGPagedLOD()
34 {
35     //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::~SGPagedLOD(" << getFileName(0) << ")");
36 }
37
38 SGPagedLOD::SGPagedLOD(const SGPagedLOD& plod,const CopyOp& copyop)
39         : osg::PagedLOD(plod, copyop),
40         _readerWriterOptions(plod._readerWriterOptions)
41 {
42 }
43
44 bool SGPagedLOD::addChild(osg::Node *child)
45 {
46     //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::addChild(" << getFileName(getNumChildren()) << ")");
47     if (!PagedLOD::addChild(child))
48         return false;
49
50     // if the model was an .xml-file it will have UserData set
51     osg::ref_ptr<SGModelData> d = dynamic_cast<SGModelData*>(child->getUserData());
52     if (d.valid())
53         d->modelLoaded(getFileName(getNumChildren()-1), d->getProperties(), this);
54     else // this calls modelLoaded for non-xml models
55     {
56         SGReaderWriterXMLOptions *o=dynamic_cast<SGReaderWriterXMLOptions*>(_readerWriterOptions.get());
57         if(o)
58         {
59             d = o->getModelData();
60             if(d.valid())
61                 d->modelLoaded(getFileName(getNumChildren()-1), 0, this);
62         }
63     }
64     return true;
65 }
66
67 void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp)
68 {
69     //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::forceLoad(" << getFileName(getNumChildren()) << ")");
70     setTimeStamp(getNumChildren(),0);
71     double priority=1.0;
72     dbp->requestNodeFile(getFileName(getNumChildren()),this,priority,0, _readerWriterOptions.get());
73 }
74