]> git.mxchange.org Git - flightgear.git/commitdiff
Initial work on state-machine AP module.
authorJames Turner <zakalawe@mac.com>
Fri, 25 Jan 2013 08:34:57 +0000 (09:34 +0100)
committerJames Turner <zakalawe@mac.com>
Thu, 31 Jan 2013 22:40:48 +0000 (22:40 +0000)
src/Autopilot/autopilot.cxx
src/Autopilot/autopilot.hxx

index d6e87eb5e3acf83232ce675933b38333d1f533bd..7e5f67e6d6a302c789fb68f6bc2c059678573ba5 100644 (file)
 #  include <config.h>
 #endif
 
+#include "autopilot.hxx"
+
+#include <simgear/structure/StateMachine.hxx>
+#include <simgear/sg_inlines.h>
+
+#include "component.hxx"
 #include "functor.hxx"
 #include "predictor.hxx"
 #include "digitalfilter.hxx"
 #include "pisimplecontroller.hxx"
 #include "pidcontroller.hxx"
-#include "autopilot.hxx"
 #include "logic.hxx"
 #include "flipflop.hxx"
 
@@ -41,6 +46,40 @@ using std::string;
 
 using namespace FGXMLAutopilot;
 
+class StateMachineComponent : public Component
+{
+public:
+  StateMachineComponent(SGPropertyNode_ptr config)
+  {
+    inner = simgear::StateMachine::createFromPlist(config, globals->get_props());
+  }
+  
+  virtual bool configure( const std::string & nodeName, SGPropertyNode_ptr config)
+  {
+    return false;
+  }
+  
+  virtual void update( bool firstTime, double dt )
+  {
+    SG_UNUSED(firstTime);
+    inner->update(dt);
+  }
+  
+private:
+  simgear::StateMachine_ptr inner;
+};
+
+class StateMachineFunctor : public FunctorBase<Component>
+{
+public:
+  virtual ~StateMachineFunctor() {}
+  virtual Component* operator()( SGPropertyNode_ptr configNode )
+  {
+    return new StateMachineComponent(configNode);
+  }
+};
+
+
 class ComponentForge : public map<string,FunctorBase<Component> *> {
 public:
     virtual ~ ComponentForge();
@@ -67,6 +106,7 @@ Autopilot::Autopilot( SGPropertyNode_ptr rootNode, SGPropertyNode_ptr configNode
       componentForge["filter"]               = new CreateAndConfigureFunctor<DigitalFilter,Component>();
       componentForge["logic"]                = new CreateAndConfigureFunctor<Logic,Component>();
       componentForge["flipflop"]             = new CreateAndConfigureFunctor<FlipFlop,Component>();
+      componentForge["state-machine"]        = new StateMachineFunctor();
   }
 
   if( configNode == NULL ) configNode = rootNode;
index b24977e560adf1d8178e821dd0acbf4051ee73de..3962081a8beb238293b49c9604a5780cce16ad61 100644 (file)
 #ifndef __AUTOPILOT_HXX
 #define __AUTOPILOT_HXX 1
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#include "component.hxx"
-
 #include <simgear/props/props.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
 
 namespace FGXMLAutopilot {
 
+class Component;
+  
 /**
  * @brief A SGSubsystemGroup implementation to serve as a collection
  * of Components