]> git.mxchange.org Git - flightgear.git/commitdiff
Tweaks to 'native fdm' output. Time offset should now be properly supported
authorcurt <curt>
Fri, 8 Feb 2002 23:03:54 +0000 (23:03 +0000)
committercurt <curt>
Fri, 8 Feb 2002 23:03:54 +0000 (23:03 +0000)
as well as visibility.
This means that if you are using this protocal to exchange data with a
visual channel, you should be able to change time and visibility on the master
and all the slaved visual channels will match it.

src/Network/native_fdm.cxx
src/Network/net_fdm.hxx

index c9d6df7967c11ecc8afa18630107588cc998abad..90e54b44b2da75cf77be6deec77d39237e16b705 100644 (file)
@@ -30,6 +30,8 @@
 #include <simgear/io/iochannel.hxx>
 
 #include <FDM/flight.hxx>
+#include <Time/tmp.hxx>
+#include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 
 #include "native_fdm.hxx"
@@ -98,6 +100,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 +117,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 +134,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 +151,34 @@ 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 );
 
         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." );
     }
index 494352fc72e387c8c3bcd28c08c1e6da816aefdf..b1436e8457aca1f4d1bc509781f88ee6a6829b03 100644 (file)
@@ -58,9 +58,10 @@ public:
     double vcas;               // calibrated airspeed
     double climb_rate;         // feet per second
 
-    // Time
+    // Environment
     time_t cur_time;            // current unix time
     long int warp;              // offset in seconds to unix time
+    double visibility;          // visibility in meters (for env. effects)
 };