]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/SceneryPager.cxx
fg: move most scenery-related code to simgear
[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 flightgear;
25 using osg::ref_ptr;
26 using osg::Node;
27
28 SceneryPager::SceneryPager()
29 {
30     _pagerRequests.reserve(48);
31     _deleteRequests.reserve(16);
32     setExpiryDelay(120.0);
33 }
34
35 SceneryPager::SceneryPager(const SceneryPager& rhs) :
36     DatabasePager(rhs)
37 {
38 }
39
40 SceneryPager::~SceneryPager()
41 {
42 }
43
44 void SceneryPager::requestNodeFile(const std::string& fileName,osg::Group* group,
45                                     float priority, const osg::FrameStamp* framestamp)
46 {
47     simgear::SGPagedLOD *sgplod = dynamic_cast<simgear::SGPagedLOD*>(group);
48     if(sgplod)
49         DatabasePager::requestNodeFile(fileName,group,priority,framestamp,sgplod->getReaderWriterOptions());
50     else
51         DatabasePager::requestNodeFile(fileName,group,priority,framestamp);
52 }
53
54 void SceneryPager::queueRequest(const std::string& fileName, osg::Group* group,
55                                 float priority, osg::FrameStamp* frameStamp,
56                                 osgDB::ReaderWriter::Options* options)
57 {
58     _pagerRequests.push_back(PagerRequest(fileName, group, priority,
59                                           frameStamp, options));
60 }
61
62 void SceneryPager::queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr)
63 {
64     _deleteRequests.push_back(objptr);
65     objptr = 0;
66 }
67 void SceneryPager::signalEndFrame()
68 {
69     using namespace std;
70     bool areDeleteRequests = false;
71     bool arePagerRequests = false;
72     if (!_deleteRequests.empty()) {
73         areDeleteRequests = true;
74         OpenThreads::ScopedLock<OpenThreads::Mutex>
75             lock(_childrenToDeleteListMutex);
76         _childrenToDeleteList.insert(_childrenToDeleteList.end(),
77                                      _deleteRequests.begin(),
78                                      _deleteRequests.end());
79         _deleteRequests.clear();
80     }
81     if (!_pagerRequests.empty()) {
82         arePagerRequests = true;
83         for_each(_pagerRequests.begin(), _pagerRequests.end(),
84                  bind2nd(mem_fun_ref(&PagerRequest::doRequest), this));
85         _pagerRequests.clear();
86     }
87     if (areDeleteRequests && !arePagerRequests)
88         updateDatabasePagerThreadBlock();
89     DatabasePager::signalEndFrame();
90 }
91