#pragma once #include "componentbasic.h" #include /// /// 行为树实例化节点 /// class COMPONENTBASIC_EXPORT MapHost : public Serializable { private: /// /// {Topic,init-value} /// QHash> _variable_types; /// /// 变量表 /// QHash> _variable_map; public: virtual ~MapHost() = default; /// /// 注册数据类型 /// /// virtual void registData(std::shared_ptr init) = 0; /// /// 设置变量,如果类型错误会抛出UniException异常 /// 节点初始化时会按照配置注册默认值变量 /// virtual void setVariable(const QString& key, std::shared_ptr ins); /// /// 获取指定名称的数据变量 /// /// /// 如果不存在指定名称数据,返回nullptr,类型不确定 virtual std::shared_ptr getVariable(const QString& key) const; }; /// /// 所有逻辑节点的基类 /// class LogicalNode : public Serializable { public: virtual ~LogicalNode() = default; /// /// 设置节点id /// /// virtual void setID(int unique_id) = 0; /// /// 提取节点id /// /// virtual int getID() const = 0; /// /// 获取节点名称 /// /// virtual QString name() const = 0; /// /// 获取子节点列表 /// /// virtual QList> children() const = 0; /// /// 声明输入变量的内部标识和数据接口 /// /// map{name, type} virtual QHash> inputDeclares() const = 0; /// /// 声明输出变量的内部标识和数据接口 /// /// map{name, type} virtual QHash> outputDeclares() const = 0; }; /// /// 自定义行为树节点实例 /// class COMPONENTBASIC_EXPORT BehaviorMapNode : public MapHost, public LogicalNode { public: /// /// 重置行为树数据文件 /// /// virtual void setBehaviorMap(const QString &path){} /// /// 设置行为树节点名称 /// /// virtual void resetName(const QString &val){} }; /// /// 行为树组件 /// class COMPONENTBASIC_EXPORT BehaviorPerformPlugin : public ProcList< WsRespond >{ private: std::weak_ptr _bind_entity; public: // 通过 ProcList 继承 void execute(std::shared_ptr map, std::shared_ptr in, QList>& out) override; void recoveryFrom(const QJsonObject& obj) override; void saveTo(QJsonObject& obj) const override; std::shared_ptr defaultNew() const override; void bindEntity(std::weak_ptr host) override; QString name() const override; };