Skip to content

Commit

Permalink
Update terrain engine usage of options to be more dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Oct 11, 2023
1 parent 4b47831 commit 946f39b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 63 deletions.
11 changes: 1 addition & 10 deletions src/osgEarthDrivers/engine_rex/RexTerrainEngineNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/osgEarthDrivers/engine_rex/TileNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
46 changes: 3 additions & 43 deletions src/osgEarthDrivers/engine_rex/Unloader
Original file line number Diff line number Diff line change
Expand Up @@ -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<TileKey>& 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<osg::observer_ptr<TileNode> > _deadpool;
unsigned _frameLastUpdated;
Expand Down
19 changes: 10 additions & 9 deletions src/osgEarthDrivers/engine_rex/Unloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand All @@ -60,16 +61,16 @@ 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:
_tiles->collectDormantTiles(
nv,
oldestAllowableTime,
oldestAllowableFrame,
_minRange,
_maxTilesToUnloadPerFrame,
_options.getMinExpiryRange(),
_options.getMaxTilesToUnloadPerFrame(),
_deadpool);

// Remove them from the scene graph:
Expand Down

0 comments on commit 946f39b

Please sign in to comment.