From 100439aadd5d07a94a343e78100f3bfab869205f Mon Sep 17 00:00:00 2001 From: Richard Harrison Date: Wed, 5 Jul 2017 01:19:23 +0200 Subject: [PATCH] Model relative property tree root binding. This fixes the animation bindings to use the defined property tree root - to support multiplayer (or other) model that can bind to the correct part of the property tree. Requires a corresponding fix in fg to allow the command methods to take an optional root parameter. What this means is that when inside someone else's multiplayer model (e.g. backseat, or co-pilot), the multipalyer (AI) model will correctly modify properties inside the correct part of the property tree inside (/ai), rather than modifying the properties inside the same part of the tree as the non-ai model. This means that a properly setup model will operate within it's own space in the property tree; and permit more generic multiplayer code to be written. This is probably responsible for some of the pollution of the /sim property tree with MP aircraft properties. --- simgear/structure/SGBinding.cxx | 4 +++- simgear/structure/SGBinding.hxx | 1 + simgear/structure/commands.cxx | 4 ++-- simgear/structure/commands.hxx | 12 ++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/simgear/structure/SGBinding.cxx b/simgear/structure/SGBinding.cxx index 4a0d0326..320e13a1 100644 --- a/simgear/structure/SGBinding.cxx +++ b/simgear/structure/SGBinding.cxx @@ -69,7 +69,9 @@ SGBinding::read(const SGPropertyNode* node, SGPropertyNode* root) } _arg = const_cast(node); + _root = const_cast(root); _setting = 0; + } void @@ -89,7 +91,7 @@ SGBinding::innerFire () const SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding:" << _command_name); } else { try { - if (!(*_command)(_arg)) { + if (!(*_command)(_arg, _root)) { SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command " << _command_name); } diff --git a/simgear/structure/SGBinding.hxx b/simgear/structure/SGBinding.hxx index 6ec2bc68..3574a524 100644 --- a/simgear/structure/SGBinding.hxx +++ b/simgear/structure/SGBinding.hxx @@ -142,6 +142,7 @@ private: mutable SGCommandMgr::Command* _command; mutable SGPropertyNode_ptr _arg; mutable SGPropertyNode_ptr _setting; + mutable SGPropertyNode_ptr _root; }; typedef SGSharedPtr SGBinding_ptr; diff --git a/simgear/structure/commands.cxx b/simgear/structure/commands.cxx index 752f880c..150e16aa 100644 --- a/simgear/structure/commands.cxx +++ b/simgear/structure/commands.cxx @@ -75,7 +75,7 @@ SGCommandMgr::getCommandNames () const } bool -SGCommandMgr::execute (const std::string &name, const SGPropertyNode * arg) const +SGCommandMgr::execute (const std::string &name, const SGPropertyNode * arg, SGPropertyNode *root) const { Command* command = getCommand(name); if (command == 0) @@ -86,7 +86,7 @@ SGCommandMgr::execute (const std::string &name, const SGPropertyNode * arg) cons try { - return (*command)(arg); + return (*command)(arg, root); } catch(sg_exception& e) { diff --git a/simgear/structure/commands.hxx b/simgear/structure/commands.hxx index 7f4185ec..58d8c281 100644 --- a/simgear/structure/commands.hxx +++ b/simgear/structure/commands.hxx @@ -41,11 +41,11 @@ public: { public: virtual ~Command() { } - virtual bool operator()(const SGPropertyNode * arg) = 0; + virtual bool operator()(const SGPropertyNode * arg, SGPropertyNode *root) = 0; }; - typedef bool (*command_t) (const SGPropertyNode * arg); + typedef bool (*command_t) (const SGPropertyNode * arg, SGPropertyNode *root); private: class FunctionCommand : public Command @@ -54,7 +54,7 @@ private: FunctionCommand( command_t fun ) : f_(fun) {} - virtual bool operator()(const SGPropertyNode * arg) { return (*f_)(arg); } + virtual bool operator()(const SGPropertyNode * arg, SGPropertyNode *root) { return (*f_)(arg, root); } private: command_t f_; }; @@ -66,9 +66,9 @@ private: MethodCommand( const ObjPtr& pObj, MemFn pMemFn ) : pObj_(pObj), pMemFn_(pMemFn) {} - virtual bool operator()(const SGPropertyNode * arg) + virtual bool operator()(const SGPropertyNode * arg, SGPropertyNode *root) { - return ((*pObj_).*pMemFn_)(arg); + return ((*pObj_).*pMemFn_)(arg,root); } private: ObjPtr pObj_; @@ -147,7 +147,7 @@ public: * @return true if the command is present and executes successfully, * false otherwise. */ - virtual bool execute (const std::string &name, const SGPropertyNode * arg) const; + virtual bool execute (const std::string &name, const SGPropertyNode * arg, SGPropertyNode *root) const; /** * Remove a command registration