]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/native_fdm.cxx
Updated adf property names.
[flightgear.git] / src / Network / native_fdm.cxx
index 5af740b1784337bd645c14b1b3ccc2b983a090a6..9f83f4faba0e2304cd1474b44951afba335676c8 100644 (file)
 #  include <config.h>
 #endif
 
-#if defined(WIN32) && !defined(__CYGWIN__)
-#  include <windows.h>
-#else
-#  include <netinet/in.h>      // htonl() ntohl()
-#endif
-
 #include <simgear/debug/logstream.hxx>
 #include <simgear/io/lowlevel.hxx> // endian tests
 #include <simgear/io/iochannel.hxx>
+#include <simgear/timing/sg_time.hxx>
 
 #include <FDM/flight.hxx>
+#include <Time/tmp.hxx>
+#include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 
 #include "native_fdm.hxx"
 
+// FreeBSD works better with this included last ... (?)
+#if defined(WIN32) && !defined(__CYGWIN__)
+#  include <windows.h>
+#else
+#  include <netinet/in.h>      // htonl() ntohl()
+#endif
 
 
 // The function htond is defined this way due to the way some
@@ -98,6 +101,9 @@ bool FGNativeFDM::open() {
 
 
 static void global2net( const FGInterface *global, FGNetFDM *net ) {
+    static const SGPropertyNode *visibility
+        = fgGetNode("/environment/visibility-m");
+
     net->version = FG_NET_FDM_VERSION;
 
     // positions
@@ -112,9 +118,10 @@ static void global2net( const FGInterface *global, FGNetFDM *net ) {
     net->vcas = cur_fdm_state->get_V_calibrated_kts();
     net->climb_rate = cur_fdm_state->get_Climb_Rate();
 
-    // time
+    // environment
     net->cur_time = globals->get_time_params()->get_cur_time();
     net->warp = globals->get_warp();
+    net->visibility = visibility->getDoubleValue();
 
     // Convert the net buffer to network format
     net->version = htonl(net->version);
@@ -128,13 +135,15 @@ static void global2net( const FGInterface *global, FGNetFDM *net ) {
     htond(net->climb_rate);
     net->cur_time = htonl( net->cur_time );
     net->warp = htonl( net->warp );
+    htond(net->visibility);
 }
 
 
 static void net2global( FGNetFDM *net, FGInterface *global ) {
+    static long int last_warp = 0;
 
     // Convert to the net buffer from network format
-    net->version = htonl(net->version);
+    net->version = ntohl(net->version);
     htond(net->longitude);
     htond(net->latitude);
     htond(net->altitude);
@@ -143,25 +152,38 @@ static void net2global( FGNetFDM *net, FGInterface *global ) {
     htond(net->psi);
     htond(net->vcas);
     htond(net->climb_rate);
-    net->cur_time = htonl(net->cur_time);
-    net->warp = htonl(net->warp);
+    net->cur_time = ntohl(net->cur_time);
+    net->warp = ntohl(net->warp);
+    htond(net->visibility);
 
     if ( net->version == FG_NET_FDM_VERSION ) {
-       // cout << "pos = " << net->longitude << " " << net->latitude << endl;
-       // cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius() << endl;
-       cur_fdm_state->_updateGeodeticPosition( net->latitude,
-                                               net->longitude,
-                                               net->altitude
-                                                 * SG_METER_TO_FEET );
-       cur_fdm_state->_set_Euler_Angles( net->phi,
-                                         net->theta,
-                                         net->psi );
-       cur_fdm_state->_set_V_calibrated_kts( net->vcas );
-       cur_fdm_state->_set_Climb_Rate( net->climb_rate );
+        // cout << "pos = " << net->longitude << " " << net->latitude << endl;
+        // cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius() << endl;
+        cur_fdm_state->_updateGeodeticPosition( net->latitude,
+                                                net->longitude,
+                                                net->altitude
+                                                  * SG_METER_TO_FEET );
+        cur_fdm_state->_set_Euler_Angles( net->phi,
+                                          net->theta,
+                                          net->psi );
+        cur_fdm_state->_set_V_calibrated_kts( net->vcas );
+        cur_fdm_state->_set_Climb_Rate( net->climb_rate );
+
+       if ( net->cur_time ) {
+           fgSetLong("/sim/time/cur-time-override", net->cur_time);
+       }
 
         globals->set_warp( net->warp );
+        if ( net->warp != last_warp ) {
+            fgUpdateSkyAndLightingParams();
+        }
+        last_warp = net->warp;
+
+        fgSetDouble( "/environment/visibility-m", net->visibility );
     } else {
        SG_LOG( SG_IO, SG_ALERT, "Error: version mismatch in net2global()" );
+       SG_LOG( SG_IO, SG_ALERT,
+               "\tread " << net->version << " need " << FG_NET_FDM_VERSION );
        SG_LOG( SG_IO, SG_ALERT,
                "\tsomeone needs to upgrade net_fdm.hxx and recompile." );
     }