1 // SceneryPager.hxx -- 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.
19 #include <simgear/scene/model/SGPagedLOD.hxx>
20 #include "SceneryPager.hxx"
24 using namespace flightgear;
28 SceneryPager::SceneryPager()
30 _pagerRequests.reserve(48);
31 _deleteRequests.reserve(16);
34 SceneryPager::SceneryPager(const SceneryPager& rhs) :
39 SceneryPager::~SceneryPager()
43 void SceneryPager::requestNodeFile(const std::string& fileName,osg::Group* group,
44 float priority, const osg::FrameStamp* framestamp)
46 simgear::SGPagedLOD *sgplod = dynamic_cast<simgear::SGPagedLOD*>(group);
48 DatabasePager::requestNodeFile(fileName,group,priority,framestamp,sgplod->getReaderWriterOptions());
50 DatabasePager::requestNodeFile(fileName,group,priority,framestamp);
53 void SceneryPager::queueRequest(const std::string& fileName, osg::Group* group,
54 float priority, osg::FrameStamp* frameStamp)
56 _pagerRequests.push_back(PagerRequest(fileName, group, priority,
60 void SceneryPager::queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr)
62 _deleteRequests.push_back(objptr);
65 void SceneryPager::signalEndFrame()
68 bool areDeleteRequests = false;
69 bool arePagerRequests = false;
70 if (!_deleteRequests.empty()) {
71 areDeleteRequests = true;
72 OpenThreads::ScopedLock<OpenThreads::Mutex>
73 lock(_childrenToDeleteListMutex);
74 _childrenToDeleteList.insert(_childrenToDeleteList.end(),
75 _deleteRequests.begin(),
76 _deleteRequests.end());
77 _deleteRequests.clear();
79 if (!_pagerRequests.empty()) {
80 arePagerRequests = true;
81 for_each(_pagerRequests.begin(), _pagerRequests.end(),
82 bind2nd(mem_fun_ref(&PagerRequest::doRequest), this));
83 _pagerRequests.clear();
85 if (areDeleteRequests && !arePagerRequests)
86 updateDatabasePagerThreadBlock();
87 DatabasePager::signalEndFrame();