diff --git a/ComponentBasic/BehaviorPerform.cpp b/ComponentBasic/BehaviorPerform.cpp index 6bf17e7..976b19f 100644 --- a/ComponentBasic/BehaviorPerform.cpp +++ b/ComponentBasic/BehaviorPerform.cpp @@ -109,9 +109,9 @@ void MapKernal::initial() registData(messageLoader()->makeDefault(key)); // 注册可用节点类型 - registNode(std::make_shared()); - registNode(std::make_shared()); - registNode(std::make_shared()); + registNode(std::make_shared(this->shared_from_this())); + registNode(std::make_shared(this->shared_from_this())); + registNode(std::make_shared(this->shared_from_this())); registNode(std::make_shared(this->shared_from_this())); registNode(std::make_shared(this->shared_from_this())); registNode(std::make_shared(this->shared_from_this())); @@ -199,6 +199,11 @@ std::shared_ptr LogicalNode::bindMap() const return std::dynamic_pointer_cast(node_temp); } +std::shared_ptr LogicalNode::getKernal() const +{ + return _bind_kernal; +} + void LogicalNode::setID(int unique_id) { this->_node_id = unique_id; @@ -220,12 +225,7 @@ std::weak_ptr LogicalNode::parent() const } BehaviorMapNode::BehaviorMapNode(std::shared_ptr core) - :LogicalNode(NodeKind::MAPNODE, core), _bind_kernal(core) { -} - -std::shared_ptr BehaviorMapNode::getKernal() const -{ - return _bind_kernal; + :LogicalNode(NodeKind::MAPNODE, core){ } void BehaviorMapNode::setVariable(const QString& key, IO_TYPE t, std::shared_ptr ins) @@ -251,7 +251,7 @@ void BehaviorMapNode::resetName(const QString& val) std::shared_ptr BehaviorMapNode::newDefault() const { - return std::make_shared(this->_bind_kernal); + return std::make_shared(this->getKernal()); } void BehaviorMapNode::recoveryFrom(const QJsonObject& obj) @@ -394,7 +394,7 @@ bool SequenceNode::fallback(std::shared_ptr node, LogicalResult ste std::shared_ptr SequenceNode::newDefault() const { - return std::make_shared(this->bindMap()->getKernal()); + return std::make_shared(this->getKernal()); } void SequenceNode::reset() @@ -425,8 +425,8 @@ void LogicalNode::remove(std::shared_ptr node) _child_list.removeAll(node); } -SelectorNode::SelectorNode(std::shared_ptr kernal) -: LogicalNode(NodeKind::SEQUENCENODE, kernal) { +SelectorNode::SelectorNode(std::shared_ptr kernal) + : LogicalNode(NodeKind::SEQUENCENODE, kernal) { } QList> SelectorNode::getForwards() const @@ -455,7 +455,7 @@ bool SelectorNode::fallback(std::shared_ptr node, LogicalResult ste std::shared_ptr SelectorNode::newDefault() const { - return std::make_shared(); + return std::make_shared(this->getKernal()); } void SelectorNode::recoveryFrom(const QJsonObject& obj) @@ -541,11 +541,11 @@ LogicalResult ParallelNode::execute() std::shared_ptr ParallelNode::newDefault() const { - return std::make_shared(); + return std::make_shared(this->getKernal()); } -ParallelNode::ParallelNode(std::shared_ptr kernal) -: LogicalNode(NodeKind::PARALLELNODE, kernal) { +ParallelNode::ParallelNode(std::shared_ptr kernal) + : LogicalNode(NodeKind::PARALLELNODE, kernal) { } QHash> ParallelNode::inputList() const @@ -612,11 +612,11 @@ bool CompareNode::fallback(std::shared_ptr node, LogicalResult ste) std::shared_ptr CompareNode::newDefault() const { - return std::make_shared(_bind_kernal); + return std::make_shared(getKernal()); } CompareNode::CompareNode(std::shared_ptr ins) - : LogicalNode(NodeKind::COMPARENODE, ins), _bind_kernal(ins) { + : LogicalNode(NodeKind::COMPARENODE, ins) { _data_map[u8"左值"] = std::make_shared(); _data_map[u8"右值"] = std::make_shared(); } @@ -655,7 +655,7 @@ void CompareNode::recoveryFrom(const QJsonObject& obj) QString delegate_name = ""; STRING_PEAK(delegate_name); - auto deins = _bind_kernal->getCompare(delegate_name); + auto deins = getKernal()->getCompare(delegate_name); bindDelegate(deins); } @@ -746,7 +746,7 @@ std::shared_ptr ConvertDelegate::convert(const QList ins) - : LogicalNode(NodeKind::ACTIONNODE), _bind_kernal(ins) { + : LogicalNode(NodeKind::ACTIONNODE, ins) { } QString ExecuteNode::delegateName() const @@ -809,7 +809,7 @@ bool ExecuteNode::fallback(std::shared_ptr node, LogicalResult ste) std::shared_ptr ExecuteNode::newDefault() const { - return std::make_shared(this->_bind_kernal); + return std::make_shared(this->getKernal()); } void ExecuteNode::recoveryFrom(const QJsonObject& obj) @@ -817,7 +817,7 @@ void ExecuteNode::recoveryFrom(const QJsonObject& obj) QString delegate_name = ""; STRING_PEAK(delegate_name); - auto de_ins = _bind_kernal->getExecute(delegate_name); + auto de_ins = getKernal()->getExecute(delegate_name); this->bindDelegate(de_ins); if (obj.contains("data_json")) { @@ -840,3 +840,7 @@ void ExecuteNode::saveTo(QJsonObject& obj) const obj["data_json"] = data_json; } } + +ModifiedNode::ModifiedNode(std::shared_ptr kernal) + : LogicalNode(NodeKind::MODIFYNODE, kernal) { +} diff --git a/ComponentBasic/BehaviorPerform.h b/ComponentBasic/BehaviorPerform.h index 7182ea7..ccc9ab5 100644 --- a/ComponentBasic/BehaviorPerform.h +++ b/ComponentBasic/BehaviorPerform.h @@ -364,6 +364,7 @@ public: /// /// std::shared_ptr bindMap() const; + std::shared_ptr getKernal() const; /// /// 回退节点 @@ -466,7 +467,6 @@ enum class IO_TYPE { /// class COMPONENTBASIC_EXPORT BehaviorMapNode : public LogicalNode { private: - std::shared_ptr _bind_kernal; QString _map_name = u8"行为树"; /// @@ -478,8 +478,6 @@ private: public: BehaviorMapNode(std::shared_ptr kernal); - std::shared_ptr getKernal() const; - /// /// 设置变量,如果类型错误会抛出UniException异常 /// 节点初始化时会按照配置注册默认值变量 @@ -630,8 +628,6 @@ public: /// class COMPONENTBASIC_EXPORT CompareNode : public LogicalNode { private: - std::shared_ptr _bind_kernal; - std::shared_ptr _bind_delegate; QHash> _data_map; @@ -663,7 +659,6 @@ public: /// class COMPONENTBASIC_EXPORT ExecuteNode : public LogicalNode { private: - std::shared_ptr _bind_kernal; std::shared_ptr _bind_delegate; public: @@ -702,10 +697,9 @@ class COMPONENTBASIC_EXPORT ModifiedNode : public LogicalNode { private: std::shared_ptr _bind_kernal; ModifyType _type_appoint = ModifyType::NONE; - + public: - ModifiedNode(std::shared_ptr kernal) - : _bind_kernal(kernal){} + ModifiedNode(std::shared_ptr kernal); ModifyType modifyType() const; void resetModify(ModifyType t);