1 // SceneryPager.cxx -- Interface to OSG database pager
3 // Copyright (C) 2007 Tim Moore timoore@redhat.com
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.
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.
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.
23 #include "SceneryPager.hxx"
28 using namespace flightgear;
30 SceneryPager::SceneryPager()
32 _pagerRequests.reserve(48);
33 _deleteRequests.reserve(16);
36 SceneryPager::SceneryPager(const SceneryPager& rhs) :
41 SceneryPager::~SceneryPager()
45 void SceneryPager::queueRequest(const std::string& fileName, Group* group,
46 float priority, FrameStamp* frameStamp,
47 ref_ptr<Referenced>& databaseRequest,
48 osgDB::ReaderWriter::Options* options)
50 _pagerRequests.push_back(PagerRequest(fileName, group, priority,
56 void SceneryPager::queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr)
58 _deleteRequests.push_back(objptr);
62 // Work around interface change in
63 // osgDB::DatabasePager::requestNodeFile
68 NodePathProxy(NodePath& nodePath)
72 operator Group* () { return static_cast<Group*>(_nodePath.back()); }
73 operator NodePath& () { return _nodePath; }
78 void SceneryPager::PagerRequest::doRequest(SceneryPager* pager)
80 if (_group->getNumChildren() == 0) {
82 path.push_back(_group.get());
83 pager->requestNodeFile(_fileName, NodePathProxy(path), _priority,
90 void SceneryPager::signalEndFrame()
93 bool areDeleteRequests = false;
94 bool arePagerRequests = false;
95 if (!_deleteRequests.empty()) {
96 areDeleteRequests = true;
97 OpenThreads::ScopedLock<OpenThreads::Mutex>
98 lock(_fileRequestQueue->_childrenToDeleteListMutex);
99 ObjectList& deleteList = _fileRequestQueue->_childrenToDeleteList;
100 deleteList.insert(deleteList.end(),
101 _deleteRequests.begin(),
102 _deleteRequests.end());
103 _deleteRequests.clear();
105 if (!_pagerRequests.empty()) {
106 arePagerRequests = true;
107 for_each(_pagerRequests.begin(), _pagerRequests.end(),
108 bind2nd(mem_fun_ref(&PagerRequest::doRequest), this));
109 _pagerRequests.clear();
111 if (areDeleteRequests && !arePagerRequests) {
112 _fileRequestQueue->updateBlock();
114 DatabasePager::signalEndFrame();