From: Torsten Dreyer Date: Thu, 5 Apr 2012 18:40:07 +0000 (+0200) Subject: Autopilot: save loads of CPU cycles X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=68e1a8c4cb13f365a7d01ed5d20a112404694f05;p=flightgear.git Autopilot: save loads of CPU cycles Not every xml-autopilot filter needs to run at the update rate of the FDM. This only makes sense for the autpilot filters. Those, who update instrument needles or environment properties for example may run at frame rate. This patch (thanks to ThorstenB, who is the author) forces those filters defined in /sim/systems/autopilot into the FDM loop and those defined in /sim/systems/property-rule into the default loop. They show up as xml-autopilot and xml-proprules in the performance monitor --- diff --git a/src/Autopilot/autopilotgroup.cxx b/src/Autopilot/autopilotgroup.cxx index 8cf389f8e..c9df860d2 100644 --- a/src/Autopilot/autopilotgroup.cxx +++ b/src/Autopilot/autopilotgroup.cxx @@ -44,6 +44,8 @@ using simgear::PropertyList; class FGXMLAutopilotGroupImplementation : public FGXMLAutopilotGroup { public: + FGXMLAutopilotGroupImplementation(const std::string& nodeName) : + FGXMLAutopilotGroup(), _nodeName(nodeName) {} virtual void addAutopilot( const std::string & name, SGPropertyNode_ptr apNode, SGPropertyNode_ptr config ); virtual void removeAutopilot( const std::string & name ); void init(); @@ -52,6 +54,7 @@ public: private: void initFrom( SGPropertyNode_ptr rootNode, const char * childName ); vector _autopilotNames; + std::string _nodeName; }; @@ -100,12 +103,7 @@ void FGXMLAutopilotGroupImplementation::reinit() void FGXMLAutopilotGroupImplementation::init() { - static const char * nodeNames[] = { - "autopilot", - "property-rule" - }; - for( unsigned i = 0; i < sizeof(nodeNames)/sizeof(nodeNames[0]); i++ ) - initFrom( fgGetNode( "/sim/systems" ), nodeNames[i] ); + initFrom( fgGetNode( "/sim/systems" ), _nodeName.c_str() ); SGSubsystemGroup::bind(); SGSubsystemGroup::init(); @@ -173,7 +171,7 @@ void FGXMLAutopilotGroup::addAutopilotFromFile( const std::string & name, SGProp } } -FGXMLAutopilotGroup * FGXMLAutopilotGroup::createInstance() +FGXMLAutopilotGroup * FGXMLAutopilotGroup::createInstance(const std::string& nodeName) { - return new FGXMLAutopilotGroupImplementation(); + return new FGXMLAutopilotGroupImplementation(nodeName); } diff --git a/src/Autopilot/autopilotgroup.hxx b/src/Autopilot/autopilotgroup.hxx index 6e6c1f196..5390f8c43 100644 --- a/src/Autopilot/autopilotgroup.hxx +++ b/src/Autopilot/autopilotgroup.hxx @@ -31,7 +31,7 @@ class FGXMLAutopilotGroup : public SGSubsystemGroup { public: - static FGXMLAutopilotGroup * createInstance(); + static FGXMLAutopilotGroup * createInstance(const std::string& nodeName); void addAutopilotFromFile( const std::string & name, SGPropertyNode_ptr apNode, const char * path ); virtual void addAutopilot( const std::string & name, SGPropertyNode_ptr apNode, SGPropertyNode_ptr config ) = 0; virtual void removeAutopilot( const std::string & name ) = 0; diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index d26a93bce..8f1141c26 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1251,7 +1251,8 @@ bool fgInitSubsystems() { // Initialize the XML Autopilot subsystem. //////////////////////////////////////////////////////////////////// - globals->add_subsystem( "xml-autopilot", FGXMLAutopilotGroup::createInstance(), SGSubsystemMgr::FDM ); + globals->add_subsystem( "xml-autopilot", FGXMLAutopilotGroup::createInstance("autopilot"), SGSubsystemMgr::FDM ); + globals->add_subsystem( "xml-proprules", FGXMLAutopilotGroup::createInstance("property-rule"), SGSubsystemMgr::GENERAL ); globals->add_subsystem( "route-manager", new FGRouteMgr ); ////////////////////////////////////////////////////////////////////