1
0
Fork 0

Changes for new DatabasePager interface in OSG 2.5.1

This commit is contained in:
timoore 2008-06-02 21:10:13 +00:00
parent 32e9505eed
commit 8d1c97d94b
4 changed files with 89 additions and 34 deletions

View file

@ -31,11 +31,8 @@
# error This library requires C++
#endif
#include <osg/Version>
#define FG_OSG_VERSION \
((OPENSCENEGRAPH_MAJOR_VERSION*10000)\
+ (OPENSCENEGRAPH_MINOR_VERSION*1000) + OPENSCENEGRAPH_PATCH_VERSION)
#include <simgear/structure/OSGVersion.hxx>
#define FG_OSG_VERSION SG_OSG_VERSION
// #define FANCY_FRAME_COUNTER
#ifdef FANCY_FRAME_COUNTER

View file

@ -21,9 +21,8 @@
#include <algorithm>
#include <functional>
using namespace osg;
using namespace flightgear;
using osg::ref_ptr;
using osg::Node;
SceneryPager::SceneryPager()
{
@ -41,22 +40,42 @@ SceneryPager::~SceneryPager()
{
}
void SceneryPager::requestNodeFile(const std::string& fileName,osg::Group* group,
float priority, const osg::FrameStamp* framestamp)
void SceneryPager::requestNodeFile(const std::string& fileName, Group* group,
float priority,
const FrameStamp* framestamp,
#ifdef FGOSGPAGER25
ref_ptr<Referenced>& databaseRequest
#endif
)
{
simgear::SGPagedLOD *sgplod = dynamic_cast<simgear::SGPagedLOD*>(group);
if(sgplod)
DatabasePager::requestNodeFile(fileName,group,priority,framestamp,sgplod->getReaderWriterOptions());
DatabasePager::requestNodeFile(fileName, group, priority, framestamp,
#ifdef FGOSGPAGER25
databaseRequest,
#endif
sgplod->getReaderWriterOptions());
else
DatabasePager::requestNodeFile(fileName,group,priority,framestamp);
DatabasePager::requestNodeFile(fileName, group, priority, framestamp,
#ifdef FGOSGPAGER25
databaseRequest
#endif
);
}
void SceneryPager::queueRequest(const std::string& fileName, osg::Group* group,
float priority, osg::FrameStamp* frameStamp,
void SceneryPager::queueRequest(const std::string& fileName, Group* group,
float priority, FrameStamp* frameStamp,
#ifdef FGOSGPAGER25
ref_ptr<Referenced>& databaseRequest,
#endif
osgDB::ReaderWriter::Options* options)
{
_pagerRequests.push_back(PagerRequest(fileName, group, priority,
frameStamp, options));
frameStamp,
#ifdef FGOSGPAGER25
databaseRequest,
#endif
options));
}
void SceneryPager::queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr)
@ -71,9 +90,16 @@ void SceneryPager::signalEndFrame()
bool arePagerRequests = false;
if (!_deleteRequests.empty()) {
areDeleteRequests = true;
#ifdef FGOSGPAGER25
OpenThreads::ScopedLock<OpenThreads::Mutex>
lock(_fileRequestQueue->_childrenToDeleteListMutex);
ObjectList& deleteList = _fileRequestQueue->_childrenToDeleteList;
#else
OpenThreads::ScopedLock<OpenThreads::Mutex>
lock(_childrenToDeleteListMutex);
_childrenToDeleteList.insert(_childrenToDeleteList.end(),
ObjectList& deleteList = _childrenToDeleteList;
#endif
deleteList.insert(deleteList.end(),
_deleteRequests.begin(),
_deleteRequests.end());
_deleteRequests.clear();
@ -84,8 +110,13 @@ void SceneryPager::signalEndFrame()
bind2nd(mem_fun_ref(&PagerRequest::doRequest), this));
_pagerRequests.clear();
}
if (areDeleteRequests && !arePagerRequests)
if (areDeleteRequests && !arePagerRequests) {
#ifdef FGOSGPAGER25
_fileRequestQueue->updateBlock();
#else
updateDatabasePagerThreadBlock();
#endif
}
DatabasePager::signalEndFrame();
}

