]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Turn back to default lighting when specular-highlight gets disabled
[flightgear.git] / src / Main / main.cxx
index 95ca119f34d1af2a92c5604bfb8d0a59217eafd8..4332c28cda376b26d4dd27de775634bcf292d68b 100644 (file)
 #  include <config.h>
 #endif
 
+#include <simgear/compiler.h>
+
 #if defined(__linux__) && defined(__i386__)
 #  include <fpu_control.h>
 #  include <signal.h>
 #endif
 
-#include <simgear/compiler.h>
-
-#include STL_IOSTREAM
-SG_USING_STD(cerr);
-SG_USING_STD(endl);
-
-#include <simgear/misc/exception.hxx>
-#include <simgear/ephemeris/ephemeris.hxx>
-#include <simgear/route/route.hxx>
-#include <simgear/screen/extensions.hxx>
-
-#include <Environment/environment_mgr.hxx>
-
 #ifdef SG_MATH_EXCEPTION_CLASH
 #  include <math.h>
 #endif
@@ -52,65 +41,54 @@ SG_USING_STD(endl);
 #  include <float.h>
 #endif
 
-#include GLUT_H
-
-#include <stdio.h>
-#include <string.h>            // for strcmp()
-#include <string>
-
-#ifdef HAVE_STDLIB_H
-#   include <stdlib.h>
-#endif
-
-#ifdef HAVE_SYS_STAT_H
-#  include <sys/stat.h>                // for stat()
-#endif
-
-#ifdef HAVE_UNISTD_H
-#  include <unistd.h>          // for stat()
-#endif
-
-#include <plib/netChat.h>
-#include <plib/pu.h>
-#include <plib/sg.h>
 #include <plib/ssg.h>
+#include <plib/pu.h>
+#include <plib/netSocket.h>
 
-#include <simgear/constants.h>  // for VERSION
-#include <simgear/debug/logstream.hxx>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_random.h>
-#include <simgear/misc/sg_path.hxx>
+#include <simgear/screen/extensions.hxx>
 #include <simgear/scene/material/matlib.hxx>
+#include <simgear/props/props.hxx>
+#include <simgear/scene/sky/sky.hxx>
+#include <simgear/timing/sg_time.hxx>
 #include <simgear/scene/model/animation.hxx>
-#include <simgear/scene/model/location.hxx>
-#include <simgear/scene/model/model.hxx>
+#include <simgear/ephemeris/ephemeris.hxx>
+#include <simgear/scene/model/placement.hxx>
+#include <simgear/math/sg_random.h>
+#include <simgear/route/route.hxx>
 #include <simgear/scene/model/modellib.hxx>
+
 #ifdef FG_USE_CLOUDS_3D
 #  include <simgear/scene/sky/clouds3d/SkySceneLoader.hpp>
 #  include <simgear/scene/sky/clouds3d/SkyUtil.hpp>
 #endif
-#include <simgear/scene/sky/sky.hxx>
-#include <simgear/timing/sg_time.hxx>
 
 #include <Include/general.hxx>
-
+#include <Scenery/tileentry.hxx>
+#include <Time/FGEventMgr.hxx>
+#include <Time/light.hxx>
+#include <Time/light.hxx>
 #include <Aircraft/aircraft.hxx>
-
-#include <ATC/ATCmgr.hxx>
+#include <Cockpit/panel.hxx>
+#include <Cockpit/cockpit.hxx>
+#include <Cockpit/radiostack.hxx>
+#include <Cockpit/hud.hxx>
+#include <Model/panelnode.hxx>
+#include <Model/modelmgr.hxx>
+#include <Model/acmodel.hxx>
+#include <Scenery/scenery.hxx>
+#include <Scenery/tilemgr.hxx>
+#include <FDM/flight.hxx>
+#include <FDM/UIUCModel/uiuc_aircraftdir.h>
+#include <FDM/ADA.hxx>
 #include <ATC/ATCdisplay.hxx>
+#include <ATC/ATCmgr.hxx>
 #include <ATC/AIMgr.hxx>
-
 #include <Autopilot/newauto.hxx>
+#include <Replay/replay.hxx>
+#include <Time/tmp.hxx>
+#include <Time/fg_timer.hxx>
+#include <Environment/environment_mgr.hxx>
 
