root/OpenSceneGraph/trunk/src/osg/ProxyNode.cpp @ 8325

Revision 8325, 3.2 kB (checked in by robert, 6 years ago)

Refactored DatabasePager? and related classes to introduce support for
multi-threaded paging, where the Pager manages threads of reading local
and http files via seperate threads. This makes it possible to smoothly
browse large databases where parts of the data are locally cached while
others are on a remote server. Previously with this type of dataset
the pager would stall all paging while http requests were being served,
even when parts of the models are still loadable virtue of being in the
local cache.

Also as part of the refactoring the DatabaseRequest? are now stored in the
ProxyNode?/PagedLOD nodes to facilitate quite updating in the cull traversal,
with the new code avoiding mutex locks and searches. Previous on big
databases the overhead involved in make database requests could accumulate
to a point where it'd cause the cull traversal to break frame. The overhead
now is negligable.

Finally OSG_FILE_CACHE support has been moved from the curl plugin into
the DatabasePager?. Eventually this functionality will be moved out into
osgDB for more general usage.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osg/ProxyNode>
15#include <osg/CullStack>
16#include <osg/Notify>
17
18using namespace osg;
19
20ProxyNode::ProxyNode() :
21    _loadingExtReference(LOAD_IMMEDIATELY),
22    _centerMode(USER_DEFINED_CENTER),
23    _radius(-1)
24{
25}
26
27ProxyNode::ProxyNode(const ProxyNode& proxynode,const CopyOp& copyop):
28    Group(proxynode,copyop),
29    _filenameList(proxynode._filenameList),
30    _loadingExtReference(proxynode._loadingExtReference),
31    _centerMode(proxynode._centerMode),
32    _userDefinedCenter(proxynode._userDefinedCenter),
33    _radius(proxynode._radius)
34{
35}
36
37void ProxyNode::setDatabasePath(const std::string& path)
38{
39    _databasePath = path;
40    if (!_databasePath.empty())
41    {
42        char& lastCharacter = _databasePath[_databasePath.size()-1];
43        const char unixSlash = '/';
44        const char winSlash = '\\';
45
46        if (lastCharacter==winSlash)
47        {
48            lastCharacter = unixSlash;
49        }
50        else if (lastCharacter!=unixSlash)
51        {
52            _databasePath += unixSlash;
53        }
54    }
55}
56
57void ProxyNode::traverse(NodeVisitor& nv)
58{
59    if (nv.getDatabaseRequestHandler() && _filenameList.size()>_children.size() &&
60        nv.getVisitorType()==NodeVisitor::CULL_VISITOR &&
61        _loadingExtReference!=NO_AUTOMATIC_LOADING)
62    {
63        for(unsigned int i=_children.size(); i<_filenameList.size(); ++i)
64        {
65            nv.getDatabaseRequestHandler()->requestNodeFile(_databasePath+_filenameList[i].first, this, 1.0f, nv.getFrameStamp(), _filenameList[i].second);
66        }
67    }
68    else
69    {
70        Group::traverse(nv);
71    }
72}
73
74void ProxyNode::expandFileNameListTo(unsigned int pos)
75{
76    if (pos>=_filenameList.size()) _filenameList.resize(pos+1);
77}
78
79bool ProxyNode::addChild( Node *child )
80{
81    if (Group::addChild(child))
82    {
83        expandFileNameListTo(_children.size()-1);
84        return true;
85    }
86    return false;
87}
88
89bool ProxyNode::addChild(Node *child, const std::string& filename)
90{
91    if (Group::addChild(child))
92    {
93        setFileName(_children.size()-1,filename);
94        return true;
95    }
96    return false;
97}
98
99bool ProxyNode::removeChildren(unsigned int pos,unsigned int numChildrenToRemove)
100{
101    if (pos<_filenameList.size()) _filenameList.erase(_filenameList.begin()+pos, osg::minimum(_filenameList.begin()+(pos+numChildrenToRemove), _filenameList.end()) );
102
103    return Group::removeChildren(pos,numChildrenToRemove);
104}
105
106BoundingSphere ProxyNode::computeBound() const
107{
108    if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f)
109    {
110        return BoundingSphere(_userDefinedCenter,_radius);
111    }
112    else
113    {
114        return Group::computeBound();
115    }
116}
117
Note: See TracBrowser for help on using the browser.