]> git.mxchange.org Git - flightgear.git/commitdiff
Small refactoring of the submodel patch from onox
authorTorsten Dreyer <torsten@ŧ3r.de>
Thu, 30 Apr 2015 09:39:00 +0000 (11:39 +0200)
committerErik Hofman <erik@ehofman.com>
Mon, 18 May 2015 10:34:56 +0000 (12:34 +0200)
Signed-off-by: onox <denkpadje@gmail.com>
Signed-off-by: Erik Hofman <erik@ehofman.com>
src/AIModel/submodel.cxx
src/AIModel/submodel.hxx

index 70a13eec3ab5b0ebf3514734b20b3ba8d61413fc..d66a8e413494c19dc347a9140e78bd6627f7d0c7 100644 (file)
@@ -28,8 +28,6 @@ using std::endl;
 using std::string;
 using std::vector;
 
-using FGXMLAutopilot::InputValue;
-
 const double FGSubmodelMgr::lbs_to_slugs = 0.031080950172;
 
 FGSubmodelMgr::FGSubmodelMgr()
@@ -269,10 +267,8 @@ bool FGSubmodelMgr::release(submodel *sm, double dt)
     double yaw_offset   = 0.0;
     double pitch_offset = 0.0;
 
-    if (sm->yaw_node != 0)
-        yaw_offset = sm->yaw_node->get_value();
-    if (sm->pitch_node != 0)
-        pitch_offset = sm->pitch_node->get_value();
+    yaw_offset = sm->yaw_offset->get_value();
+    pitch_offset = sm->pitch_offset->get_value();
 
     transform(sm);  // calculate submodel's initial conditions in world-coordinates
 
@@ -366,10 +362,8 @@ void FGSubmodelMgr::transform(submodel *sm)
     double yaw_offset   = 0.0;
     double pitch_offset = 0.0;
 
-    if (sm->yaw_node != 0)
-        yaw_offset = sm->yaw_node->get_value();
-    if (sm->pitch_node != 0)
-        pitch_offset = sm->pitch_node->get_value();
+    yaw_offset = sm->yaw_offset->get_value();
+    pitch_offset = sm->pitch_offset->get_value();
 
     //cout << " name " << name << " id " << id << " sub id" << sub_id << endl;
 
@@ -586,15 +580,14 @@ void FGSubmodelMgr::setData(int id, const string& path, bool serviceable)
         sm->random                     = entry_node->getBoolValue("random", false);
         sm->randomness         = entry_node->getDoubleValue("randomness", 0.5);
 
-        SGPropertyNode_ptr a = entry_node->getNode("yaw-offset");
-        SGPropertyNode_ptr b = entry_node->getNode("pitch-offset");
         SGPropertyNode_ptr prop_root = fgGetNode("/", true);
-        sm->yaw_node        = 0;
-        sm->pitch_node      = 0;
-        if (a != 0)
-            sm->yaw_node    = new InputValue(*prop_root, *a);
-        if (b != 0)
-            sm->pitch_node  = new InputValue(*prop_root, *b);
+        SGPropertyNode n;
+
+        SGPropertyNode_ptr a = entry_node->getNode("yaw-offset");
+        sm->yaw_offset    = new FGXMLAutopilot::InputValue(*prop_root, a ? *a : n );
+
+        a = entry_node->getNode("pitch-offset");
+        sm->pitch_offset  = new FGXMLAutopilot::InputValue(*prop_root, a ? *a : n );
 
         if (sm->contents_node != 0)
             sm->contents = sm->contents_node->getDoubleValue();
@@ -699,15 +692,14 @@ void FGSubmodelMgr::setSubData(int id, const string& path, bool serviceable)
         sm->random          = entry_node->getBoolValue("random", false);
         sm->randomness      = entry_node->getDoubleValue("randomness", 0.5);
 
-        SGPropertyNode_ptr a = entry_node->getNode("yaw-offset");
-        SGPropertyNode_ptr b = entry_node->getNode("pitch-offset");
         SGPropertyNode_ptr prop_root = fgGetNode("/", true);
-        sm->yaw_node        = 0;
-        sm->pitch_node      = 0;
-        if (a != 0)
-            sm->yaw_node    = new InputValue(*prop_root, *a);
-        if (b != 0)
-            sm->pitch_node  = new InputValue(*prop_root, *b);
+        SGPropertyNode n;
+
+        SGPropertyNode_ptr a = entry_node->getNode("yaw-offset");
+        sm->yaw_offset    = new FGXMLAutopilot::InputValue(*prop_root, a ? *a : n );
+
+        a = entry_node->getNode("pitch-offset");
+        sm->pitch_offset  = new FGXMLAutopilot::InputValue(*prop_root, a ? *a : n );
 
         if (sm->contents_node != 0)
             sm->contents = sm->contents_node->getDoubleValue();
index 5546f0df242bc283872f16258b4e63cb664e0dd7..21583b2f71ae40494c3a41b40a18b7d57c8afdeb 100644 (file)
@@ -20,8 +20,6 @@
 #include <vector>
 #include <string>
 
-using FGXMLAutopilot::InputValue_ptr;
-
 class FGAIBase;
 class FGAIManager;
 
@@ -36,8 +34,6 @@ public:
         SGPropertyNode_ptr contents_node;
         SGPropertyNode_ptr submodel_node;
         SGPropertyNode_ptr speed_node;
-        InputValue_ptr yaw_node;
-        InputValue_ptr pitch_node;
 
         std::string        name;
         std::string        model;
@@ -50,6 +46,8 @@ public:
         double             x_offset;
         double             y_offset;
         double             z_offset;
+        FGXMLAutopilot::InputValue_ptr yaw_offset;
+        FGXMLAutopilot::InputValue_ptr pitch_offset;
         double             drag_area;
         double             life;
         double             buoyancy;