-#include <Cockpit/hud.hxx>
-#include <Cockpit/cockpit.hxx>
-#include <Cockpit/radiostack.hxx>
-
-#include <FDM/UIUCModel/uiuc_aircraftdir.h>
-#include <GUI/gui.h>
-#include <Model/acmodel.hxx>
-#include <Model/modelmgr.hxx>
-#include <Model/panelnode.hxx>
 #ifdef FG_NETWORK_OLK
 #include <NetworkOLK/network.h>
 #endif
@@ -120,38 +98,12 @@ SG_USING_STD(endl);
 #include <MultiPlayer/multiplayrxmgr.hxx>
 #endif
 
-#include <Replay/replay.hxx>
-#include <Scenery/scenery.hxx>
-#include <Scenery/tilemgr.hxx>
-#ifdef ENABLE_AUDIO_SUPPORT
-#  include <Sound/fg_fx.hxx>
-#  include <Sound/morse.hxx>
-#endif
-#include <Systems/system_mgr.hxx>
-#include <Instrumentation/instrument_mgr.hxx>
-#include <Time/FGEventMgr.hxx>
-#include <Time/fg_timer.hxx>
-#include <Time/light.hxx>
-#include <Time/sunpos.hxx>
-#include <Time/tmp.hxx>
-
-// ADA
-#include <simgear/misc/sgstream.hxx>
-#include <simgear/math/point3d.hxx>
-#include <FDM/flight.hxx>
-#include <FDM/ADA.hxx>
-#include <Scenery/tileentry.hxx>
-
+#include "splash.hxx"
 #include "fg_commands.hxx"
-
-glPointParameterfProc glPointParameterfPtr = 0;
-glPointParameterfvProc glPointParameterfvPtr = 0;
-bool glPointParameterIsSupported = false;
+#include "fg_io.hxx"
+#include "main.hxx"
 
 float default_attenuation[3] = {1.0, 0.0, 0.0};
-//Required for using GL_extensions
-void fgLoadDCS (void);
-void fgUpdateDCS (void);
 ssgSelector *ship_sel=NULL;
 // upto 32 instances of a same object can be loaded.
 ssgTransform *ship_pos[32];
@@ -168,27 +120,19 @@ float scene_farplane = 120000.0f;
 
 static double delta_time_sec = 0.0;
 
+glPointParameterfProc glPointParameterfPtr = 0;
+glPointParameterfvProc glPointParameterfvPtr = 0;
+bool glPointParameterIsSupported = false;
+
 
 #ifdef FG_WEATHERCM
 #  include <WeatherCM/FGLocalWeatherDatabase.h>
 #endif
 
-#include "version.h"
-
-#include "fg_init.hxx"
-#include "fg_io.hxx"
-#include "fg_props.hxx"
-#include "globals.hxx"
-#include "splash.hxx"
-#include "viewmgr.hxx"
-#include "options.hxx"
-#include "logger.hxx"
-
 #ifdef macintosh
 #  include <console.h>         // -dw- for command line dialog
 #endif
 
-
 FGEventMgr global_events;
 
 // This is a record containing a bit of global housekeeping information
