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 <simgear/scene/model/SGPagedLOD.hxx>
24 #include <simgear/math/SGMath.hxx>
25 #include "SceneryPager.hxx"
30 using namespace flightgear;
32 SceneryPager::SceneryPager()
34 _pagerRequests.reserve(48);
35 _deleteRequests.reserve(16);
38 SceneryPager::SceneryPager(const SceneryPager& rhs) :
43 SceneryPager::~SceneryPager()
47 #if SG_PAGEDLOD_HAS_OPTIONS
49 void SceneryPager::requestNodeFile(const std::string& fileName, Group* group,
50 float priority, const FrameStamp* framestamp,
51 ref_ptr<Referenced>& databaseRequest,
52 osgDB::ReaderWriter::Options* options)
54 simgear::SGPagedLOD *sgplod = dynamic_cast<simgear::SGPagedLOD*>(group);
56 DatabasePager::requestNodeFile(fileName, group, priority, framestamp,
58 sgplod->getReaderWriterOptions());
60 DatabasePager::requestNodeFile(fileName, group, priority, framestamp,
66 void SceneryPager::queueRequest(const std::string& fileName, Group* group,
67 float priority, FrameStamp* frameStamp,
68 ref_ptr<Referenced>& databaseRequest,
69 osgDB::ReaderWriter::Options* options)
71 _pagerRequests.push_back(PagerRequest(fileName, group, priority,
77 void SceneryPager::queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr)
79 _deleteRequests.push_back(objptr);
83 // Work around interface change in
84 // osgDB::DatabasePager::requestNodeFile
89 NodePathProxy(NodePath& nodePath)
93 operator Group* () { return static_cast<Group*>(_nodePath.back()); }
94 operator NodePath& () { return _nodePath; }
99 void SceneryPager::PagerRequest::doRequest(SceneryPager* pager)
101 if (_group->getNumChildren() == 0) {
103 path.push_back(_group.get());
104 pager->requestNodeFile(_fileName, NodePathProxy(path), _priority,
111 void SceneryPager::signalEndFrame()
114 bool areDeleteRequests = false;
115 bool arePagerRequests = false;
116 if (!_deleteRequests.empty()) {
117 areDeleteRequests = true;
118 OpenThreads::ScopedLock<OpenThreads::Mutex>
119 lock(_fileRequestQueue->_childrenToDeleteListMutex);
120 ObjectList& deleteList = _fileRequestQueue->_childrenToDeleteList;
121 deleteList.insert(deleteList.end(),
122 _deleteRequests.begin(),
123 _deleteRequests.end());
124 _deleteRequests.clear();
126 if (!_pagerRequests.empty()) {
127 arePagerRequests = true;
128 for_each(_pagerRequests.begin(), _pagerRequests.end(),
129 bind2nd(mem_fun_ref(&PagerRequest::doRequest), this));
130 _pagerRequests.clear();
132 if (areDeleteRequests && !arePagerRequests) {
133 _fileRequestQueue->updateBlock();
135 DatabasePager::signalEndFrame();