diff --git a/src/GUI/gui_local.cxx b/src/GUI/gui_local.cxx index d4d6cab2b..6eee5d570 100644 --- a/src/GUI/gui_local.cxx +++ b/src/GUI/gui_local.cxx @@ -83,7 +83,7 @@ void reInit(puObject *cb) fgReInitSubsystems(); - global_tile_mgr.update( fgGetDouble("/environment/visibility-m") ); + globals->get_tile_mgr()->update( fgGetDouble("/environment/visibility-m") ); cur_light_params.Update(); diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index bb5368183..e8acfcea0 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -237,7 +237,7 @@ do_view_next( bool ) globals->get_current_view()->setHeadingOffset_deg(0.0); globals->get_viewmgr()->next_view(); fix_hud_visibility(); - global_tile_mgr.refresh_view_timestamps(); + globals->get_tile_mgr()->refresh_view_timestamps(); } void @@ -246,7 +246,7 @@ do_view_prev( bool ) globals->get_current_view()->setHeadingOffset_deg(0.0); globals->get_viewmgr()->prev_view(); fix_hud_visibility(); - global_tile_mgr.refresh_view_timestamps(); + globals->get_tile_mgr()->refresh_view_timestamps(); } /** @@ -258,7 +258,7 @@ do_view_cycle (const SGPropertyNode * arg) globals->get_current_view()->setHeadingOffset_deg(0.0); globals->get_viewmgr()->next_view(); fix_hud_visibility(); - global_tile_mgr.refresh_view_timestamps(); + globals->get_tile_mgr()->refresh_view_timestamps(); // fgReshape(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize")); return true; } @@ -288,10 +288,10 @@ do_tile_cache_reload (const SGPropertyNode * arg) fgSetBool("/sim/freeze/master", true); } // BusyCursor(0); - if ( global_tile_mgr.init() ) { + if ( globals->get_tile_mgr()->init() ) { // Load the local scenery data double visibility_meters = fgGetDouble("/environment/visibility-m"); - global_tile_mgr.update( visibility_meters ); + globals->get_tile_mgr()->update( visibility_meters ); } else { SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" ); @@ -607,7 +607,7 @@ do_presets_commit (const SGPropertyNode * arg) // BusyCursor(0); fgReInitSubsystems(); - global_tile_mgr.update( fgGetDouble("/environment/visibility-m") ); + globals->get_tile_mgr()->update( fgGetDouble("/environment/visibility-m") ); if ( ! fgGetBool("/sim/presets/onground") ) { fgSetBool( "/sim/freeze/master", true ); diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index ec7e640e1..790811dc4 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1264,11 +1264,11 @@ bool fgInitSubsystems() { // Initialize the scenery management subsystem. //////////////////////////////////////////////////////////////////// - if ( global_tile_mgr.init() ) { + if ( globals->get_tile_mgr()->init() ) { // Load the local scenery data double visibility_meters = fgGetDouble("/environment/visibility-m"); - global_tile_mgr.update( visibility_meters ); + globals->get_tile_mgr()->update( visibility_meters ); } else { SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" ); exit(-1); @@ -1276,7 +1276,8 @@ bool fgInitSubsystems() { // cause refresh of viewer scenery timestamps every 15 seconds... global_events.Register( "FGTileMgr::refresh_view_timestamps()", - &global_tile_mgr, &FGTileMgr::refresh_view_timestamps, + globals->get_tile_mgr(), + &FGTileMgr::refresh_view_timestamps, 15000 ); SG_LOG( SG_GENERAL, SG_DEBUG, diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 7cadcdcd0..e92cd7b7c 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -47,30 +47,32 @@ typedef vector string_list; class SGEphemeris; +class SGCommandMgr; class SGMagVar; +class SGPropertyNode; class SGRoute; class SGTime; -class SGPropertyNode; -class SGCommandMgr; -class FGSubsystemMgr; -class FGEnvironmentMgr; -class FGEnvironment; -class FGControls; -class FGSteam; -class FGSoundMgr; -class FGAutopilot; -class FGViewMgr; -class FGViewer; +class FGAIMgr; class FGATCMgr; class FGATCDisplay; -class FGAIMgr; -class FGModelLoader; -class FGTextureLoader; class FGAircraftModel; +class FGAutopilot; +class FGControls; +class FGEnvironment; +class FGEnvironmentMgr; +class FGIO; +class FGModelLoader; class FGModelMgr; class FGScenery; -class FGIO; +class FGSoundMgr; +class FGSteam; +class FGSubsystemMgr; +class FGTextureLoader; +class FGTileMgr; +class FGViewMgr; +class FGViewer; + /** * Bucket for subsystem pointers representing the sim's state. @@ -166,6 +168,9 @@ private: // FlightGear scenery manager FGScenery *scenery; + // Tile manager + FGTileMgr *tile_mgr; + FGIO* io; public: @@ -290,6 +295,9 @@ public: inline FGScenery * get_scenery () const { return scenery; } inline void set_scenery ( FGScenery *s ) { scenery = s; } + inline FGTileMgr * get_tile_mgr () const { return tile_mgr; } + inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; } + FGIO* get_io() const { return io; } /** diff --git a/src/Main/location.hxx b/src/Main/location.hxx index b3aad326e..f7f60c782 100644 --- a/src/Main/location.hxx +++ b/src/Main/location.hxx @@ -31,7 +31,6 @@ #include #include -#include #include #include // plib include @@ -112,10 +111,6 @@ public: void set_cur_elev_m ( double elev ) { _cur_elev_m = elev; } inline double get_cur_elev_m () { return _cur_elev_m; } // Interface to current buckets for use with tilemgr... - void set_current_bucket ( SGBucket current_bucket ) { _current_bucket = current_bucket; } - inline SGBucket get_current_bucket () { return _current_bucket; } - void set_previous_bucket ( SGBucket previous_bucket ) { _previous_bucket = previous_bucket; } - inline SGBucket get_previous_bucket () { return _previous_bucket; } void set_tile_center ( Point3D tile_center ) { _tile_center = tile_center; } inline Point3D get_tile_center () { return _tile_center; } @@ -149,10 +144,6 @@ private: // elevation of ground under this location... double _cur_elev_m; - // current and previous scenery buckets to be saved for use in - // getting current elevation from tilemgr. - SGBucket _previous_bucket; - SGBucket _current_bucket; Point3D _tile_center; // surface vector heading south diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 8edb7bd7d..abb47fe1c 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -699,11 +699,6 @@ void fgRenderFrame() { } # endif - // position tile nodes and update range selectors - - // this is done in the main loop now... - // global_tile_mgr.prep_ssg_nodes(visibility_meters); - if ( fgGetBool("/sim/rendering/skyblend") ) { // draw the sky backdrop @@ -1208,42 +1203,34 @@ static void fgMainLoop( void ) { // ...only if location is different than the viewer (to avoid duplicating effort) if( acmodel_location != current_view->getFGLocation() ) { if( acmodel_location != 0 ) { - global_tile_mgr.prep_ssg_nodes( acmodel_location, visibility_meters ); - global_tile_mgr.update( acmodel_location, visibility_meters, - acmodel_location->get_absolute_view_pos(), - acmodel_location->get_current_bucket(), - acmodel_location->get_previous_bucket(), - globals->get_scenery()->get_center() - ); + globals->get_tile_mgr()->prep_ssg_nodes( acmodel_location, + visibility_meters ); + globals->get_tile_mgr()-> + update( acmodel_location, visibility_meters, + acmodel_location->get_absolute_view_pos() ); // save results of update in FGLocation for fdm... if ( globals->get_scenery()->get_cur_elev() > -9990 ) { - acmodel_location->set_cur_elev_m( globals->get_scenery()->get_cur_elev() ); + acmodel_location-> + set_cur_elev_m( globals->get_scenery()->get_cur_elev() ); } - acmodel_location->set_current_bucket( global_tile_mgr.get_current_bucket() ); - acmodel_location->set_previous_bucket( global_tile_mgr.get_previous_bucket() ); - acmodel_location->set_tile_center( globals->get_scenery()->get_next_center() ); + acmodel_location-> + set_tile_center( globals->get_scenery()->get_next_center() ); } } - global_tile_mgr.prep_ssg_nodes( current_view->getFGLocation(), - visibility_meters ); + globals->get_tile_mgr()->prep_ssg_nodes( current_view->getFGLocation(), + visibility_meters ); // update tile manager for view... // IMPORTANT!!! the tilemgr update for view location _must_ be done last // after the FDM's until all of Flight Gear code references the viewer's location // for elevation instead of the "scenery's" current elevation. FGLocation *view_location = globals->get_current_view()->getFGLocation(); - global_tile_mgr.update( view_location, visibility_meters, - current_view->get_absolute_view_pos(), - current_view->getFGLocation()->get_current_bucket(), - current_view->getFGLocation()->get_previous_bucket(), - globals->get_scenery()->get_center() - ); + globals->get_tile_mgr()->update( view_location, visibility_meters, + current_view->get_absolute_view_pos() ); // save results of update in FGLocation for fdm... if ( globals->get_scenery()->get_cur_elev() > -9990 ) { current_view->getFGLocation()->set_cur_elev_m( globals->get_scenery()->get_cur_elev() ); } - current_view->getFGLocation()->set_current_bucket( global_tile_mgr.get_current_bucket() ); - current_view->getFGLocation()->set_previous_bucket( global_tile_mgr.get_previous_bucket() ); current_view->getFGLocation()->set_tile_center( globals->get_scenery()->get_next_center() ); // If fdm location is same as viewer's then we didn't do the update for fdm location @@ -1253,8 +1240,6 @@ static void fgMainLoop( void ) { if ( globals->get_scenery()->get_cur_elev() > -9990 ) { acmodel_location->set_cur_elev_m( globals->get_scenery()->get_cur_elev() ); } - acmodel_location->set_current_bucket( global_tile_mgr.get_current_bucket() ); - acmodel_location->set_previous_bucket( global_tile_mgr.get_previous_bucket() ); acmodel_location->set_tile_center( globals->get_scenery()->get_next_center() ); } } @@ -1640,6 +1625,9 @@ static bool fgMainInit( int argc, char **argv ) { globals->get_scenery()->init(); globals->get_scenery()->bind(); + // Initialize the global tile manager + globals->set_tile_mgr( new FGTileMgr ); + //////////////////////////////////////////////////////////////////// // Initialize the property-based built-in commands //////////////////////////////////////////////////////////////////// diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index c1e760609..f0b8ae7dc 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -53,10 +53,6 @@ #define TEST_LAST_HIT_CACHE -// the tile manager -FGTileMgr global_tile_mgr; - - #ifdef ENABLE_THREADS SGLockedQueue FGTileMgr::attach_queue; SGLockedQueue FGTileMgr::model_queue; @@ -364,30 +360,30 @@ int FGTileMgr::update( double visibility_meters ) sgdVec3 abs_pos_vector; sgdCopyVec3( abs_pos_vector, globals->get_current_view()->get_absolute_view_pos() ); - return update( location, visibility_meters, abs_pos_vector, - current_bucket, previous_bucket, - globals->get_scenery()->get_center() ); + return update( location, visibility_meters, abs_pos_vector ); } int FGTileMgr::update( FGLocation *location, double visibility_meters, - sgdVec3 abs_pos_vector, SGBucket p_current, - SGBucket p_previous, Point3D center ) + sgdVec3 abs_pos_vector ) { - // SG_LOG( SG_TERRAIN, SG_DEBUG, "FGTileMgr::update() for " - // << lon << " " << lat ); - longitude = location->getLongitude_deg(); latitude = location->getLatitude_deg(); - current_bucket = p_current; - previous_bucket = p_previous; + // SG_LOG( SG_TERRAIN, SG_DEBUG, "FGTileMgr::update() for " + // << longitude << " " << latatitude ); - // SG_LOG( SG_TERRAIN, SG_DEBUG, "lon "<< lonlat[LON] << - // " lat " << lonlat[LAT] ); + current_bucket.set_bucket( longitude, latitude ); + // SG_LOG( SG_TERRAIN, SG_DEBUG, "Updating tile list for " + // << current_bucket ); - // SG_LOG( SG_TERRAIN, SG_DEBUG, "Updating Tile list for " << current_bucket ); - - setCurrentTile( longitude, latitude); + // set global scenery center from current tile center + current_tile = tile_cache.get_tile( current_bucket ); + if ( current_tile != NULL ) { + globals->get_scenery()->set_next_center( current_tile->center ); + } else { + SG_LOG( SG_TERRAIN, SG_WARN, "Tile not found (Ok if initializing)" ); + globals->get_scenery()->set_next_center( Point3D(0.0) ); + } // do tile load scheduling. // Note that we need keep track of both viewer buckets and fdm buckets. @@ -416,7 +412,9 @@ int FGTileMgr::update( FGLocation *location, double visibility_meters, // no reason to update this if we haven't moved... if ( longitude != last_longitude || latitude != last_latitude ) { // update current elevation... - if ( updateCurrentElevAtPos( abs_pos_vector, center ) ) { + if ( updateCurrentElevAtPos( abs_pos_vector, + globals->get_scenery()->get_center() ) ) + { last_longitude = longitude; last_latitude = latitude; } @@ -425,6 +423,7 @@ int FGTileMgr::update( FGLocation *location, double visibility_meters, return 1; } + // timer event driven call to scheduler for the purpose of refreshing the tile timestamps void FGTileMgr::refresh_view_timestamps() { SG_LOG( SG_TERRAIN, SG_INFO, @@ -434,21 +433,6 @@ void FGTileMgr::refresh_view_timestamps() { } -// check and set current tile and scenery center... -void FGTileMgr::setCurrentTile(double longitude, double latitude) { - - // check tile cache entry... - current_bucket.set_bucket( longitude, latitude ); - if ( tile_cache.exists( current_bucket ) ) { - current_tile = tile_cache.get_tile( current_bucket ); - globals->get_scenery()->set_next_center( current_tile->center ); - } else { - SG_LOG( SG_TERRAIN, SG_WARN, "Tile not found (Ok if initializing)" ); - globals->get_scenery()->set_next_center( Point3D(0.0) ); - } -} - - int FGTileMgr::updateCurrentElevAtPos(sgdVec3 abs_pos_vector, Point3D center) { sgdVec3 sc; diff --git a/src/Scenery/tilemgr.hxx b/src/Scenery/tilemgr.hxx index 160dc583d..1eb97e701 100644 --- a/src/Scenery/tilemgr.hxx +++ b/src/Scenery/tilemgr.hxx @@ -165,9 +165,8 @@ public: // read it from disk. int update( double visibility_meters ); int update( FGLocation *location, double visibility_meters, - sgdVec3 abs_pos_vector, SGBucket p_current, - SGBucket p_previous, Point3D center ); - void setCurrentTile( double longitude, double latitude ); + sgdVec3 abs_pos_vector ); + int updateCurrentElevAtPos(sgdVec3 abs_pos_vector, Point3D center ); // Determine scenery altitude. Normally this just happens when we @@ -196,8 +195,4 @@ public: }; -// the tile manager -extern FGTileMgr global_tile_mgr; - - #endif // _TILEMGR_HXX