]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/cockpit.cxx
- modified FGBinding to keep a local copy of the argument property
[flightgear.git] / src / Cockpit / cockpit.cxx
index 9ffee6e009ea404dc8370657caa7b7d0bb0fe892..b88c5e93e5d3df82256528815438ffe5a1954ee4 100644 (file)
@@ -30,7 +30,6 @@
 #endif
 
 #include <GL/glut.h>
-// #include <simgear/xgl/xgl.h>
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -39,6 +38,7 @@
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/polar3d.hxx>
+#include <simgear/misc/props.hxx>
 
 #include <Aircraft/aircraft.hxx>
 #include <Include/general.hxx>
@@ -65,7 +65,7 @@ float get_latitude( void )
 {
     double lat;
 
-    lat = current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
+    lat = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
 
     float flat = lat;
     return(flat);
@@ -76,7 +76,7 @@ float get_lat_min( void )
 {
     double      a, d;
 
-    a = current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;    
+    a = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;    
     if (a < 0.0) {
         a = -a;
     }
@@ -90,7 +90,7 @@ float get_longitude( void )
 {
     double lon;
 
-    lon = current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
+    lon = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
 
     float flon = lon;
     return(flon);
@@ -112,7 +112,7 @@ get_formated_gmt_time( void )
 float get_long_min( void )
 {
     double  a, d;
-    a = current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;   
+    a = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;   
     if (a < 0.0) {
         a = -a;
     }
@@ -153,10 +153,12 @@ float get_rudderval( void )
 
 float get_speed( void )
 {
-    // Make an explicit function call.
+    static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
+
     float speed = current_aircraft.fdm_state->get_V_calibrated_kts()
-       * fgGetInt("/sim/speed-up"); // FIXME: inefficient
-    return( speed );
+       * speedup_node->getIntValue();
+
+    return speed;
 }
 
 float get_mach(void)
@@ -167,7 +169,7 @@ float get_mach(void)
 
 float get_aoa( void )
 {
-    float aoa = current_aircraft.fdm_state->get_Alpha() * RAD_TO_DEG;
+    float aoa = current_aircraft.fdm_state->get_Alpha() * SGD_RADIANS_TO_DEGREES;
     return( aoa );
 }
 
@@ -185,25 +187,24 @@ float get_pitch( void )
 
 float get_heading( void )
 {
-    float heading = (current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG);
+    float heading = (current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES);
     return( heading );
 }
 
 float get_altitude( void )
 {
-//  FGState *f;
-    // double rough_elev;
+    static const SGPropertyNode *startup_units_node
+        = fgGetNode("/sim/startup/units");
 
-//  current_aircraft.fdm_state
-    // rough_elev = mesh_altitude(f->get_Longitude() * RAD_TO_ARCSEC,
-    //                         f->get_Latitude()  * RAD_TO_ARCSEC);
     float altitude;
 
-    if ( fgGetString("/sim/startup/units") == "feet" ) {
+    if ( startup_units_node->getStringValue() == "feet" ) {
         altitude = current_aircraft.fdm_state->get_Altitude();
     } else {
-        altitude = (current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER);
+        altitude = (current_aircraft.fdm_state->get_Altitude()
+                    * SG_FEET_TO_METER);
     }
+
     return altitude;
 }
 
@@ -213,9 +214,9 @@ float get_agl( void )
 
     if ( fgGetString("/sim/startup/units") == "feet" ) {
         agl = (current_aircraft.fdm_state->get_Altitude()
-               - scenery.cur_elev * METER_TO_FEET);
+               - scenery.cur_elev * SG_METER_TO_FEET);
     } else {
-        agl = (current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER
+        agl = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
                - scenery.cur_elev);
     }
     return agl;
@@ -266,7 +267,7 @@ float get_climb_rate( void )
     if ( fgGetString("/sim/startup/units") == "feet" ) {
         climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
     } else {
-        climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * FEET_TO_METER * 60.0;
+        climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * SG_FEET_TO_METER * 60.0;
     }
     return (climb_rate);
 }
@@ -274,9 +275,9 @@ float get_climb_rate( void )
 
 float get_view_direction( void )
 {
-    double view_off = SG_2PI - globals->get_current_view()->get_view_offset();
+    double view_off = SGD_2PI - globals->get_current_view()->get_view_offset();
     double view = ( current_aircraft.fdm_state->get_Psi() + view_off)
-       * RAD_TO_DEG;
+       * SGD_RADIANS_TO_DEGREES;
     
     if(view > 360.)
         view -= 360.;
@@ -672,7 +673,7 @@ char *coord_format_latlon(double latitude, double longitude)
 
 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
 {
-    FG_LOG( FG_COCKPIT, FG_INFO, "Initializing cockpit subsystem" );
+    SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
 
     //  cockpit->code = 1;  /* It will be aircraft dependent */
     //  cockpit->status = 0;
@@ -692,7 +693,7 @@ bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
     // Have to set the LatLon display type
     fgLatLonFormat = toDM;
     
-    FG_LOG( FG_COCKPIT, FG_INFO,
+    SG_LOG( SG_COCKPIT, SG_INFO,
         "  Code " << ac_cockpit->code() << " Status " 
         << ac_cockpit->status() );
 
@@ -701,19 +702,22 @@ bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
 
 void fgCockpitUpdate( void ) {
 
-    FG_LOG( FG_COCKPIT, FG_DEBUG,
-        "Cockpit: code " << ac_cockpit->code() << " status " 
-        << ac_cockpit->status() );
+    SG_LOG( SG_COCKPIT, SG_DEBUG,
+            "Cockpit: code " << ac_cockpit->code() << " status " 
+            << ac_cockpit->status() );
 
-                               // FIXME: inefficient
-       int iwidth   = fgGetInt("/sim/startup/xsize");
-                               // FIXME: inefficient
-       int iheight  = fgGetInt("/sim/startup/ysize");
-       float width  = iwidth;
-       float height = iheight;
+    static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
+    static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
+    static const SGPropertyNode * hud_visibility_node
+        = fgGetNode("/sim/hud/visibility");
+
+    int iwidth   = xsize_node->getIntValue();
+    int iheight  = ysize_node->getIntValue();
+    float width  = iwidth;
+    // float height = iheight;
 
                                // FIXME: inefficient
-    if ( fgGetBool("/sim/hud/visibility") ) {
+    if ( hud_visibility_node->getBoolValue() ) {
         // This will check the global hud linked list pointer.
         // If these is anything to draw it will.
         fgUpdateHUD();
@@ -732,8 +736,7 @@ void fgCockpitUpdate( void ) {
         glMatrixMode( GL_PROJECTION );
         glPushMatrix();
         glLoadIdentity();
-        gluOrtho2D( 0, fgGetInt("/sim/startup/xsize"),
-                   0, fgGetInt("/sim/startup/ysize") );
+        gluOrtho2D( 0, iwidth, 0, iheight );
         glMatrixMode( GL_MODELVIEW );
         glPushMatrix();
         glLoadIdentity();
@@ -755,8 +758,5 @@ void fgCockpitUpdate( void ) {
     }
 #endif // #ifdef DISPLAY_COUNTER
     
-    glViewport( 0, 0, 
-               fgGetInt("/sim/startup/xsize"),
-               fgGetInt("/sim/startup/ysize") );
-
+    glViewport( 0, 0, iwidth, iheight );
 }