]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Move the texture loader to SimGear
[flightgear.git] / src / Main / main.cxx
index 478baf576e6fe0448ee57f845645d8247905b3c0..048fb35687edb73fa903f75052890397324f806a 100644 (file)
 #include <simgear/compiler.h>
 
 #include STL_IOSTREAM
-#ifndef SG_HAVE_NATIVE_SGI_COMPILERS
 SG_USING_STD(cerr);
 SG_USING_STD(endl);
-#endif
 
 #include <simgear/misc/exception.hxx>
 #include <simgear/ephemeris/ephemeris.hxx>
@@ -51,8 +49,7 @@ SG_USING_STD(endl);
 #  include <float.h>
 #endif
 
-#include <GL/glut.h>
-#include <GL/gl.h>
+#include GLUT_H
 
 #include <stdio.h>
 #include <string.h>            // for strcmp()
@@ -80,8 +77,10 @@ SG_USING_STD(endl);
 #include <simgear/math/polar3d.hxx>
 #include <simgear/math/sg_random.h>
 #include <simgear/misc/sg_path.hxx>
-#include <simgear/sky/clouds3d/SkySceneLoader.hpp>
-#include <simgear/sky/clouds3d/SkyUtil.hpp>
+#ifdef FG_USE_CLOUDS_3D
+#  include <simgear/sky/clouds3d/SkySceneLoader.hpp>
+#  include <simgear/sky/clouds3d/SkyUtil.hpp>
+#endif
 #include <simgear/sky/sky.hxx>
 #include <simgear/timing/sg_time.hxx>
 
@@ -96,9 +95,9 @@ SG_USING_STD(endl);
 
 #include <Autopilot/newauto.hxx>
 
+#include <Cockpit/hud.hxx>
 #include <Cockpit/cockpit.hxx>
 #include <Cockpit/radiostack.hxx>
-#include <Cockpit/steam.hxx>
 
 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
 #include <GUI/gui.h>
@@ -111,6 +110,12 @@ SG_USING_STD(endl);
 #ifdef FG_NETWORK_OLK
 #include <NetworkOLK/network.h>
 #endif
+
+#ifdef FG_MPLAYER_AS
+#include <MultiPlayer/multiplaytxmgr.hxx>
+#include <MultiPlayer/multiplayrxmgr.hxx>
+#endif
+
 #include <Objects/matlib.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
@@ -136,9 +141,8 @@ SG_USING_STD(endl);
 
 #include "fg_commands.hxx"
 
-// #define FG_EXPERIMENTAL_LIGHTING
-#ifdef FG_EXPERIMENTAL_LIGHTING
-#  ifdef WIN32
+#ifdef FG_EXPERIMENTAL_POINT_LIGHTING
+#ifdef WIN32
   typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname,
                                                         GLfloat param);
   typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname,
@@ -146,7 +150,7 @@ SG_USING_STD(endl);
 
   PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT = 0;
   PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT = 0;
-#  elif linux
+#elif linux
   #include <GL/glx.h>
 
   typedef void (* OpenGLFuncExt)(GLenum pname, GLfloat param);
@@ -154,7 +158,7 @@ SG_USING_STD(endl);
 
   OpenGLFuncExt glPointParameterfEXT = 0;
   OpenGLFuncExtv glPointParameterfvEXT = 0;
-#  endif
+#endif
 #endif
 
 float default_attenuation[3] = {1.0, 0.0, 0.0};
@@ -211,9 +215,6 @@ FGGeneral general;
 static int idle_state = 0;
 static long global_multi_loop;
 
-// forward declaration
-void fgReshape( int width, int height );
-
 // fog constants.  I'm a little nervous about putting actual code out
 // here but it seems to work (?)
 static const double m_log01 = -log( 0.01 );
@@ -231,8 +232,11 @@ ssgTransform *fgd_pos = NULL;
 
 // Sky structures
 SGSky *thesky;
-SkySceneLoader *sgClouds3d;
-bool _bcloud_orig = true;
+
+#ifdef FG_USE_CLOUDS_3D
+  SkySceneLoader *sgClouds3d;
+  bool _bcloud_orig = true;
+#endif
 
 // hack
 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
