]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/autopilot.cxx
toggle fullscreen: also adapt GUI plane when resizing
[flightgear.git] / src / Autopilot / autopilot.cxx
index e8bb91b02bc857bf090267e962e67e2dc8d8f135..a4a593158b8c371d9a382d813623c966cf03bb69 100644 (file)
 
 #include "Main/fg_props.hxx"
 
+using std::map;
+using std::string;
+
 using namespace FGXMLAutopilot;
 
+class ComponentForge : public map<string,FunctorBase<Component> *> {
+public:
+    virtual ~ ComponentForge();
+};
+
+ComponentForge::~ComponentForge()
+{
+    for( iterator it = begin(); it != end(); ++it )
+        delete it->second;
+}
+
+static ComponentForge componentForge;
+
 Autopilot::Autopilot( SGPropertyNode_ptr rootNode, SGPropertyNode_ptr configNode ) :
   _name("unnamed autopilot"),
   _serviceable(true),
   _rootNode(rootNode)
 {
-  map<string,FunctorBase<Component> *> componentForge;
+
   componentForge["pid-controller"]       = new CreateAndConfigureFunctor<PIDController,Component>();
   componentForge["pi-simple-controller"] = new CreateAndConfigureFunctor<PISimpleController,Component>();
   componentForge["predict-simple"]       = new CreateAndConfigureFunctor<Predictor,Component>();
@@ -58,19 +74,21 @@ Autopilot::Autopilot( SGPropertyNode_ptr rootNode, SGPropertyNode_ptr configNode
     SGPropertyNode_ptr node = configNode->getChild(i);
     string childName = node->getName();
     if( componentForge.count(childName) == 0 ) {
-      SG_LOG( SG_AUTOPILOT, SG_BULK, "unhandled element <" << childName << ">" << endl );
+      SG_LOG( SG_AUTOPILOT, SG_BULK, "unhandled element <" << childName << ">" << std::endl );
       continue;
     }
 
     Component * component = (*componentForge[childName])(node);
     if( component->get_name().length() == 0 ) {
-      ostringstream buf;
+      std::ostringstream buf;
       buf <<  "unnamed_component_" << i;
       component->set_name( buf.str() );
     }
 
-    SG_LOG( SG_AUTOPILOT, SG_INFO, "adding  autopilot component \"" << childName << "\" as \"" << component->get_name() << "\"" );
-    add_component(component);
+    double updateInterval = node->getDoubleValue( "update-interval-secs", 0.0 );
+
+    SG_LOG( SG_AUTOPILOT, SG_DEBUG, "adding  autopilot component \"" << childName << "\" as \"" << component->get_name() << "\" with interval=" << updateInterval );
+    add_component(component,updateInterval);
   }
 }
 
@@ -89,21 +107,21 @@ void Autopilot::unbind()
   _rootNode->untie( "serviceable" );
 }
 
-void Autopilot::add_component( Component * component )
+void Autopilot::add_component( Component * component, double updateInterval )
 {
   if( component == NULL ) return;
 
   // check for duplicate name
   std::string name = component->get_name();
   for( unsigned i = 0; get_subsystem( name.c_str() ) != NULL; i++ ) {
-      ostringstream buf;
+      std::ostringstream buf;
       buf <<  component->get_name() << "_" << i;
       name = buf.str();
   }
   if( name != component->get_name() )
     SG_LOG( SG_ALL, SG_WARN, "Duplicate autopilot component " << component->get_name() << ", renamed to " << name );
 
-  set_subsystem( name.c_str(), component );
+  set_subsystem( name.c_str(), component, updateInterval );
 }
 
 void Autopilot::update( double dt )