@@ -389,6 +333,12 @@ void trRenderFrame( void ) {
     glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
     glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
 
+    if (fgGetBool("/sim/rendering/specular-highlight")) {
+        glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
+    } else {
+        glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
+    }
+
     ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
 
     // texture parameters
@@ -397,7 +347,7 @@ void trRenderFrame( void ) {
 
     // we need a white diffuse light for the phase of the moon
     ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
-    thesky->preDraw();
+    thesky->preDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
 
     // draw the ssg scene
     // return to the desired diffuse color
@@ -580,15 +530,20 @@ void fgRenderFrame() {
                     "    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.cloud_color,
-                             cur_light_params.sun_angle,
-                             cur_light_params.moon_angle,
-                             globals->get_ephem()->getNumPlanets(),
-                             globals->get_ephem()->getPlanets(),
-                             globals->get_ephem()->getNumStars(),
-                             globals->get_ephem()->getStars() );
+
+            static SGSkyColor scolor;
+
+            scolor.sky_color   = cur_light_params.sky_color;
+            scolor.fog_color   = cur_light_params.adj_fog_color;
+            scolor.cloud_color = cur_light_params.cloud_color;
+            scolor.sun_angle   = cur_light_params.sun_angle;
+            scolor.moon_angle  = cur_light_params.moon_angle;
+            scolor.nplanets    = globals->get_ephem()->getNumPlanets();
+            scolor.nstars      = globals->get_ephem()->getNumStars();
+            scolor.planet_data = globals->get_ephem()->getPlanets();
+            scolor.star_data   = globals->get_ephem()->getStars();
+
+            thesky->repaint( scolor );
 
             /*
             SG_LOG( SG_GENERAL, SG_BULK,
@@ -621,23 +576,28 @@ void fgRenderFrame() {
             } else {
                sun_horiz_eff = moon_horiz_eff = 1.0;
             }
-            thesky->reposition( current__view->get_view_pos(),
-                                current__view->get_zero_elev(),
-                                current__view->get_world_up(),
-                                current__view->getLongitude_deg()
-                                  * SGD_DEGREES_TO_RADIANS,
-                                current__view->getLatitude_deg()
-                                  * SGD_DEGREES_TO_RADIANS,
-                                current__view->getAltitudeASL_ft()
-                                  * SG_FEET_TO_METER,
-                                cur_light_params.sun_rotation,
-                                globals->get_time_params()->getGst(),
-                                globals->get_ephem()->getSunRightAscension(),
-                                globals->get_ephem()->getSunDeclination(),
-                                50000.0 * sun_horiz_eff,
-                                globals->get_ephem()->getMoonRightAscension(),
-                                globals->get_ephem()->getMoonDeclination(),
-                                40000.0 * moon_horiz_eff );
+
+            static SGSkyState sstate;
+
+            sstate.view_pos  = current__view->get_view_pos();
+            sstate.zero_elev = current__view->get_zero_elev();
+            sstate.view_up   = current__view->get_world_up();
+            sstate.lon       = current__view->getLongitude_deg()
+                                * SGD_DEGREES_TO_RADIANS;
+            sstate.lat       = current__view->getLatitude_deg()
+                                * SGD_DEGREES_TO_RADIANS;
+            sstate.alt       = current__view->getAltitudeASL_ft()
+                                * SG_FEET_TO_METER;
+            sstate.spin      = cur_light_params.sun_rotation;
+            sstate.gst       = globals->get_time_params()->getGst();
+            sstate.sun_ra    = globals->get_ephem()->getSunRightAscension();
+            sstate.sun_dec   = globals->get_ephem()->getSunDeclination();
+            sstate.sun_dist  = 50000.0 * sun_horiz_eff;
+            sstate.moon_ra   = globals->get_ephem()->getMoonRightAscension();
+            sstate.moon_dec  = globals->get_ephem()->getMoonDeclination();
+            sstate.moon_dist = 40000.0 * moon_horiz_eff;
+
+            thesky->reposition( sstate, delta_time_sec );
         }
 
         glEnable( GL_DEPTH_TEST );
@@ -655,6 +615,13 @@ void fgRenderFrame() {
         // a completely dark scene.  So, we set GL_LIGHT_MODEL_AMBIENT
         // explicitely to black.
         glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
+        if (fgGetBool("/sim/rendering/specular-highlight")) {
+            glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,
+                          GL_SEPARATE_SPECULAR_COLOR);
+        } else {
+            glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,
+                         GL_SINGLE_COLOR);
+        }
 
         ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
         ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
@@ -722,10 +689,16 @@ void fgRenderFrame() {
             // we need a white diffuse light for the phase of the moon
             ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
 
-            thesky->preDraw();
+            thesky->preDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
 
             // return to the desired diffuse color
             ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
+
+            // FIXME: This should not be needed, but at this time (08/15/2003)
+            //        certain NVidia drivers don't seem to implement
+            //        fgPushAttrib(FG_FOG_BIT) properly. The result is that
+            //        there is not fog when looking at the sun.
+            glFogf ( GL_FOG_DENSITY, fog_exp2_density );
         }
 
         // draw the ssg scene
@@ -1110,15 +1083,20 @@ static void fgMainLoop( void ) {
            cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
            cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
 
-// Curt is this code used?  I don't see any problems when I comment it out.
+#if 0
+// This code is used by LaRCsim/UIUC to position the aircraft at a proper
+// place. This code should eventually go into the LaRCsim directory.
+// Commented out at Jul 27 2003 because tests show it is not needed.
+// Can probbaly be safely removed after Spet. 2003 - EMH
+
     if ( acmodel_location != 0 ) {
       if ( acmodel_location->get_cur_elev_m() > -9990 && cur_fdm_state->get_inited() ) {
         if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER < 
-             (acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0) ) {
+             (acmodel_location->get_cur_elev_m() + alt_adjust_m - 130.0) ) {
             // now set aircraft altitude above ground
             printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n", 
                cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
-               acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0,
+               acmodel_location->get_cur_elev_m() + alt_adjust_m - 130.0,
                acmodel_location->get_cur_elev_m() + alt_adjust_m );
             cur_fdm_state->set_Altitude( (acmodel_location->get_cur_elev_m() 
                                                 + alt_adjust_m) * SG_METER_TO_FEET );
@@ -1130,6 +1108,7 @@ static void fgMainLoop( void ) {
       }
     }
 // End of code in question. (see Curt is this code used? above)
+#endif
 
     /* printf("Adjustment - ground = %.2f  runway = %.2f  alt = %.2f\n",
            scenery.get_cur_elev(),
@@ -1570,7 +1549,7 @@ static bool fgGlutInitEvents( void ) {
 }
 
 // Main top level initialization
-static bool fgMainInit( int argc, char **argv ) {
+bool fgMainInit( int argc, char **argv ) {
 
 #if defined( macintosh )
     freopen ("stdout.txt", "w", stdout );
@@ -1837,100 +1816,6 @@ static bool fgMainInit( int argc, char **argv ) {
 // $$$ end - added VS Renganathan, 15 Oct 2K
 //         - added Venky         , 12 Nov 2K
 
-#if defined(__linux__) && defined(__i386__)
-
-static void handleFPE (int);
-
-static void
-initFPE ()
-{
-    fpu_control_t fpe_flags = 0;
-    _FPU_GETCW(fpe_flags);
-//     fpe_flags &= ~_FPU_MASK_IM;     // invalid operation
-//     fpe_flags &= ~_FPU_MASK_DM;     // denormalized operand
-//     fpe_flags &= ~_FPU_MASK_ZM;     // zero-divide
-//     fpe_flags &= ~_FPU_MASK_OM;     // overflow
-//     fpe_flags &= ~_FPU_MASK_UM;     // underflow
-//     fpe_flags &= ~_FPU_MASK_PM;     // precision (inexact result)
-    _FPU_SETCW(fpe_flags);
-    signal(SIGFPE, handleFPE);
-}
-
-static void
-handleFPE (int num)
-{
-  initFPE();
-  SG_LOG(SG_GENERAL, SG_ALERT, "Floating point interrupt (SIGFPE)");
-}
-#endif
-
-#ifdef __APPLE__
-
-typedef struct
-{
-  int  lo;
-  int  hi;
-} PSN;
-
-extern "C" {
-  short CPSGetCurrentProcess(PSN *psn);
-  short CPSSetProcessName (PSN *psn, char *processname);
-  short CPSEnableForegroundOperation(PSN *psn, int _arg2, int _arg3, int _arg4, int _arg5);
-  short CPSSetFrontProcess(PSN *psn);
-};
-
-#define CPSEnableFG(psn) CPSEnableForegroundOperation(psn,0x03,0x3C,0x2C,0x1103)
-
-#endif
-
-// Main entry point; catch any exceptions that have made it this far.
-int main ( int argc, char **argv ) {
-
-    // Enable floating-point exceptions for Linux/x86
-#if defined(__linux__) && defined(__i386__)
-    initFPE();
-#endif
-
-    // Enable floating-point exceptions for Windows
-#if defined( _MSC_VER ) && defined( DEBUG )
-    // Christian, we should document what this does
-    _control87( _EM_INEXACT, _MCW_EM );
-#endif
-
-#if defined( HAVE_BC5PLUS )
-    _control87(MCW_EM, MCW_EM);  /* defined in float.h */
-#endif
-
-    // Keyboard focus hack
-#ifdef __APPLE__
-    {
-      PSN psn;
-
-      glutInit (&argc, argv);
-
-      CPSGetCurrentProcess(&psn);
-      CPSSetProcessName(&psn, "FlightGear");
-      CPSEnableFG(&psn);
-      CPSSetFrontProcess(&psn);
-    }
-#endif
-
-    // FIXME: add other, more specific
-    // exceptions.
-    try {
-        fgMainInit(argc, argv);
-    } catch (sg_throwable &t) {
-                            // We must use cerr rather than
-                            // logging, since logging may be
-                            // disabled.
-        cerr << "Fatal error: " << t.getFormattedMessage()
-             << "\n (received from " << t.getOrigin() << ')' << endl;
-        exit(1);
-    }
-
-    return 0;
-}
-
 
 void fgLoadDCS(void) {