]> git.mxchange.org Git - flightgear.git/commitdiff
Updates to move scenery initialization earlier in the initialization
authorcurt <curt>
Sun, 23 Jul 2000 21:32:59 +0000 (21:32 +0000)
committercurt <curt>
Sun, 23 Jul 2000 21:32:59 +0000 (21:32 +0000)
sequence so that the FDM can know the current ground altitude when it is
initialized.

src/GUI/gui.cxx
src/Main/fg_init.cxx
src/Main/keyboard.cxx
src/Main/main.cxx
src/Scenery/scenery.cxx
src/Scenery/tilecache.cxx
src/Scenery/tilemgr.cxx
src/Scenery/tilemgr.hxx

index 23464e22a60d38bc3b066e2c97eed01cbd58bfd2..2a3d52254e5b267b39073e5d56a6fc49efc653ef 100644 (file)
@@ -1042,6 +1042,8 @@ void AptDialog_OK (puObject *)
         if ( airports.search( AptId, &a ) )
         {
             current_options.set_airport_id( AptId.c_str() );
+            current_options.set_altitude( -9999.0 );
+           fgSetPosFromAirportID( AptId );
             BusyCursor(0);
             fgReInitSubsystems();
             BusyCursor(1);
index 5fb58c971fc62de85a42a2e3100d548e93902d21..313776de7cb9550a3afa1a4907d6d6b9cc9dbfb6 100644 (file)
@@ -188,17 +188,14 @@ bool fgInitPosition( void ) {
     FGInterface *f = current_aircraft.fdm_state;
     string id = current_options.get_airport_id();
 
-    if ( id.length() ) {
-       // set initial position from airport id
-       if ( ! fgSetPosFromAirportID( id ) ) {
-           exit(-1);
-       }
-    }
-
     // set initial position from default or command line coordinates
     f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
     f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
 
+    if ( scenery.cur_elev > current_options.get_altitude() - 2 ) {
+       current_options.set_altitude( scenery.cur_elev + 2 );
+    }
+
     FG_LOG( FG_GENERAL, FG_INFO,
            "starting altitude is = " << current_options.get_altitude() );
 
@@ -266,32 +263,6 @@ bool fgInitSubsystems( void ) {
     FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
     FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
 
-    if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
-       cur_fdm_state = new FGLaRCsim;
-    } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
-       cur_fdm_state = new FGJSBsim;
-    } else if ( current_options.get_flight_model() == 
-               FGInterface::FG_BALLOONSIM ) {
-       cur_fdm_state = new FGBalloonSim;
-    } else if ( current_options.get_flight_model() == 
-               FGInterface::FG_MAGICCARPET ) {
-       cur_fdm_state = new FGMagicCarpet;
-    } else if ( current_options.get_flight_model() == 
-               FGInterface::FG_EXTERNAL ) {
-       cur_fdm_state = new FGExternal;
-    } else {
-       FG_LOG( FG_GENERAL, FG_ALERT,
-               "No flight model, can't init aircraft" );
-       exit(-1);
-    }
-
-    // allocates structures so must happen before any of the flight
-    // model or control parameters are set
-    fgAircraftInit();   // In the future this might not be the case.
-
-    // set the initial position
-    fgInitPosition();
-
     // Initialize the material property lib
     FGPath mpath( current_options.get_fg_root() );
     mpath.append( "materials" );
@@ -309,10 +280,10 @@ bool fgInitSubsystems( void ) {
        exit(-1);
     }
 
-    if( global_tile_mgr.init() ) {
+    if ( global_tile_mgr.init() ) {
        // Load the local scenery data
-       global_tile_mgr.update( cur_fdm_state->get_Longitude(),
-                               cur_fdm_state->get_Latitude() );
+       global_tile_mgr.update( current_options.get_lon(),
+                               current_options.get_lat() );
     } else {
        FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
        exit(-1);
@@ -322,6 +293,32 @@ bool fgInitSubsystems( void ) {
            "Current terrain elevation after tile mgr init " <<
            scenery.cur_elev );
 
+    if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
+       cur_fdm_state = new FGLaRCsim;
+    } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
+       cur_fdm_state = new FGJSBsim;
+    } else if ( current_options.get_flight_model() == 
+               FGInterface::FG_BALLOONSIM ) {
+       cur_fdm_state = new FGBalloonSim;
+    } else if ( current_options.get_flight_model() == 
+               FGInterface::FG_MAGICCARPET ) {
+       cur_fdm_state = new FGMagicCarpet;
+    } else if ( current_options.get_flight_model() == 
+               FGInterface::FG_EXTERNAL ) {
+       cur_fdm_state = new FGExternal;
+    } else {
+       FG_LOG( FG_GENERAL, FG_ALERT,
+               "No flight model, can't init aircraft" );
+       exit(-1);
+    }
+
+    // allocates structures so must happen before any of the flight
+    // model or control parameters are set
+    fgAircraftInit();   // In the future this might not be the case.
+
+    // set the initial position
+    fgInitPosition();
+
     // Calculate ground elevation at starting point (we didn't have
     // tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
     //
@@ -613,15 +610,18 @@ void fgReInitSubsystems( void )
     if( !freeze )
         globals->set_freeze( true );
     
-    fgInitPosition();
     if( global_tile_mgr.init() ) {
        // Load the local scenery data
-       global_tile_mgr.update( cur_fdm_state->get_Longitude(),
-                               cur_fdm_state->get_Latitude() );
+       global_tile_mgr.update( current_options.get_lon(),
+                               current_options.get_lat() );
     } else {
        FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
                exit(-1);
     }
+
+    // cout << "current scenery elev = " << scenery.cur_elev << endl;
+
+    fgInitPosition();
     fgFDMSetGroundElevation( current_options.get_flight_model(), 
                             scenery.cur_elev );
 
index ddf52d44b8d32f9012fafd63f07c4ca6fd80369f..dc52097a2a2cbef9cc746590b7875780760c1f7f 100644 (file)
@@ -476,10 +476,11 @@ void GLUTspecialkey(int k, int x, int y) {
                if ( !freeze ) 
                    globals->set_freeze( true );
                BusyCursor(0);
-               if( global_tile_mgr.init() ) {
+               if ( global_tile_mgr.init() ) {
                    // Load the local scenery data
-                   global_tile_mgr.update( cur_fdm_state->get_Longitude(),
-                                           cur_fdm_state->get_Latitude() );
+                   global_tile_mgr.update( 
+                       cur_fdm_state->get_Longitude() * RAD_TO_DEG,
+                       cur_fdm_state->get_Latitude() * RAD_TO_DEG );
                } else {
                    FG_LOG( FG_GENERAL, FG_ALERT, 
                            "Error in Tile Manager initialization!" );
index bbac07348415be814e91ca15ac0e889c67bc55bf..1afd19c32322348f903fb4caaba7e9a63b8810bb 100644 (file)
@@ -879,8 +879,8 @@ static void fgMainLoop( void ) {
 #endif
 
     // see if we need to load any new scenery tiles
-    global_tile_mgr.update( cur_fdm_state->get_Longitude(),
-                           cur_fdm_state->get_Latitude() );
+    global_tile_mgr.update( cur_fdm_state->get_Longitude() * RAD_TO_DEG,
+                           cur_fdm_state->get_Latitude() * RAD_TO_DEG );
 
     // Process/manage pending events
     global_events.Process();
index e74a2ad245ff026d1edd9efe16d4d6008997a977..7f27a782dec1e714efcba56c1f2c3a4a83c3f9f0 100644 (file)
@@ -52,18 +52,11 @@ struct fgSCENERY scenery;
 
 // Initialize the Scenery Management system
 int fgSceneryInit( void ) {
-    fgOPTIONS *o;
-    // char path[1024], fgpath[1024];
-    // GLubyte *texbuf;
-    // int width, height;
-
-    o = &current_options;
-
     FG_LOG( FG_TERRAIN, FG_INFO, "Initializing scenery subsystem" );
 
     scenery.cur_elev = -9999;
 
-    return(1);
+    return 1;
 }
 
 
index b0f8d9be72f205a631e5fe8fcd5475baa2f39099..1bca11ee345213c08dcf8213f5894f1d014777c8 100644 (file)
@@ -114,7 +114,7 @@ FGTileCache::init( void )
     // and ... just in case we missed something ... 
     terrain->removeAllKids();
 
-    FG_LOG( FG_TERRAIN, FG_DEBUG, "  done with init()"  );
+    FG_LOG( FG_TERRAIN, FG_INFO, "  done with init()"  );
 }
 
 
index 56290a48f408e064a9c7c43c3b31529478f7c15a..7949a9b94329e3bf3833506ddccba7596dd5562d 100644 (file)
@@ -39,7 +39,7 @@
 #include <simgear/math/polar3d.hxx>
 #include <simgear/math/vector.hxx>
 
-#include <Aircraft/aircraft.hxx>
+// #include <Aircraft/aircraft.hxx>
 #include <Main/options.hxx>
 #include <Main/views.hxx>
 #include <Objects/obj.hxx>
@@ -88,7 +88,7 @@ int FGTileMgr::init( void ) {
 
     if ( state != Start ) {
        FG_LOG( FG_TERRAIN, FG_INFO,
-               "ReInitializing the Tile Manager subsystem." );
+               "... Reinitializing." );
 
        // This is necessay to keep bookeeping straight for the
        // tile_cache   -- which actually handles all the
@@ -102,7 +102,7 @@ int FGTileMgr::init( void ) {
        }
     } else {
        FG_LOG( FG_TERRAIN, FG_INFO,
-               "Initializing Tile Manager subsystem." );
+               "... First time through." );
     }
 
     global_tile_cache.init();
@@ -304,13 +304,12 @@ void FGTileMgr::scroll( void )
 }
 
 
-void FGTileMgr::initialize_queue( void )
+void FGTileMgr::initialize_queue()
 {
     // First time through or we have teleported, initialize the
     // system and load all relavant tiles
 
     FG_LOG( FG_TERRAIN, FG_INFO, "Updating Tile list for " << current_bucket );
-    FG_LOG( FG_TERRAIN, FG_INFO, "  First time through ... " );
     FG_LOG( FG_TERRAIN, FG_INFO, "  Updating Tile list for " << current_bucket );
     FG_LOG( FG_TERRAIN, FG_INFO, "  Loading " 
             << tile_diameter * tile_diameter << " tiles" );
@@ -328,12 +327,6 @@ void FGTileMgr::initialize_queue( void )
     // "rings"
 
     sched_tile( current_bucket );
-    Point3D geod_view_center( current_bucket.get_center_lon(), 
-                              current_bucket.get_center_lat(), 
-                              cur_fdm_state->get_Altitude()*FEET_TO_METER + 3 );
-
-    current_view.abs_view_pos = fgGeodToCart( geod_view_center );
-    current_view.view_pos = current_view.abs_view_pos - scenery.next_center;
 
     for ( i = 3; i <= tile_diameter; i = i + 2 ) {
         int j;
@@ -372,16 +365,19 @@ void FGTileMgr::initialize_queue( void )
 }
 
 
-// given the current lon/lat, fill in the array of local chunks.  If
-// the chunk isn't already in the cache, then read it from disk.
-int FGTileMgr::update( double junk1, double junk2 ) {
+// given the current lon/lat (in degrees), fill in the array of local
+// chunks.  If the chunk isn't already in the cache, then read it from
+// disk.
+int FGTileMgr::update( double lon, double lat ) {
     // FG_LOG( FG_TERRAIN, FG_DEBUG, "FGTileMgr::update()" );
 
-    FGInterface *f = current_aircraft.fdm_state;
+    // FGInterface *f = current_aircraft.fdm_state;
 
     // lonlat for this update 
-    longitude = f->get_Longitude() * RAD_TO_DEG;
-    latitude = f->get_Latitude() * RAD_TO_DEG;
+    // longitude = f->get_Longitude() * RAD_TO_DEG;
+    // latitude = f->get_Latitude() * RAD_TO_DEG;
+    longitude = lon;
+    latitude = lat;
     // FG_LOG( FG_TERRAIN, FG_DEBUG, "lon "<< lonlat[LON] <<
     //      " lat " << lonlat[LAT] );
 
@@ -395,7 +391,7 @@ int FGTileMgr::update( double junk1, double junk2 ) {
         current_tile = global_tile_cache.get_tile(tile_index);
         scenery.next_center = current_tile->center;
     } else {
-        FG_LOG( FG_TERRAIN, FG_WARN, "Tile not found" );
+        FG_LOG( FG_TERRAIN, FG_WARN, "Tile not found (Ok if initializing)" );
     }
 
     if ( state == Running ) {
@@ -438,7 +434,7 @@ int FGTileMgr::update( double junk1, double junk2 ) {
            scroll();
        }
 
-    } else if ( (state == Start) || (state == Inited) ) {
+    } else if ( state == Start || state == Inited ) {
        initialize_queue();
        state = Running;
     }
@@ -451,19 +447,25 @@ int FGTileMgr::update( double junk1, double junk2 ) {
        load_tile( pending.b, pending.cache_index );
     }
 
-    // find our current elevation (feed in the current bucket to save work)
-    // Point3D geod_pos = Point3D( f->get_Longitude(), f->get_Latitude(), 0.0);
-    // Point3D tmp_abs_view_pos = fgGeodToCart(geod_pos);
-
-    // cout << "current elevation (old) == " 
-    //      << current_elev( f->get_Longitude(), f->get_Latitude(), 
-    //                       tmp_abs_view_pos ) 
-    //      << endl;
-
-    // set scenery.cur_elev and scenery.cur_radius
+    if ( scenery.center == Point3D(0.0) ) {
+       // initializing
+       // cout << "initializing ... " << endl;
+       Point3D geod_pos = Point3D( longitude * DEG_TO_RAD,
+                                   latitude * DEG_TO_RAD,
+                                   0.0);
+       Point3D tmp_abs_view_pos = fgGeodToCart( geod_pos );
+       scenery.center = tmp_abs_view_pos;
+       // cout << "abs_view_pos = " << tmp_abs_view_pos << endl;
+       prep_ssg_nodes();
+       current_elev_ssg( tmp_abs_view_pos,
+                         Point3D( 0.0 ) );
+    } else {
+       // cout << "abs view pos = " << current_view.abs_view_pos
+       //      << " view pos = " << current_view.view_pos << endl;
+       current_elev_ssg( current_view.abs_view_pos,
+                         current_view.view_pos );
+    }
 
-    current_elev_ssg( current_view.abs_view_pos,
-                      current_view.view_pos );
     // cout << "current elevation (ssg) == " << scenery.cur_elev << endl;
 
     previous_bucket = current_bucket;
@@ -483,6 +485,18 @@ void FGTileMgr::prep_ssg_nodes( void ) {
     FGTileEntry *t;
     float ranges[2];
     ranges[0] = 0.0f;
+    double vis = 0.0;
+
+#ifndef FG_OLD_WEATHER
+    if ( WeatherDatabase != NULL ) {
+       vis = WeatherDatabase->getWeatherVisibility();
+    } else {
+       vis = 16000;
+    }
+#else
+    vis = current_weather.get_visibility();
+#endif
+    // cout << "visibility = " << vis << endl;
 
     // traverse the potentially viewable tile list and update range
     // selector and transform
@@ -493,12 +507,7 @@ void FGTileMgr::prep_ssg_nodes( void ) {
            // set range selector (LOD trick) to be distance to center
            // of tile + bounding radius
 
-#ifndef FG_OLD_WEATHER
-            ranges[1] = WeatherDatabase->getWeatherVisibility()
-               + t->bounding_radius;
-#else
-            ranges[1] = current_weather.get_visibility()+t->bounding_radius;
-#endif
+            ranges[1] = vis + t->bounding_radius;
             t->range_ptr->setRanges( ranges, 2 );
 
             // calculate tile offset
index 0d616bdb4da913cff33cdce578b597a0e1ddb020..b99760fb7c5d8ecbfe7957d63783d278db61ebd0 100644 (file)
@@ -94,7 +94,7 @@ private:
     list < FGLoadRec > load_queue;
 
     // initialize the cache
-    void initialize_queue( void );
+    void initialize_queue();
 
     FGBucket BucketOffset( int dx, int dy );
 
@@ -143,10 +143,10 @@ public:
     // Initialize the Tile Manager subsystem
     int init( void );
 
-    // given the current lon/lat, fill in the array of local chunks.
-    // If the chunk isn't already in the cache, then read it from
-    // disk.
-    int update( double junk1, double junk2 );
+    // given the current lon/lat (in degrees), fill in the array of
+    // local chunks.  If the chunk isn't already in the cache, then
+    // read it from disk.
+    int update( double lon, double lat );
 
     // Determine scenery altitude.  Normally this just happens when we
     // render the scene, but we'd also like to be able to do this