diff --git a/src/Autopilot/autopilot.cxx b/src/Autopilot/autopilot.cxx index d6e87eb5e..7e5f67e6d 100644 --- a/src/Autopilot/autopilot.cxx +++ b/src/Autopilot/autopilot.cxx @@ -25,12 +25,17 @@ # include #endif +#include "autopilot.hxx" + +#include +#include + +#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 +{ +public: + virtual ~StateMachineFunctor() {} + virtual Component* operator()( SGPropertyNode_ptr configNode ) + { + return new StateMachineComponent(configNode); + } +}; + + class ComponentForge : public map *> { public: virtual ~ ComponentForge(); @@ -67,6 +106,7 @@ Autopilot::Autopilot( SGPropertyNode_ptr rootNode, SGPropertyNode_ptr configNode componentForge["filter"] = new CreateAndConfigureFunctor(); componentForge["logic"] = new CreateAndConfigureFunctor(); componentForge["flipflop"] = new CreateAndConfigureFunctor(); + componentForge["state-machine"] = new StateMachineFunctor(); } if( configNode == NULL ) configNode = rootNode; diff --git a/src/Autopilot/autopilot.hxx b/src/Autopilot/autopilot.hxx index b24977e56..3962081a8 100644 --- a/src/Autopilot/autopilot.hxx +++ b/src/Autopilot/autopilot.hxx @@ -23,17 +23,13 @@ #ifndef __AUTOPILOT_HXX #define __AUTOPILOT_HXX 1 -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "component.hxx" - #include #include namespace FGXMLAutopilot { +class Component; + /** * @brief A SGSubsystemGroup implementation to serve as a collection * of Components