]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/SceneryPager.hxx
Use the position from the model placement.
[flightgear.git] / src / Scenery / SceneryPager.hxx
1 // SceneryPager.hxx -- Interface to OSG database pager
2 //
3 // Copyright (C) 2007 Tim Moore timoore@redhat.com
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 //
19 // $Id$
20
21 #ifndef FLIGHTGEAR_SCENERYPAGERHXX
22 #include <string>
23 #include <vector>
24
25 #include <osg/FrameStamp>
26 #include <osg/Group>
27 #include <osgDB/DatabasePager>
28
29 #include <simgear/structure/OSGVersion.hxx>
30
31 // Pager request change in OpenSceneGraph 2.5.1
32 #if SG_OSG_VERSION >= 25001
33 #define FGOSGPAGER25
34 #endif
35
36 namespace flightgear
37 {
38 class SceneryPager : public osgDB::DatabasePager
39 {
40 public:
41     SceneryPager();
42     SceneryPager(const SceneryPager& rhs);
43     // Unhide DatabasePager::requestNodeFile
44     using osgDB::DatabasePager::requestNodeFile;
45     // reimplement to add readerWriterOptions from SGPagedLOD
46     virtual void requestNodeFile(const std::string& fileName, osg::Group* group,
47                                  float priority,
48                                  const osg::FrameStamp* framestamp
49 #ifdef FGOSGPAGER25
50                                  , osg::ref_ptr<osg::Referenced>&
51                                  databaseRequest
52 #endif
53         );
54     void queueRequest(const std::string& fileName, osg::Group* node,
55                       float priority, osg::FrameStamp* frameStamp,
56 #ifdef FGOSGPAGER25
57                       osg::ref_ptr<osg::Referenced>& databaseRequest,
58 #endif
59                       osgDB::ReaderWriter::Options* options);
60     // This is passed a ref_ptr so that it can "take ownership" of the
61     // node to delete and decrement its refcount while holding the
62     // lock on the delete list.
63     void queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr);
64     virtual void signalEndFrame();
65 protected:
66     // Queue up file requests until the end of the frame
67     struct PagerRequest
68     {
69         PagerRequest() : _priority(0.0f), _databaseRequest(0) {}
70         PagerRequest(const PagerRequest& rhs) :
71             _fileName(rhs._fileName), _group(rhs._group),
72             _priority(rhs._priority), _frameStamp(rhs._frameStamp),
73             _options(rhs._options), _databaseRequest(rhs._databaseRequest) {}
74
75         PagerRequest(const std::string& fileName, osg::Group* group,
76                      float priority, osg::FrameStamp* frameStamp,
77 #ifdef FGOSGPAGER25
78                      osg::ref_ptr<Referenced>& databaseRequest,
79 #endif
80                      osgDB::ReaderWriter::Options* options):
81             _fileName(fileName), _group(group), _priority(priority),
82             _frameStamp(frameStamp), _options(options),
83 #ifdef FGOSGPAGER25
84             _databaseRequest(&databaseRequest)
85 #else
86             _databaseRequest(0)
87 #endif
88         {}
89
90         void doRequest(SceneryPager* pager)
91         {
92             if (_group->getNumChildren() == 0)
93                 pager->requestNodeFile(_fileName, _group.get(), _priority,
94                                        _frameStamp.get(),
95 #ifdef FGOSGPAGER25
96                                        *_databaseRequest,
97 #endif
98                                        _options.get());
99         }
100
101         std::string _fileName;
102         osg::ref_ptr<osg::Group> _group;
103         float _priority;
104         osg::ref_ptr<osg::FrameStamp> _frameStamp;
105         osg::ref_ptr<osgDB::ReaderWriter::Options> _options;
106         osg::ref_ptr<osg::Referenced>* _databaseRequest;
107     };
108     typedef std::vector<PagerRequest> PagerRequestList;
109     PagerRequestList _pagerRequests;
110     typedef std::vector<osg::ref_ptr<osg::Object> > DeleteRequestList;
111     DeleteRequestList _deleteRequests;
112     virtual ~SceneryPager();
113 };
114 }
115 #define FLIGHTGEAR_SCENERYPAGERHXX 1
116 #endif