]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Move the texture loader to SimGear
[flightgear.git] / src / Main / main.cxx
index 7a42412571d7f1ce4a77a94895ad6f389c74a398..048fb35687edb73fa903f75052890397324f806a 100644 (file)
@@ -95,6 +95,7 @@ SG_USING_STD(endl);
 
 #include <Autopilot/newauto.hxx>
 
+#include <Cockpit/hud.hxx>
 #include <Cockpit/cockpit.hxx>
 #include <Cockpit/radiostack.hxx>
 
@@ -109,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>
@@ -208,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 );
@@ -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 );
     }
@@ -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") ) {
@@ -533,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;
        }
@@ -570,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,
@@ -591,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(),
@@ -693,7 +706,14 @@ void fgRenderFrame() {
        }
 # endif
 
-       if ( fgGetBool("/sim/rendering/skyblend") ) {
+#ifdef FG_MPLAYER_AS
+        // Update any multiplayer models
+        globals->get_multiplayer_rx_mgr()->Update();
+#endif
+
+        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
@@ -709,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
@@ -762,14 +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, fog_exp2_density );
         // sgVec3 taxi_fog;
         // sgSetVec3( taxi_fog, 0.0, 0.0, 0.0 );
         // glFogfv ( GL_FOG_COLOR, taxi_fog );
-       ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
+        if ( fgGetBool("/sim/rendering/draw-otw") ) {
+            ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
+        }
 
         // clean up lighting
         glPolygonMode(GL_FRONT, GL_FILL);
@@ -800,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;
@@ -836,8 +873,10 @@ void fgRenderFrame() {
             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 );
@@ -853,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();
 
@@ -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();
@@ -1133,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;
@@ -1142,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"))
@@ -1323,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 ) {
 
@@ -1355,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;
     }
@@ -1586,6 +1633,9 @@ 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