Changeset 13041 for OpenSceneGraph/trunk/include/osgDB/DatabasePager
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osgDB/DatabasePager (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgDB/DatabasePager
r12990 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 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 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 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 45 45 46 46 47 /** Database paging class which manages the loading of files in a background thread, 47 /** Database paging class which manages the loading of files in a background thread, 48 48 * and synchronizing of loaded models with the main scene graph.*/ 49 49 class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandler … … 64 64 /** get the prototype singleton used by DatabasePager::create().*/ 65 65 static osg::ref_ptr<DatabasePager>& prototype(); 66 66 67 67 /** create a DatabasePager by cloning DatabasePager::prototype().*/ 68 68 static DatabasePager* create(); 69 69 70 70 71 71 72 72 /** Add a request to load a node file to end the the database request list.*/ … … 79 79 int setSchedulePriority(OpenThreads::Thread::ThreadPriority priority); 80 80 81 /** Cancel the database pager thread(s).*/ 81 /** Cancel the database pager thread(s).*/ 82 82 virtual int cancel(); 83 83 84 84 virtual bool isRunning() const; 85 85 86 86 /** Clear all internally cached structures.*/ 87 87 virtual void clear(); 88 88 89 89 class OSGDB_EXPORT DatabaseThread : public osg::Referenced, public OpenThreads::Thread 90 90 { 91 91 public: 92 92 93 93 enum Mode 94 94 { … … 97 97 HANDLE_ONLY_HTTP 98 98 }; 99 99 100 100 DatabaseThread(DatabasePager* pager, Mode mode, const std::string& name); 101 101 102 102 DatabaseThread(const DatabaseThread& dt, DatabasePager* pager); 103 103 … … 107 107 void setDone(bool done) { _done.exchange(done?1:0); } 108 108 bool getDone() const { return _done!=0; } 109 109 110 110 void setActive(bool active) { _active = active; } 111 111 bool getActive() const { return _active; } 112 112 113 113 virtual int cancel(); 114 114 115 115 virtual void run(); 116 116 117 117 protected: 118 118 119 119 virtual ~DatabaseThread(); 120 120 121 121 OpenThreads::Atomic _done; 122 122 volatile bool _active; … … 126 126 127 127 }; 128 128 129 129 void setUpThreads(unsigned int totalNumThreads=2, unsigned int numHttpThreads=1); 130 130 … … 132 132 133 133 DatabaseThread* getDatabaseThread(unsigned int i) { return _databaseThreads[i].get(); } 134 134 135 135 const DatabaseThread* getDatabaseThread(unsigned int i) const { return _databaseThreads[i].get(); } 136 136 137 137 unsigned int getNumDatabaseThreads() const { return _databaseThreads.size(); } 138 138 139 139 /** Set whether the database pager thread should be paused or not.*/ 140 140 void setDatabasePagerThreadPause(bool pause); 141 141 142 142 /** Get whether the database pager thread should is paused or not.*/ 143 143 bool getDatabasePagerThreadPause() const { return _databasePagerThreadPaused; } 144 144 145 145 /** Set whether new database request calls are accepted or ignored.*/ 146 146 void setAcceptNewDatabaseRequests(bool acceptNewRequests) { _acceptNewRequests = acceptNewRequests; } 147 147 148 148 /** Get whether new database request calls are accepted or ignored.*/ 149 149 bool getAcceptNewDatabaseRequests() const { return _acceptNewRequests; } 150 150 151 151 /** Get the number of frames that are currently active.*/ 152 152 int getNumFramesActive() const { return _numFramesActive; } … … 155 155 * Note, this is called by the application so that the database pager can go to sleep while the CPU is busy on the main rendering threads. */ 156 156 virtual void signalBeginFrame(const osg::FrameStamp* framestamp); 157 157 158 158 /** Signal the database thread that the update, cull and draw dispatch has completed. 159 159 * Note, this is called by the application so that the database pager can go to wake back up now the main rendering threads are iddle waiting for the next frame.*/ 160 160 virtual void signalEndFrame(); 161 162 163 /** Find all PagedLOD nodes in a subgraph and register them with 161 162 163 /** Find all PagedLOD nodes in a subgraph and register them with 164 164 * the DatabasePager so it can keep track of expired nodes. 165 165 * note, should be only be called from the update thread. */ … … 198 198 /** Set whether the removed subgraphs should be deleted in the database thread or not.*/ 199 199 void setDeleteRemovedSubgraphsInDatabaseThread(bool flag) { _deleteRemovedSubgraphsInDatabaseThread = flag; } 200 200 201 201 /** Get whether the removed subgraphs should be deleted in the database thread or not.*/ 202 202 bool getDeleteRemovedSubgraphsInDatabaseThread() const { return _deleteRemovedSubgraphsInDatabaseThread; } … … 240 240 /** Return true if there are pending updates to the scene graph that require a call to updateSceneGraph(double). */ 241 241 bool requiresUpdateSceneGraph() const; 242 242 243 243 /** Merge the changes to the scene graph by calling calling removeExpiredSubgraphs then addLoadedDataToSceneGraph. 244 244 * Note, must only be called from single thread update phase. */ … … 250 250 /** Report how many items are in the _dataToCompileList queue */ 251 251 unsigned int getDataToCompileListSize() const { return _dataToCompileList->size(); } 252 252 253 253 /** Report how many items are in the _dataToMergeList queue */ 254 254 unsigned int getDataToMergeListSize() const { return _dataToMergeList->size(); } … … 256 256 /** Report whether any requests are in the pager.*/ 257 257 bool getRequestsInProgress() const; 258 258 259 259 /** Get the minimum time between the first request for a tile to be loaded and the time of its merge into the main scene graph.*/ 260 260 double getMinimumTimeToMergeTile() const { return _minimumTimeToMergeTile; } … … 325 325 float _priorityLastRequest; 326 326 unsigned int _numOfRequests; 327 327 328 328 osg::observer_ptr<osg::Node> _terrain; 329 329 osg::observer_ptr<osg::Group> _group; … … 381 381 }; 382 382 383 383 384 384 typedef std::vector< osg::ref_ptr<DatabaseThread> > DatabaseThreadList; 385 385 … … 416 416 friend struct SortFileRequestFunctor; 417 417 418 418 419 419 OpenThreads::Mutex _run_mutex; 420 420 OpenThreads::Mutex _dr_mutex;
