From fff2fa1718c3de81fde8864b59a4927b9a961559 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 11 Aug 2020 11:44:29 +0100 Subject: [PATCH] Raw-pointer -> smarter pointer in TileMgr Not fixing any leaks, just making ownership more explicit. --- src/Scenery/tilemgr.cxx | 25 ++++++++++++------------- src/Scenery/tilemgr.hxx | 6 ++---- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index f08d97c88..476024b5f 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -138,8 +138,6 @@ FGTileMgr::FGTileMgr(): state( Start ), last_state( Running ), scheduled_visibility(100.0), - _terra_sync(NULL), - _listener(NULL), _visibilityMeters(fgGetNode("/environment/visibility-m", true)), _lodDetailed(fgGetNode("/sim/rendering/static-lod/detailed", true)), _lodRoughDelta(fgGetNode("/sim/rendering/static-lod/rough-delta", true)), @@ -165,8 +163,7 @@ void FGTileMgr::init() void FGTileMgr::shutdown() { - delete _listener; - _listener = NULL; + _listener.reset(); FGScenery* scenery = globals->get_scenery(); if (scenery && scenery->get_terrain_branch()) { @@ -181,11 +178,11 @@ void FGTileMgr::shutdown() void FGTileMgr::reinit() { SG_LOG( SG_TERRAIN, SG_INFO, "Initializing Tile Manager subsystem." ); - _terra_sync = static_cast (globals->get_subsystem("terrasync")); + auto terraSync = globals->get_subsystem(); - // drops the previous options reference + // drops the previous options reference _options = new simgear::SGReaderWriterOptions; - _listener = new TileManagerListener(this); + _listener.reset(new TileManagerListener(this)); materialLibChanged(); _options->setPropertyNode(globals->get_props()); @@ -198,8 +195,8 @@ void FGTileMgr::reinit() } _options->setPluginStringData("SimGear::FG_ROOT", globals->get_fg_root().utf8Str()); - if (_terra_sync) { - _options->setPluginStringData("SimGear::TERRASYNC_ROOT", globals->get_terrasync_dir().utf8Str()); + if (terraSync) { + _options->setPluginStringData("SimGear::TERRASYNC_ROOT", globals->get_terrasync_dir().utf8Str()); } if (!_disableNasalHooks->getBoolValue()) @@ -353,6 +350,7 @@ void FGTileMgr::schedule_needed(const SGBucket& curr_bucket, double vis) SGBucket b; int x, y; + auto terraSync = globals->get_subsystem(); /* schedule all tiles, use distance-based loading priority, * so tiles are loaded in innermost-to-outermost sequence. */ @@ -368,8 +366,8 @@ void FGTileMgr::schedule_needed(const SGBucket& curr_bucket, double vis) float priority = (-1.0) * (x*x+y*y); sched_tile( b, priority, true, 0.0 ); - if (_terra_sync) { - _terra_sync->scheduleTile(b); + if (terraSync) { + terraSync->scheduleTile(b); } } } @@ -622,7 +620,8 @@ bool FGTileMgr::isSceneryLoaded() bool FGTileMgr::isTileDirSyncing(const std::string& tileFileName) const { - if (!_terra_sync) { + auto terraSync = globals->get_subsystem(); + if (!terraSync) { return false; } @@ -630,5 +629,5 @@ bool FGTileMgr::isTileDirSyncing(const std::string& tileFileName) const long int bucketIndex = simgear::strutils::to_int(nameWithoutExtension); SGBucket bucket(bucketIndex); - return _terra_sync->isTileDirPending(bucket.gen_base_path()); + return terraSync->isTileDirPending(bucket.gen_base_path()); } diff --git a/src/Scenery/tilemgr.hxx b/src/Scenery/tilemgr.hxx index 40a83517c..810a1d7dc 100644 --- a/src/Scenery/tilemgr.hxx +++ b/src/Scenery/tilemgr.hxx @@ -37,7 +37,6 @@ class Node; namespace simgear { -class SGTerraSync; class SGReaderWriterOptions; } @@ -73,12 +72,11 @@ private: * tile cache */ TileCache tile_cache; - simgear::SGTerraSync* _terra_sync; class TileManagerListener; friend class TileManagerListener; - TileManagerListener* _listener; - + std::unique_ptr _listener; + // update various queues internal queues void update_queues(bool& isDownloadingScenery);