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 void SceneryPager::requestNodeFile(const std::string& fileName, Group* group,
48 float priority, const FrameStamp* framestamp,
49 ref_ptr<Referenced>& databaseRequest,
50 #if SG_OSG_MIN_VERSION_REQUIRED(2,9,5)
51 const osg::Referenced* options
53 osgDB::ReaderWriter::Options* options
57 simgear::SGPagedLOD *sgplod = dynamic_cast<simgear::SGPagedLOD*>(group);
59 DatabasePager::requestNodeFile(fileName, group, priority, framestamp,
61 sgplod->getReaderWriterOptions());
63 DatabasePager::requestNodeFile(fileName, group, priority, framestamp,
68 void SceneryPager::queueRequest(const std::string& fileName, Group* group,
69 float priority, FrameStamp* frameStamp,
70 ref_ptr<Referenced>& databaseRequest,
71 osgDB::ReaderWriter::Options* options)
73 _pagerRequests.push_back(PagerRequest(fileName, group, priority,
79 void SceneryPager::queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr)
81 _deleteRequests.push_back(objptr);
84 void SceneryPager::signalEndFrame()
87 bool areDeleteRequests = false;
88 bool arePagerRequests = false;
89 if (!_deleteRequests.empty()) {
90 areDeleteRequests = true;
91 OpenThreads::ScopedLock<OpenThreads::Mutex>
92 lock(_fileRequestQueue->_childrenToDeleteListMutex);
93 ObjectList& deleteList = _fileRequestQueue->_childrenToDeleteList;
94 deleteList.insert(deleteList.end(),
95 _deleteRequests.begin(),
96 _deleteRequests.end());
97 _deleteRequests.clear();
99 if (!_pagerRequests.empty()) {
100 arePagerRequests = true;
101 for_each(_pagerRequests.begin(), _pagerRequests.end(),
102 bind2nd(mem_fun_ref(&PagerRequest::doRequest), this));
103 _pagerRequests.clear();
105 if (areDeleteRequests && !arePagerRequests) {
106 _fileRequestQueue->updateBlock();
108 DatabasePager::signalEndFrame();