View file

@ -26,6 +26,13 @@
#include <osg/Group>
#include <osgDB/DatabasePager>
#include <simgear/structure/OSGVersion.hxx>
// Pager request change in OpenSceneGraph 2.5.1
#if SG_OSG_VERSION >= 25001
#define FGOSGPAGER25
#endif
namespace flightgear
{
class SceneryPager : public osgDB::DatabasePager
@ -33,20 +40,22 @@ class SceneryPager : public osgDB::DatabasePager
public:
SceneryPager();
SceneryPager(const SceneryPager& rhs);
// Unhide DatabasePager::requestNodeFile
using osgDB::DatabasePager::requestNodeFile;
// reimplement to add readerWriterOptions from SGPagedLOD
virtual void requestNodeFile(const std::string& fileName,osg::Group* group,
float priority, const osg::FrameStamp* framestamp);
virtual void requestNodeFile(const std::string& fileName,osg::Group* group,
float priority, const osg::FrameStamp* framestamp,
osgDB::ReaderWriter::Options* options) {
osgDB::DatabasePager::requestNodeFile(fileName, group, priority,
framestamp, options);
}
virtual void requestNodeFile(const std::string& fileName, osg::Group* group,
float priority,
const osg::FrameStamp* framestamp,
#ifdef FGOSGPAGER25
osg::ref_ptr<osg::Referenced>&
databaseRequest
#endif
);
void queueRequest(const std::string& fileName, osg::Group* node,
float priority, osg::FrameStamp* frameStamp,
#ifdef FGOSGPAGER25
osg::ref_ptr<osg::Referenced>& databaseRequest,
#endif
osgDB::ReaderWriter::Options* options);
// This is passed a ref_ptr so that it can "take ownership" of the
// node to delete and decrement its refcount while holding the
@ -57,23 +66,36 @@ protected:
// Queue up file requests until the end of the frame
struct PagerRequest
{
PagerRequest() {}
PagerRequest() : _priority(0.0f), _databaseRequest(0) {}
PagerRequest(const PagerRequest& rhs) :
_fileName(rhs._fileName), _group(rhs._group),
_priority(rhs._priority), _frameStamp(rhs._frameStamp),
_options(rhs._options) {}
_options(rhs._options), _databaseRequest(rhs._databaseRequest) {}
PagerRequest(const std::string& fileName, osg::Group* group,
float priority, osg::FrameStamp* frameStamp,
#ifdef FGOSGPAGER25
osg::ref_ptr<Referenced>& databaseRequest,
#endif
osgDB::ReaderWriter::Options* options):
_fileName(fileName), _group(group), _priority(priority),
_frameStamp(frameStamp), _options(options) {}
_frameStamp(frameStamp), _options(options),
#ifdef FGOSGPAGER25
_databaseRequest(&databaseRequest)
#else
_databaseRequest(0)
#endif
{}
void doRequest(SceneryPager* pager)
{
if (_group->getNumChildren() == 0)
pager->requestNodeFile(_fileName, _group.get(), _priority,
_frameStamp.get(), _options.get());
_frameStamp.get(),
#ifdef FGOSGPAGER25
*_databaseRequest,
#endif
_options.get());
}
std::string _fileName;
@ -81,6 +103,7 @@ protected:
float _priority;
osg::ref_ptr<osg::FrameStamp> _frameStamp;
osg::ref_ptr<osgDB::ReaderWriter::Options> _options;
osg::ref_ptr<osg::Referenced>* _databaseRequest;
};
typedef std::vector<PagerRequest> PagerRequestList;
PagerRequestList _pagerRequests;

View file

@ -279,7 +279,11 @@ public:
_pager->queueRequest(entry->tileFileName,
entry->getNode(),
entry->get_inner_ring() ? 10.0f : 1.0f,
_framestamp, _options);
_framestamp,
#ifdef FGOSGPAGER25
entry->getDatabaseRequest(),
#endif
_options);
}
}
private: