]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/SceneryPager.hxx
Merge branch 'releases/2.2.0' into next
[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 #define FLIGHTGEAR_SCENERYPAGERHXX 1
23 #include <string>
24 #include <vector>
25
26 #include <osg/FrameStamp>
27 #include <osg/Group>
28 #include <osgDB/DatabasePager>
29
30 #include <simgear/structure/OSGVersion.hxx>
31 #include <simgear/scene/model/SGPagedLOD.hxx>
32
33 namespace flightgear
34 {
35 class SceneryPager : public osgDB::DatabasePager
36 {
37 public:
38     SceneryPager();
39     SceneryPager(const SceneryPager& rhs);
40     // Unhide DatabasePager::requestNodeFile
41     using osgDB::DatabasePager::requestNodeFile;
42     // reimplement to add readerWriterOptions from SGPagedLOD
43 #if SG_PAGEDLOD_HAS_OPTIONS
44 #else
45     virtual void requestNodeFile(const std::string& fileName, osg::Group* group,
46                                  float priority,
47                                  const osg::FrameStamp* framestamp,
48                                  osg::ref_ptr<osg::Referenced>& databaseRequest,
49                                  osgDB::ReaderWriter::Options* options);
50 #endif
51     void queueRequest(const std::string& fileName, osg::Group* node,
52                       float priority, osg::FrameStamp* frameStamp,
53                       osg::ref_ptr<osg::Referenced>& databaseRequest,
54                       osgDB::ReaderWriter::Options* options);
55     // This is passed a ref_ptr so that it can "take ownership" of the
56     // node to delete and decrement its refcount while holding the
57     // lock on the delete list.
58     void queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr);
59     virtual void signalEndFrame();
60 protected:
61     // Queue up file requests until the end of the frame
62     struct PagerRequest
63     {
64         PagerRequest() : _priority(0.0f), _databaseRequest(0) {}
65         PagerRequest(const PagerRequest& rhs) :
66             _fileName(rhs._fileName), _group(rhs._group),
67             _priority(rhs._priority), _frameStamp(rhs._frameStamp),
68             _options(rhs._options), _databaseRequest(rhs._databaseRequest) {}
69
70         PagerRequest(const std::string& fileName, osg::Group* group,
71                      float priority, osg::FrameStamp* frameStamp,
72                      osg::ref_ptr<Referenced>& databaseRequest,
73                      osgDB::ReaderWriter::Options* options):
74             _fileName(fileName), _group(group), _priority(priority),
75             _frameStamp(frameStamp), _options(options),
76             _databaseRequest(&databaseRequest)
77         {}
78
79         void doRequest(SceneryPager* pager);
80         std::string _fileName;
81         osg::ref_ptr<osg::Group> _group;
82         float _priority;
83         osg::ref_ptr<osg::FrameStamp> _frameStamp;
84         osg::ref_ptr<osgDB::ReaderWriter::Options> _options;
85         osg::ref_ptr<osg::Referenced>* _databaseRequest;
86     };
87     typedef std::vector<PagerRequest> PagerRequestList;
88     PagerRequestList _pagerRequests;
89     typedef std::vector<osg::ref_ptr<osg::Object> > DeleteRequestList;
90     DeleteRequestList _deleteRequests;
91     virtual ~SceneryPager();
92 };
93 }
94 #endif