From 946f39b027c81c19ff4a7fc4c4d829aacb7dc413 Mon Sep 17 00:00:00 2001 From: Glenn Waldron Date: Wed, 11 Oct 2023 15:30:47 -0400 Subject: [PATCH] Update terrain engine usage of options to be more dynamic --- .../engine_rex/RexTerrainEngineNode.cpp | 11 +---- src/osgEarthDrivers/engine_rex/TileNode.cpp | 4 +- src/osgEarthDrivers/engine_rex/Unloader | 46 ++----------------- src/osgEarthDrivers/engine_rex/Unloader.cpp | 19 ++++---- 4 files changed, 17 insertions(+), 63 deletions(-) diff --git a/src/osgEarthDrivers/engine_rex/RexTerrainEngineNode.cpp b/src/osgEarthDrivers/engine_rex/RexTerrainEngineNode.cpp index 962273b116..06a1a7a98d 100644 --- a/src/osgEarthDrivers/engine_rex/RexTerrainEngineNode.cpp +++ b/src/osgEarthDrivers/engine_rex/RexTerrainEngineNode.cpp @@ -319,12 +319,8 @@ RexTerrainEngineNode::setMap(const Map* map, const TerrainOptions& inOptions) JobArena::setConcurrency(ARENA_LOAD_TILE, concurrency); // Make a tile unloader - _unloader = new UnloaderGroup(_tiles.get()); + _unloader = new UnloaderGroup(_tiles.get(), getOptions()); _unloader->setFrameClock(&_clock); - _unloader->setMaxAge(options().minExpiryTime().get()); - _unloader->setMaxTilesToUnloadPerFrame(options().maxTilesToUnloadPerFrame().get()); - _unloader->setMinResidentTiles(options().minResidentTiles().get()); - _unloader->setMinimumRange(options().minExpiryRange().get()); this->addChild(_unloader.get()); // Initialize the core render bindings. @@ -756,11 +752,6 @@ RexTerrainEngineNode::dirtyTerrainOptions() { JobArena::setConcurrency(ARENA_LOAD_TILE, options().concurrency().get()); } - - _unloader->setMaxAge(options().minExpiryTime().get()); - _unloader->setMaxTilesToUnloadPerFrame(options().maxTilesToUnloadPerFrame().get()); - _unloader->setMinResidentTiles(options().minResidentTiles().get()); - _unloader->setMinimumRange(options().minExpiryRange().get()); } void diff --git a/src/osgEarthDrivers/engine_rex/TileNode.cpp b/src/osgEarthDrivers/engine_rex/TileNode.cpp index 5c11a33816..083c362725 100644 --- a/src/osgEarthDrivers/engine_rex/TileNode.cpp +++ b/src/osgEarthDrivers/engine_rex/TileNode.cpp @@ -361,7 +361,9 @@ TileNode::shouldSubDivide(TerrainCuller* culler, const SelectionInfo& selectionI EngineContext* context = culler->getEngineContext(); - if (currLOD < selectionInfo.getNumLODs() && currLOD != selectionInfo.getNumLODs()-1) + if (currLOD < selectionInfo.getNumLODs() && + currLOD != selectionInfo.getNumLODs()-1 && + currLOD < _context->options().getMaxLOD()) { // In PSOS mode, subdivide when the on-screen size of a tile exceeds the maximum // allowable on-screen tile size in pixels. diff --git a/src/osgEarthDrivers/engine_rex/Unloader b/src/osgEarthDrivers/engine_rex/Unloader index a5e7a77bc9..e9c5f4d0da 100644 --- a/src/osgEarthDrivers/engine_rex/Unloader +++ b/src/osgEarthDrivers/engine_rex/Unloader @@ -36,56 +36,16 @@ namespace osgEarth { namespace REX { public: //! Construct an unloader for a registry - UnloaderGroup(TileNodeRegistry* tiles); - - //! A Tile must be at least this old before it can be removed: - void setMaxAge(double value) { - _maxAge = std::max(value, 1.0); - } - double getMaxAge() const { - return _maxAge; - } - - //! Maximum number of tiles to expire per frame - void setMaxTilesToUnloadPerFrame(unsigned value) { - _maxTilesToUnloadPerFrame = value; - } - unsigned getMaxTilesToUnloadPerFrame() const { - return _maxTilesToUnloadPerFrame; - } - - //! A Tile must be at least this far from the camera before it can be unloaded: - void setMinimumRange(float value) { - _minRange = std::max(value, 0.0f); - } - float getMinimumRange() const { - return _minRange; - } - - //! The engine may keep at least this many tiles in memory - //! before disposing anything - void setMinResidentTiles(unsigned value) { - _minResidentTiles = value; - } - unsigned getMinResidentTiles() const { - return _minResidentTiles; - } + UnloaderGroup(TileNodeRegistry* tiles, const TerrainOptionsAPI& options); //! Set the frame clock to use void setFrameClock(const FrameClock* value) { _clock = value; } - public: // Unloader - - //void unloadChildren(const std::vector& keys); - public: // osg::Node - void traverse(osg::NodeVisitor& nv); + void traverse(osg::NodeVisitor& nv) override; protected: - unsigned _minResidentTiles; - double _maxAge; - float _minRange; - unsigned _maxTilesToUnloadPerFrame; + TerrainOptionsAPI _options; TileNodeRegistry* _tiles; std::vector > _deadpool; unsigned _frameLastUpdated; diff --git a/src/osgEarthDrivers/engine_rex/Unloader.cpp b/src/osgEarthDrivers/engine_rex/Unloader.cpp index 44c3352cd8..7af22c377a 100644 --- a/src/osgEarthDrivers/engine_rex/Unloader.cpp +++ b/src/osgEarthDrivers/engine_rex/Unloader.cpp @@ -29,12 +29,13 @@ using namespace osgEarth::REX; -UnloaderGroup::UnloaderGroup(TileNodeRegistry* tiles) : +UnloaderGroup::UnloaderGroup(TileNodeRegistry* tiles, const TerrainOptionsAPI& api) : + _options(api), _tiles(tiles), - _minResidentTiles(0u), - _maxAge(0.1), - _minRange(0.0f), - _maxTilesToUnloadPerFrame(~0), + //_minResidentTiles(0u), + //_maxAge(0.1), + //_minRange(0.0f), + //_maxTilesToUnloadPerFrame(~0), _frameLastUpdated(0u) { ADJUST_UPDATE_TRAV_COUNT(this, +1); @@ -48,7 +49,7 @@ UnloaderGroup::traverse(osg::NodeVisitor& nv) unsigned frame = _clock->getFrame(); bool runUpdate = (_frameLastUpdated < frame); - if (runUpdate && _tiles->size() > _minResidentTiles) + if (runUpdate && _tiles->size() > _options.getMinResidentTiles()) { _frameLastUpdated = frame; @@ -60,7 +61,7 @@ UnloaderGroup::traverse(osg::NodeVisitor& nv) // Have to enforce both the time delay AND a frame delay since the frames can // stop while the time rolls on (e.g., if you are dragging the window) - double oldestAllowableTime = now - _maxAge; + double oldestAllowableTime = now - _options.getMinExpiryTime(); unsigned oldestAllowableFrame = osg::maximum(frame, 3u) - 3u; // Remove them from the registry: @@ -68,8 +69,8 @@ UnloaderGroup::traverse(osg::NodeVisitor& nv) nv, oldestAllowableTime, oldestAllowableFrame, - _minRange, - _maxTilesToUnloadPerFrame, + _options.getMinExpiryRange(), + _options.getMaxTilesToUnloadPerFrame(), _deadpool); // Remove them from the scene graph: