]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/cockpit.cxx
remove the rest of the static variables (except one); cleanup
[flightgear.git] / src / Cockpit / cockpit.cxx
index 0415b86a8219afa70c605517db0e81627f42b779..5aa7f82411e98539ad3b83f9ae315a6f84857a4d 100644 (file)
@@ -16,7 +16,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #  include <config.h>
 #endif
 
-#ifdef HAVE_WINDOWS_H          
+#ifdef HAVE_WINDOWS_H
 #  include <windows.h>
 #endif
 
-#include GLUT_H
+#include <simgear/compiler.h>
+
+#include SG_GLU_H
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/polar3d.hxx>
-#include <simgear/misc/props.hxx>
+#include <simgear/props/props.hxx>
 #include <simgear/timing/sg_time.hxx>
 
 #include <Aircraft/aircraft.hxx>
 #include <Include/general.hxx>
-#include <FDM/ADA.hxx>
+#ifdef ENABLE_SP_FMDS
+#include <FDM/SP/ADA.hxx>
+#endif
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/viewmgr.hxx>
@@ -73,7 +77,7 @@ float get_lat_min( void )
 {
     double a, d;
 
-    a = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;    
+    a = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
     if (a < 0.0) {
         a = -a;
     }
@@ -95,7 +99,7 @@ get_formated_gmt_time( void )
 {
     static char buf[32];
     const struct tm *p = globals->get_time_params()->getGmt();
-    sprintf( buf, "%d/%d/%4d %d:%02d:%02d", 
+    sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
          p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
          p->tm_hour, p->tm_min, p->tm_sec);
 
@@ -106,12 +110,12 @@ get_formated_gmt_time( void )
 float get_long_min( void )
 {
     double  a, d;
-    a = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;   
+    a = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
     if (a < 0.0) {
         a = -a;
     }
     d = (double) ( (int) a);
-    float lon_min = (a - d) * 60.0; 
+    float lon_min = (a - d) * 60.0;
 
     return lon_min;
 }
@@ -147,7 +151,7 @@ float get_speed( void )
     static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
 
     float speed = current_aircraft.fdm_state->get_V_calibrated_kts()
-       * speedup_node->getIntValue();
+        * speedup_node->getIntValue();
 
     return speed;
 }
@@ -155,7 +159,7 @@ float get_speed( void )
 float get_mach(void)
 {
     return current_aircraft.fdm_state->get_Mach_number();
-}      
+}
 
 float get_aoa( void )
 {
@@ -203,10 +207,10 @@ float get_agl( void )
 
     if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
         agl = (current_aircraft.fdm_state->get_Altitude()
-               - globals->get_scenery()->get_cur_elev() * SG_METER_TO_FEET);
+               - current_aircraft.fdm_state->get_Runway_altitude());
     } else {
-        agl = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
-               - globals->get_scenery()->get_cur_elev());
+        agl = (current_aircraft.fdm_state->get_Altitude()
+               - current_aircraft.fdm_state->get_Runway_altitude()) * SG_FEET_TO_METER;
     }
 
     return agl;
@@ -224,7 +228,7 @@ float get_frame_rate( void )
 
 float get_fov( void )
 {
-    return globals->get_current_view()->get_fov(); 
+    return globals->get_current_view()->get_fov();
 }
 
 float get_vfc_ratio( void )
@@ -268,16 +272,25 @@ float get_view_direction( void )
 {
     double view_off = SGD_2PI - globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
     double view = ( current_aircraft.fdm_state->get_Psi() + view_off)
-       * SGD_RADIANS_TO_DEGREES;
-    
-    if(view > 360.)
+        * SGD_RADIANS_TO_DEGREES;
+
+    if (view > 360.)
         view -= 360.;
-    else if(view<0.)
+    else if (view<0.)
         view += 360.;
-    
+
     return view;
 }
 
+// Added by Markus Hof on 5. Jan 2004
+float get_dme( void )
+{
+    static const SGPropertyNode * dme_node =
+        fgGetNode("/instrumentation/dme/indicated-distance-nm");
+
+    return dme_node->getFloatValue();
+}
+
 // $$$ begin - added, VS Renganathan 13 Oct 2K
 // #ifdef FIGHTER_HUD
 float get_Vx   ( void )
@@ -328,6 +341,7 @@ float get_anzg   ( void )
     return anzg;
 }
 
+#ifdef ENABLE_SP_FMDS
 int get_iaux1 (void)
 {
     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
@@ -507,7 +521,7 @@ float get_aux18 (void)
     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
     return fdm->get_faux(10);
 }
-// #endif
+#endif
 // $$$ end - added, VS Renganathan 13 Oct 2K
 
 
