]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/SceneryPager.hxx
283c9db95bf6beec18d7af975b7c95ad4bcd260e
[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 namespace flightgear
30 {
31 class SceneryPager : public osgDB::DatabasePager
32 {
33 public:
34     SceneryPager();
35     SceneryPager(const SceneryPager& rhs);
36
37     // reimplement to add readerWriterOptions from SGPagedLOD
38     virtual void requestNodeFile(const std::string& fileName,osg::Group* group,
39                                  float priority, const osg::FrameStamp* framestamp);
40
41     void queueRequest(const std::string& fileName, osg::Group* node,
42                       float priority, osg::FrameStamp* frameStamp);
43     // This is passed a ref_ptr so that it can "take ownership" of the
44     // node to delete and decrement its refcount while holding the
45     // lock on the delete list.
46     void queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr);
47     virtual void signalEndFrame();
48 protected:
49     // Queue up file requests until the end of the frame
50     struct PagerRequest
51     {
52         PagerRequest() {}
53         PagerRequest(const PagerRequest& rhs) :
54             _fileName(rhs._fileName), _group(rhs._group),
55             _priority(rhs._priority), _frameStamp(rhs._frameStamp) {}
56         PagerRequest(const std::string& fileName, osg::Group* group,
57                      float priority, osg::FrameStamp* frameStamp) :
58             _fileName(fileName), _group(group), _priority(priority),
59             _frameStamp(frameStamp) {}
60         void doRequest(SceneryPager* pager)
61         {
62             if (_group->getNumChildren() == 0)
63                 pager->requestNodeFile(_fileName, _group.get(), _priority,
64                                        _frameStamp.get());
65         }
66         std::string _fileName;
67         osg::ref_ptr<osg::Group> _group;
68         float _priority;
69         osg::ref_ptr<osg::FrameStamp> _frameStamp;
70     };
71     typedef std::vector<PagerRequest> PagerRequestList;
72     PagerRequestList _pagerRequests;
73     typedef std::vector<osg::ref_ptr<osg::Object> > DeleteRequestList;
74     DeleteRequestList _deleteRequests;
75     virtual ~SceneryPager();
76 };
77 }
78 #define FLIGHTGEAR_SCENERYPAGERHXX 1
79 #endif