2010-11-19 12:59:43 +00:00
|
|
|
// SceneryPager.cxx -- Interface to OSG database pager
|
2007-12-15 06:01:24 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 2007 Tim Moore timoore@redhat.com
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2009-07-26 18:54:55 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2008-03-22 09:31:06 +00:00
|
|
|
#include <simgear/scene/model/SGPagedLOD.hxx>
|
2009-07-27 09:51:56 +00:00
|
|
|
#include <simgear/math/SGMath.hxx>
|
2007-12-14 22:51:56 +00:00
|
|
|
#include "SceneryPager.hxx"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
|
|
|
|
2008-06-02 21:10:13 +00:00
|
|
|
using namespace osg;
|
2007-12-14 22:51:56 +00:00
|
|
|
using namespace flightgear;
|
|
|
|
|
|
|
|
SceneryPager::SceneryPager()
|
|
|
|
{
|
|
|
|
_pagerRequests.reserve(48);
|
|
|
|
_deleteRequests.reserve(16);
|
2008-04-25 08:43:59 +00:00
|
|
|
setExpiryDelay(120.0);
|
2007-12-14 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SceneryPager::SceneryPager(const SceneryPager& rhs) :
|
|
|
|
DatabasePager(rhs)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneryPager::~SceneryPager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-02 21:10:13 +00:00
|
|
|
void SceneryPager::requestNodeFile(const std::string& fileName, Group* group,
|
2009-05-16 08:16:20 +00:00
|
|
|
float priority, const FrameStamp* framestamp,
|
|
|
|
ref_ptr<Referenced>& databaseRequest,
|
|
|
|
#if SG_OSG_MIN_VERSION_REQUIRED(2,9,5)
|
|
|
|
const osg::Referenced* options
|
|
|
|
#else
|
|
|
|
osgDB::ReaderWriter::Options* options
|
2008-06-02 21:10:13 +00:00
|
|
|
#endif
|
2009-05-16 08:16:20 +00:00
|
|
|
)
|
2008-03-22 09:31:06 +00:00
|
|
|
{
|
|
|
|
simgear::SGPagedLOD *sgplod = dynamic_cast<simgear::SGPagedLOD*>(group);
|
|
|
|
if(sgplod)
|
2008-06-02 21:10:13 +00:00
|
|
|
DatabasePager::requestNodeFile(fileName, group, priority, framestamp,
|
|
|
|
databaseRequest,
|
|
|
|
sgplod->getReaderWriterOptions());
|
2008-03-22 09:31:06 +00:00
|
|
|
else
|
2009-05-16 08:16:20 +00:00
|
|
|
DatabasePager::requestNodeFile(fileName, group, priority, framestamp,
|
|
|
|
databaseRequest,
|
|
|
|
options);
|
2008-03-22 09:31:06 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 21:10:13 +00:00
|
|
|
void SceneryPager::queueRequest(const std::string& fileName, Group* group,
|
|
|
|
float priority, FrameStamp* frameStamp,
|
|
|
|
ref_ptr<Referenced>& databaseRequest,
|
2008-05-14 22:10:07 +00:00
|
|
|
osgDB::ReaderWriter::Options* options)
|
2007-12-14 22:51:56 +00:00
|
|
|
{
|
|
|
|
_pagerRequests.push_back(PagerRequest(fileName, group, priority,
|
2008-06-02 21:10:13 +00:00
|
|
|
frameStamp,
|
|
|
|
databaseRequest,
|
|
|
|
options));
|
2007-12-14 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneryPager::queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr)
|
|
|
|
{
|
|
|
|
_deleteRequests.push_back(objptr);
|
|
|
|
objptr = 0;
|
|
|
|
}
|
|
|
|
void SceneryPager::signalEndFrame()
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
bool areDeleteRequests = false;
|
|
|
|
bool arePagerRequests = false;
|
|
|
|
if (!_deleteRequests.empty()) {
|
|
|
|
areDeleteRequests = true;
|
2008-06-02 21:10:13 +00:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex>
|
|
|
|
lock(_fileRequestQueue->_childrenToDeleteListMutex);
|
|
|
|
ObjectList& deleteList = _fileRequestQueue->_childrenToDeleteList;
|
|
|
|
deleteList.insert(deleteList.end(),
|
|
|
|
_deleteRequests.begin(),
|
|
|
|
_deleteRequests.end());
|
2007-12-14 22:51:56 +00:00
|
|
|
_deleteRequests.clear();
|
|
|
|
}
|
|
|
|
if (!_pagerRequests.empty()) {
|
|
|
|
arePagerRequests = true;
|
|
|
|
for_each(_pagerRequests.begin(), _pagerRequests.end(),
|
|
|
|
bind2nd(mem_fun_ref(&PagerRequest::doRequest), this));
|
|
|
|
_pagerRequests.clear();
|
|
|
|
}
|
2008-06-02 21:10:13 +00:00
|
|
|
if (areDeleteRequests && !arePagerRequests) {
|
|
|
|
_fileRequestQueue->updateBlock();
|
|
|
|
}
|
2007-12-14 22:51:56 +00:00
|
|
|
DatabasePager::signalEndFrame();
|
|
|
|
}
|
|
|
|
|