]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/generic.hxx
#738: crash when switching 2D panels
[flightgear.git] / src / Network / generic.hxx
index ec03a46ad4e26b2bd57900120897ca074c099f74..55f0ca8a5675df995d5c57cab9b67297bab167c8 100644 (file)
@@ -67,6 +67,9 @@ protected:
         e_type type;
         double offset;
         double factor;
+        double min, max;
+        bool wrap;
+        bool rel;
         SGPropertyNode_ptr prop;
     } _serial_prot;
 
@@ -99,6 +102,27 @@ private:
     bool parse_message_binary(int length);
     void read_config(SGPropertyNode *root, vector<_serial_prot> &msg);
     bool exitOnError;
+    
+    template<class T>
+    static void updateValue(_serial_prot& prot, const T& val)
+    {
+      T new_val = (prot.rel ? getValue<T>(prot.prop) : 0)
+                + prot.offset
+                + prot.factor * val;
+                
+      if( prot.max > prot.min )
+      {
+        if( prot.wrap )
+          new_val = SGMisc<double>::normalizePeriodic(prot.min, prot.max, new_val);
+        else
+          new_val = SGMisc<T>::clip(new_val, prot.min, prot.max);
+      }
+
+      setValue(prot.prop, new_val);
+    }
+    
+    // Special handling for bool (relative change = toggle, no min/max, no wrap)
+    static void updateValue(_serial_prot& prot, bool val);
 };