]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/SceneryPager.cxx
Use OSG polytope intersector to fill ground cache
[flightgear.git] / src / Scenery / SceneryPager.cxx
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 #include <simgear/scene/model/SGPagedLOD.hxx>
20 #include "SceneryPager.hxx"
21 #include <algorithm>
22 #include <functional>
23
24 using namespace osg;
25 using namespace flightgear;
26
27 SceneryPager::SceneryPager()
28 {
29     _pagerRequests.reserve(48);
30     _deleteRequests.reserve(16);
31     setExpiryDelay(120.0);
32 }
33
34 SceneryPager::SceneryPager(const SceneryPager& rhs) :
35     DatabasePager(rhs)
36 {
37 }
38
39 SceneryPager::~SceneryPager()
40 {
41 }
42
43 void SceneryPager::requestNodeFile(const std::string& fileName, Group* group,
44                                    float priority,
45                                    const FrameStamp* framestamp
46 #ifdef FGOSGPAGER25
47                                    , ref_ptr<Referenced>& databaseRequest
48 #endif
49     )
50 {
51     simgear::SGPagedLOD *sgplod = dynamic_cast<simgear::SGPagedLOD*>(group);
52     if(sgplod)
53         DatabasePager::requestNodeFile(fileName, group, priority, framestamp,
54 #ifdef FGOSGPAGER25
55                                        databaseRequest,
56 #endif
57                                        sgplod->getReaderWriterOptions());
58     else
59         DatabasePager::requestNodeFile(fileName, group, priority, framestamp
60 #ifdef FGOSGPAGER25
61                                        , databaseRequest
62 #endif
63             );
64 }
65
66 void SceneryPager::queueRequest(const std::string& fileName, Group* group,
67                                 float priority, FrameStamp* frameStamp,
68 #ifdef FGOSGPAGER25
69                                 ref_ptr<Referenced>& databaseRequest,
70 #endif
71                                 osgDB::ReaderWriter::Options* options)
72 {
73     _pagerRequests.push_back(PagerRequest(fileName, group, priority,
74                                           frameStamp,
75 #ifdef FGOSGPAGER25
76                                           databaseRequest,
77 #endif
78                                           options));
79 }
80
81 void SceneryPager::queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr)
82 {
83     _deleteRequests.push_back(objptr);
84     objptr = 0;
85 }
86 void SceneryPager::signalEndFrame()
87 {
88     using namespace std;
89     bool areDeleteRequests = false;
90     bool arePagerRequests = false;
91     if (!_deleteRequests.empty()) {
92         areDeleteRequests = true;
93 #ifdef FGOSGPAGER25
94         OpenThreads::ScopedLock<OpenThreads::Mutex>
95             lock(_fileRequestQueue->_childrenToDeleteListMutex);
96         ObjectList& deleteList = _fileRequestQueue->_childrenToDeleteList;
97 #else
98         OpenThreads::ScopedLock<OpenThreads::Mutex>
99             lock(_childrenToDeleteListMutex);
100         ObjectList& deleteList = _childrenToDeleteList;
101 #endif
102         deleteList.insert(deleteList.end(),
103                           _deleteRequests.begin(),
104                           _deleteRequests.end());
105         _deleteRequests.clear();
106     }
107     if (!_pagerRequests.empty()) {
108         arePagerRequests = true;
109         for_each(_pagerRequests.begin(), _pagerRequests.end(),
110                  bind2nd(mem_fun_ref(&PagerRequest::doRequest), this));
111         _pagerRequests.clear();
112     }
113     if (areDeleteRequests && !arePagerRequests) {
114 #ifdef FGOSGPAGER25
115         _fileRequestQueue->updateBlock();
116 #else
117         updateDatabasePagerThreadBlock();
118 #endif        
119     }
120     DatabasePager::signalEndFrame();
121 }
122