@@ -517,11 +531,11 @@ float get_aux18 (void)
 /****************************************************************************/
 char *dmshh_format(double degrees)
 {
-    static char buf[16];    
+    static char buf[16];
     int deg_part;
     int min_part;
     double sec_part;
-    
+
     if (degrees < 0)
       degrees = -degrees;
 
@@ -559,9 +573,9 @@ static char *toDM(float dd)
     double sign = 1;
     int deg;
 
-    if (dd < 0) {
-       sign = -1;
-    }
+    if (dd < 0)
+        sign = -1;
+
     /* round for minutes expressed to three decimal places */
     tempdd = fabs(dd) + (5.0E-4 / 60.0);
     deg = (int)tempdd;
@@ -590,9 +604,9 @@ static char *toDMS(float dd)
     double sec;
     double sign = 1;
 
-    if(dd < 0) {
-       sign = -1;
-    }
+    if (dd < 0)
+        sign = -1;
+
     /* round up for seconds expressed to one decimal place */
     tempdd = fabs(dd) + (0.05 / 3600.0);
     deg = (int)tempdd;
@@ -617,7 +631,7 @@ char *coord_format_lat(float latitude)
 //      dmshh_format(latitude),
 //      toDMS(latitude),
 //      toDM(latitude),
-        fgLatLonFormat(latitude),           
+        fgLatLonFormat(latitude),
         latitude > 0 ? 'N' : 'S');
     return buf;
 }
@@ -639,11 +653,11 @@ void fgLatLonFormatToggle( puObject *)
 {
     static int toggle = 0;
 
-    if ( toggle ) 
+    if ( toggle )
         fgLatLonFormat = toDM;
     else
         fgLatLonFormat = toDMS;
-    
+
     toggle = ~toggle;
 }
 
@@ -671,30 +685,30 @@ bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
 
     // If aircraft has HUD specified we will get the specs from its def
     // file. For now we will depend upon hard coding in hud?
-    
+
     // We must insure that the existing instrument link is purged.
     // This is done by deleting the links in the list.
-    
+
     // HI_Head is now a null pointer so we can generate a new list from the
     // current aircraft.
 
     fgHUDInit( cur_aircraft );
     ac_cockpit = new fg_Cockpit();
-    
+
     // Have to set the LatLon display type
     fgLatLonFormat = toDM;
-    
+
     SG_LOG( SG_COCKPIT, SG_INFO,
-        "  Code " << ac_cockpit->code() << " Status " 
+        "  Code " << ac_cockpit->code() << " Status "
         << ac_cockpit->status() );
 
-       return true;
+    return true;
 }
 
 void fgCockpitUpdate( void ) {
 
     SG_LOG( SG_COCKPIT, SG_DEBUG,
-            "Cockpit: code " << ac_cockpit->code() << " status " 
+            "Cockpit: code " << ac_cockpit->code() << " status "
             << ac_cockpit->status() );
 
     static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
@@ -704,52 +718,14 @@ void fgCockpitUpdate( void ) {
 
     int iwidth   = xsize_node->getIntValue();
     int iheight  = ysize_node->getIntValue();
-    float width  = iwidth;
-    // float height = iheight;
 
-                               // FIXME: inefficient
+                                // FIXME: inefficient
     if ( hud_visibility_node->getBoolValue() ) {
         // This will check the global hud linked list pointer.
-        // If these is anything to draw it will.
+        // If there is anything to draw it will.
         fgUpdateHUD();
     }
 
-#define DISPLAY_COUNTER
-#ifdef DISPLAY_COUNTER
-    else
-    {
-        char buf[64];
-        float fps    =       get_frame_rate();
-//      float tris   = fps * get_vfc_tris_drawn();
-//      float culled = fps * get_vfc_tris_culled();
-//      sprintf(buf,"%-4.1f  %7.0f  %7.0f", fps, tris, culled);
-        sprintf(buf,"%-5.1f", fps);
-
-        glMatrixMode( GL_PROJECTION );
-        glPushMatrix();
-        glLoadIdentity();
-        gluOrtho2D( 0, iwidth, 0, iheight );
-        glMatrixMode( GL_MODELVIEW );
-        glPushMatrix();
-        glLoadIdentity();
-
-        glDisable( GL_DEPTH_TEST );
-        glDisable( GL_LIGHTING );
-        
-        glColor3f( 0.9, 0.4, 0.2 );
-
-        guiFnt.drawString( buf,
-                          int(width - guiFnt.getStringWidth(buf) - 10),
-                           10 );
-        glEnable( GL_DEPTH_TEST );
-        glEnable( GL_LIGHTING );
-        glMatrixMode( GL_PROJECTION );
-        glPopMatrix();
-        glMatrixMode( GL_MODELVIEW );
-        glPopMatrix();
-    }
-#endif // #ifdef DISPLAY_COUNTER
-    
     glViewport( 0, 0, iwidth, iheight );
 }