@@ -272,6 +276,7 @@ ssgSimpleState *menus;
 SGTimeStamp last_time_stamp;
 SGTimeStamp current_time_stamp;
 
+
 void fgBuildRenderStates( void ) {
     default_state = new ssgSimpleState;
     default_state->ref();
@@ -369,7 +374,7 @@ void trRenderFrame( void ) {
     if ( fgPanelVisible() ) {
         GLfloat height = fgGetInt("/sim/startup/ysize");
         GLfloat view_h =
-            (current_panel->getViewHeight() - current_panel->getYOffset())
+            (globals->get_current_panel()->getViewHeight() - globals->get_current_panel()->getYOffset())
             * (height / 768.0) + 1;
         glTranslatef( 0.0, view_h, 0.0 );
     }
@@ -424,7 +429,7 @@ void trRenderFrame( void ) {
     ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
 
     if (fgGetBool("/environment/clouds/status"))
-      thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
+        thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
 
     globals->get_model_mgr()->draw();
     globals->get_aircraft_model()->draw();
@@ -433,7 +438,7 @@ void trRenderFrame( void ) {
 
 // Update all Visuals (redraws anything graphics related)
 void fgRenderFrame() {
-  
+
     GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
     GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
 
@@ -484,7 +489,7 @@ void fgRenderFrame() {
     // GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
     // GLfloat mat_shininess[] = { 10.0 };
     GLbitfield clear_mask;
-    
+
     if ( idle_state != 1000 ) {
        // still initializing, draw the splash screen
        if ( fgGetBool("/sim/startup/splash-screen") ) {
@@ -513,20 +518,14 @@ void fgRenderFrame() {
             glEnable(GL_BLEND);
             glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
 
-            /*
-            glEnable( GL_TEXTURE_2D );
-            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-            */
-
+#ifdef FG_USE_CLOUDS_3D
             if ( _bcloud_orig ) {
                 Point3D c = globals->get_scenery()->get_center();
                 sgClouds3d->Set_Cloud_Orig( &c );
                 _bcloud_orig = false;
             }
             sgClouds3d->Update( current__view->get_absolute_view_pos() );
+#endif
             glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
             glDisable(GL_DEPTH_TEST);
         }
@@ -539,12 +538,12 @@ void fgRenderFrame() {
        if ( fgGetBool("/sim/rendering/skyblend") ) {
            if ( fgGetBool("/sim/rendering/textures") ) {
                // glClearColor(black[0], black[1], black[2], black[3]);
-               glClearColor(l->adj_fog_color[0], l->adj_fog_color[1], 
+               glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
                             l->adj_fog_color[2], l->adj_fog_color[3]);
                clear_mask |= GL_COLOR_BUFFER_BIT;
            }
        } else {
-           glClearColor(l->sky_color[0], l->sky_color[1], 
+           glClearColor(l->sky_color[0], l->sky_color[1],
                         l->sky_color[2], l->sky_color[3]);
            clear_mask |= GL_COLOR_BUFFER_BIT;
        }
@@ -576,19 +575,21 @@ void fgRenderFrame() {
 
        // update the sky dome
        if ( fgGetBool("/sim/rendering/skyblend") ) {
-           /* cout << "thesky->repaint() sky_color = "
+           /*
+             SG_LOG( SG_GENERAL, SG_BULK, "thesky->repaint() sky_color = "
                 << cur_light_params.sky_color[0] << " "
                 << cur_light_params.sky_color[1] << " "
                 << cur_light_params.sky_color[2] << " "
-                << cur_light_params.sky_color[3] << endl;
-           cout << "    fog = "
+                << cur_light_params.sky_color[3] );
+           SG_LOG( SG_GENERAL, SG_BULK, "    fog = "
                 << cur_light_params.fog_color[0] << " "
                 << cur_light_params.fog_color[1] << " "
                 << cur_light_params.fog_color[2] << " "
-                << cur_light_params.fog_color[3] << endl;
-           cout << "    sun_angle = " << cur_light_params.sun_angle
-                << "    moon_angle = " << cur_light_params.moon_angle
-                 << endl; */
+                << cur_light_params.fog_color[3] ); 
+           SG_LOG( SG_GENERAL, SG_BULK,
+                    "    sun_angle = " << cur_light_params.sun_angle
+                << "    moon_angle = " << cur_light_params.moon_angle );
+            */
            thesky->repaint( cur_light_params.sky_color,
                             cur_light_params.adj_fog_color,
                             cur_light_params.sun_angle,
@@ -597,19 +598,25 @@ void fgRenderFrame() {
                             globals->get_ephem()->getPlanets(),
                             globals->get_ephem()->getNumStars(),
                             globals->get_ephem()->getStars() );
-           /* cout << "thesky->reposition( view_pos = " << view_pos[0] << " "
-                << view_pos[1] << " " << view_pos[2] << endl;
-           cout << "    zero_elev = " << zero_elev[0] << " "
+
+           /*
+            SG_LOG( SG_GENERAL, SG_BULK,
+                    "thesky->reposition( view_pos = " << view_pos[0] << " "
+                << view_pos[1] << " " << view_pos[2] );
+           SG_LOG( SG_GENERAL, SG_BULK,
+                    "    zero_elev = " << zero_elev[0] << " "
                 << zero_elev[1] << " " << zero_elev[2]
                 << " lon = " << cur_fdm_state->get_Longitude()
-                << " lat = " << cur_fdm_state->get_Latitude() << endl;
-           cout << "    sun_rot = " << cur_light_params.sun_rotation
-                << " gst = " << SGTime::cur_time_params->getGst() << endl;
-           cout << "    sun ra = " << globals->get_ephem()->getSunRightAscension()
-                << " sun dec = " << globals->get_ephem()->getSunDeclination() 
-                << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
-                << " moon dec = " << globals->get_ephem()->getMoonDeclination() << endl; */
+                << " lat = " << cur_fdm_state->get_Latitude() );
+           SG_LOG( SG_GENERAL, SG_BULK,
+                    "    sun_rot = " << cur_light_params.sun_rotation
+                << " gst = " << SGTime::cur_time_params->getGst() );
+           SG_LOG( SG_GENERAL, SG_BULK,
+                 "    sun ra = " << globals->get_ephem()->getSunRightAscension()
+              << " sun dec = " << globals->get_ephem()->getSunDeclination()
+              << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
+              << " moon dec = " << globals->get_ephem()->getMoonDeclination() );
+            */
 
            thesky->reposition( current__view->get_view_pos(),
                                current__view->get_zero_elev(),
@@ -699,12 +706,14 @@ 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);
+#ifdef FG_MPLAYER_AS
+        // Update any multiplayer models
+        globals->get_multiplayer_rx_mgr()->Update();
+#endif
 
-       if ( fgGetBool("/sim/rendering/skyblend") ) {
+        if ( fgGetBool("/sim/rendering/skyblend") &&
+             fgGetBool("/sim/rendering/draw-otw") )
+        {
            // draw the sky backdrop
 
             // we need a white diffuse light for the phase of the moon
@@ -720,7 +729,14 @@ void fgRenderFrame() {
        glEnable( GL_DEPTH_TEST );
 
         ssgSetNearFar( scene_nearplane, scene_farplane );
-       ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
+
+        if ( fgGetBool("/sim/rendering/wireframe") ) {
+            // draw wire frame
+            glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
+        }
+        if ( fgGetBool("/sim/rendering/draw-otw") ) {
+            ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
+        }
 
        // This is a bit kludgy.  Every 200 frames, do an extra
        // traversal of the scene graph without drawing anything, but
@@ -748,17 +764,19 @@ void fgRenderFrame() {
        glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
         ssgSetNearFar( scene_nearplane, scene_farplane );
 
-#ifdef FG_EXPERIMENTAL_LIGHTING
+#ifdef FG_EXPERIMENTAL_POINT_LIGHTING
         // Enable states for drawing points with GL_extension
         glEnable(GL_POINT_SMOOTH);
 
-       if (glutExtensionSupported("GL_EXT_point_parameters")) {
+        if ( fgGetBool("/sim/rendering/distance-attenuation")
+             && glutExtensionSupported("GL_EXT_point_parameters") )
+        {
             float quadratic[3] = {1.0, 0.001, 0.0000001};
             // makes the points fade as they move away
             glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, quadratic);
             glPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1.0); 
-       }
-        glPointSize(2.0);
+        }
+        glPointSize(4.0);
 
         // blending function for runway lights
         glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
@@ -771,11 +789,18 @@ void fgRenderFrame() {
         glPolygonMode(GL_FRONT, GL_POINT);
 
         // draw runway lighting
-       ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
+        if ( fgGetBool("/sim/rendering/draw-otw") ) {
+            ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
+        }
 
         // change punch through and then draw taxi lighting
-       glFogf (GL_FOG_DENSITY, taxi_exp2_punch_through);
-       ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
+       glFogf ( GL_FOG_DENSITY, fog_exp2_density );
+        // sgVec3 taxi_fog;
+        // sgSetVec3( taxi_fog, 0.0, 0.0, 0.0 );
+        // glFogfv ( GL_FOG_COLOR, taxi_fog );
+        if ( fgGetBool("/sim/rendering/draw-otw") ) {
+            ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
+        }
 
         // clean up lighting
         glPolygonMode(GL_FRONT, GL_FILL);
@@ -792,11 +817,13 @@ void fgRenderFrame() {
        //_frame_count++;
 
 
-#ifdef FG_EXPERIMENTAL_LIGHTING
-       if (glutExtensionSupported("GL_EXT_point_parameters")) {
+#ifdef FG_EXPERIMENTAL_POINT_LIGHTING
+        if ( fgGetBool("/sim/rendering/distance-attenuation")
+             && glutExtensionSupported("GL_EXT_point_parameters") )
+        {
             glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
                                   default_attenuation);
-       }
+        }
 
         glPointSize(1.0);
         glDisable(GL_POINT_SMOOTH);
@@ -804,17 +831,23 @@ void fgRenderFrame() {
 
         // draw ground lighting
        glFogf (GL_FOG_DENSITY, ground_exp2_punch_through);
-       ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
+        if ( fgGetBool("/sim/rendering/draw-otw") ) {
+            ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
+        }
 
        if ( fgGetBool("/sim/rendering/skyblend") ) {
            // draw the sky cloud layers
-            if (fgGetBool("/environment/clouds/status")) {
+            if ( fgGetBool("/environment/clouds/status") &&
+                 fgGetBool("/sim/rendering/draw-otw") )
+            {
                 thesky->postDraw( cur_fdm_state->get_Altitude()
                                   * SG_FEET_TO_METER );
             }
        }
 
-        if ( fgGetBool("/sim/rendering/clouds3d") ) {
+        if ( fgGetBool("/sim/rendering/clouds3d") &&
+             fgGetBool("/sim/rendering/draw-otw") )
+        {
             glDisable( GL_FOG );
             glDisable( GL_LIGHTING );
             // cout << "drawing new clouds" << endl;
@@ -831,15 +864,19 @@ void fgRenderFrame() {
             glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
             */
 
+#ifdef FG_USE_CLOUDS_3D
             sgClouds3d->Draw((sgVec4 *)current__view->get_VIEW());
+#endif
             glEnable( GL_FOG );
             glEnable( GL_LIGHTING );
             glEnable( GL_DEPTH_TEST );
             glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
         }
 
-       globals->get_model_mgr()->draw();
-       globals->get_aircraft_model()->draw();
+        if ( fgGetBool("/sim/rendering/draw-otw") ) {
+            globals->get_model_mgr()->draw();
+            globals->get_aircraft_model()->draw();
+        }
 
        // display HUD && Panel
        glDisable( GL_FOG );
@@ -855,11 +892,12 @@ void fgRenderFrame() {
 
        // Use the hud_and_panel ssgSimpleState for rendering the ATC output
        // This only works properly if called before the panel call
-       globals->get_ATC_display()->update(delta_time_sec);
+       if((fgGetBool("/sim/ATC/enabled")) || (fgGetBool("/sim/ai-traffic/enabled")))
+           globals->get_ATC_display()->update(delta_time_sec);
 
        // update the panel subsystem
-       if ( current_panel != NULL ) {
-           current_panel->update(delta_time_sec);
+       if ( globals->get_current_panel() != NULL ) {
+           globals->get_current_panel()->update(delta_time_sec);
        }
         fgUpdate3DPanels();
 
@@ -905,7 +943,6 @@ void fgUpdateTimeDepCalcs() {
          globals->get_scenery()->get_cur_elev() > -9990 )
     {
        SG_LOG(SG_FLIGHT,SG_INFO, "Finally initializing fdm");  
-       
        cur_fdm_state->init();
        if ( cur_fdm_state->get_bound() ) {
            cur_fdm_state->unbind();
@@ -913,6 +950,10 @@ void fgUpdateTimeDepCalcs() {
        cur_fdm_state->bind();
     }
 
+#ifndef FG_WEATHERCM
+    globals->get_environment_mgr()->update(delta_time_sec);
+#endif
+
     // conceptually, the following block could be done for each fdm
     // instance ...
     if ( !cur_fdm_state->get_inited() ) {
@@ -926,7 +967,6 @@ void fgUpdateTimeDepCalcs() {
 
        globals->get_autopilot()->update(delta_time_sec);
        cur_fdm_state->update(delta_time_sec);
-       globals->get_steam()->update(delta_time_sec);
     }
 
     globals->get_model_mgr()->update(delta_time_sec);
@@ -996,6 +1036,8 @@ static void fgMainLoop( void ) {
 
     SGTime *t = globals->get_time_params();
 
+    sglog().setLogLevels( SG_ALL, (sgDebugPriority)fgGetInt("/sim/log-level") );
+
     FGLocation * acmodel_location = 0;
     if(cur_fdm_state->getACModel() != 0) {
       acmodel_location = (FGLocation *)  cur_fdm_state->getACModel()->get3DModel()->getFGLocation();
@@ -1026,10 +1068,6 @@ static void fgMainLoop( void ) {
     // init routine and we don't have to worry about it again.
 #endif
 
-#ifndef FG_WEATHERCM
-    globals->get_environment_mgr()->update(delta_time_sec);
-#endif
-
     // Fix elevation.  I'm just sticking this here for now, it should
     // probably move eventually
 
@@ -1137,6 +1175,7 @@ static void fgMainLoop( void ) {
 #else
     if ( (t->get_cur_time() != last_time) && (last_time > 0) ) {
        general.set_frame_rate( frames );
+        fgSetInt("/sim/frame-rate", frames);
        SG_LOG( SG_ALL, SG_DEBUG, 
                "--> Frame rate is = " << general.get_frame_rate() );
        frames = 0;
@@ -1146,7 +1185,8 @@ static void fgMainLoop( void ) {
 #endif
 
     // Run ATC subsystem
-    globals->get_ATC_mgr()->update(delta_time_sec);
+    if (fgGetBool("/sim/ATC/enabled"))
+        globals->get_ATC_mgr()->update(delta_time_sec);
 
     // Run the AI subsystem
     if (fgGetBool("/sim/ai-traffic/enabled"))
@@ -1208,42 +1248,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(),
-                                acmodel_location->get_tile_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(),
-                            current_view->getFGLocation()->get_tile_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 +1285,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() );
       }
     }
@@ -1337,6 +1367,9 @@ static void fgIdleFunction ( void ) {
        // setup OpenGL view parameters
        fgInitVisuals();
 
+        // Read the list of available aircrafts
+        fgReadAircraft();
+
        idle_state++;
     } else if ( idle_state == 5 ) {
 
@@ -1369,8 +1402,8 @@ void fgReshape( int width, int height ) {
 
     if ( (!fgGetBool("/sim/virtual-cockpit"))
         && fgPanelVisible() && idle_state == 1000 ) {
-       view_h = (int)(height * (current_panel->getViewHeight() -
-                                current_panel->getYOffset()) / 768.0);
+       view_h = (int)(height * (globals->get_current_panel()->getViewHeight() -
+                                globals->get_current_panel()->getYOffset()) / 768.0);
     } else {
        view_h = height;
     }
@@ -1392,8 +1425,12 @@ void fgReshape( int width, int height ) {
               viewmgr->get_current_view()->get_v_fov() );
 
     fgHUDReshape();
+
+#ifdef FG_USE_CLOUDS_3D
     sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
                         viewmgr->get_current_view()->get_v_fov() );
+#endif
+
 }
 
 // Initialize GLUT and define a main window
@@ -1540,9 +1577,6 @@ static bool fgMainInit( int argc, char **argv ) {
     FGControls *controls = new FGControls;
     globals->set_controls( controls );
 
-    FGSteam *steam = new FGSteam;
-    globals->set_steam( steam );
-
     string_list *col = new string_list;
     globals->set_channel_options_list( col );
 
@@ -1551,7 +1585,7 @@ static bool fgMainInit( int argc, char **argv ) {
     fgInitFGRoot(argc, argv);
 
     // Check for the correct base package version
-    static char required_version[] = "0.9.0";
+    static char required_version[] = "0.9.1";
     string base_version = fgBasePackageVersion();
     if ( !(base_version == required_version) ) {
         // tell the operator how to use this application
@@ -1559,7 +1593,7 @@ static bool fgMainInit( int argc, char **argv ) {
        cerr << endl << "Base package check failed ... " \
             << "Found version " << base_version << " at: " \
              << globals->get_fg_root() << endl;
-        cerr << "Please upgrade to version" << required_version << endl;
+        cerr << "Please upgrade to version" << required_version << endl;
        exit(-1);
     }
 
@@ -1599,27 +1633,34 @@ static bool fgMainInit( int argc, char **argv ) {
     // fonts !!!
     guiInit();
 
+    // Read the list of available aircrafts
+    fgReadAircraft();
+
 #ifdef GL_EXT_texture_lod_bias
     glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
 #endif
 
-#ifdef FG_EXPERIMENTAL_LIGHTING
+#ifdef FG_EXPERIMENTAL_POINT_LIGHTING
             // get the address of our OpenGL extensions
-#  ifdef WIN32
-    glPointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC) 
-        wglGetProcAddress("glPointParameterfEXT");
-    glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC) 
-        wglGetProcAddress("glPointParameterfvEXT");
-#  elif linux
-    glPointParameterfEXT = (OpenGLFuncExt) 
-        glXGetProcAddressARB((GLubyte *)"glPointParameterfEXT");
-    glPointParameterfvEXT = (OpenGLFuncExtv) 
-        glXGetProcAddressARB((GLubyte *)"glPointParameterfvEXT");
-#  endif
+    if ( fgGetBool("/sim/rendering/distance-attenuation") )
+    {
+#ifdef WIN32
+        glPointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC) 
+            wglGetProcAddress("glPointParameterfEXT");
+        glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC) 
+            wglGetProcAddress("glPointParameterfvEXT");
+#elif linux
+        glPointParameterfEXT = (OpenGLFuncExt) 
+            glXGetProcAddressARB((GLubyte *)"glPointParameterfEXT");
+        glPointParameterfvEXT = (OpenGLFuncExtv) 
+            glXGetProcAddressARB((GLubyte *)"glPointParameterfvEXT");
+#endif
+   }
 #endif
 
     // based on the requested presets, calculate the true starting
     // lon, lat
+    fgInitNav();
     fgInitPosition();
 
     SGTime *t = fgInitTime();
@@ -1640,6 +1681,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
     ////////////////////////////////////////////////////////////////////
@@ -1688,8 +1732,8 @@ static bool fgMainInit( int argc, char **argv ) {
     texture_path.append("Textures");
     texture_path.append("Sky");
     for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
-      SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
-      thesky->add_cloud_layer(layer);
+        SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
+        thesky->add_cloud_layer(layer);
     }