From: James Turner Date: Tue, 25 Sep 2012 13:20:18 +0000 (+0100) Subject: Restore named JS/input configs (overrides) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ae6218ff102b8638a7ce584484748472d347fdd9;p=flightgear.git Restore named JS/input configs (overrides) Thanks to jano for pointing out I'd broken this feature! --- diff --git a/src/Input/FGDeviceConfigurationMap.cxx b/src/Input/FGDeviceConfigurationMap.cxx index b27d6816c..206ae6c4f 100644 --- a/src/Input/FGDeviceConfigurationMap.cxx +++ b/src/Input/FGDeviceConfigurationMap.cxx @@ -40,8 +40,17 @@ using simgear::PropertyList; using std::string; -FGDeviceConfigurationMap::FGDeviceConfigurationMap( const string& relative_path) +FGDeviceConfigurationMap::FGDeviceConfigurationMap( const string& relative_path, + SGPropertyNode* nodePath, + const std::string& nodeName) { + // scan for over-ride configurations, loaded via joysticks.xml, etc + BOOST_FOREACH(SGPropertyNode_ptr preloaded, nodePath->getChildren(nodeName)) { + BOOST_FOREACH(SGPropertyNode* nameProp, preloaded->getChildren("name")) { + overrideDict[nameProp->getStringValue()] = preloaded; + } // of names iteration + } // of defined overrides iteration + scan_dir( SGPath(globals->get_fg_home(), relative_path)); scan_dir( SGPath(globals->get_fg_root(), relative_path)); } @@ -53,6 +62,12 @@ FGDeviceConfigurationMap::~FGDeviceConfigurationMap() SGPropertyNode_ptr FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name) { + NameNodeMap::iterator j = overrideDict.find(name); + if (j != overrideDict.end()) { + return j->second; + } + +// no override, check out list of config files NamePathMap::iterator it = namePathMap.find(name); if (it == namePathMap.end()) { return SGPropertyNode_ptr(); @@ -71,6 +86,11 @@ FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name) bool FGDeviceConfigurationMap::hasConfiguration(const std::string& name) const { + NameNodeMap::const_iterator j = overrideDict.find(name); + if (j != overrideDict.end()) { + return true; + } + return namePathMap.find(name) != namePathMap.end(); } diff --git a/src/Input/FGDeviceConfigurationMap.hxx b/src/Input/FGDeviceConfigurationMap.hxx index 283973d28..8266a466b 100644 --- a/src/Input/FGDeviceConfigurationMap.hxx +++ b/src/Input/FGDeviceConfigurationMap.hxx @@ -37,7 +37,9 @@ class FGDeviceConfigurationMap { public: - FGDeviceConfigurationMap ( const std::string& relative_path); + FGDeviceConfigurationMap ( const std::string& relative_path, + SGPropertyNode* nodePath, + const std::string& nodeName); virtual ~FGDeviceConfigurationMap(); SGPropertyNode_ptr configurationForDeviceName(const std::string& name); @@ -49,6 +51,11 @@ private: void readCachedData(const SGPath& path); void refreshCacheForFile(const SGPath& path); + typedef std::map NameNodeMap; +// dictionary of over-ridden configurations, where the config data +// was explicitly loaded and shoudl be picked over a file search + NameNodeMap overrideDict; + typedef std::map NamePathMap; // mapping from joystick name to XML configuration file path NamePathMap namePathMap; diff --git a/src/Input/FGEventInput.cxx b/src/Input/FGEventInput.cxx index a6db87b31..071323414 100644 --- a/src/Input/FGEventInput.cxx +++ b/src/Input/FGEventInput.cxx @@ -294,7 +294,7 @@ void FGInputDevice::SetName( string name ) const char * FGEventInput::PROPERTY_ROOT = "/input/event"; FGEventInput::FGEventInput() : - configMap( "Input/Event") + configMap( "Input/Event", fgGetNode(PROPERTY_ROOT, true), "device-named") { } diff --git a/src/Input/FGJoystickInput.cxx b/src/Input/FGJoystickInput.cxx index e9ecc33ee..049ae7c2f 100644 --- a/src/Input/FGJoystickInput.cxx +++ b/src/Input/FGJoystickInput.cxx @@ -106,7 +106,7 @@ void FGJoystickInput::init() SGPropertyNode_ptr js_nodes = fgGetNode("/input/joysticks", true); status_node = fgGetNode("/devices/status/joysticks", true); - FGDeviceConfigurationMap configMap("Input/Joysticks"); + FGDeviceConfigurationMap configMap("Input/Joysticks",js_nodes, "js-named"); for (int i = 0; i < MAX_JOYSTICKS; i++) { jsJoystick * js = new jsJoystick(i);