Files
oops-plugin-framework/assets/libs/behavior-tree/BranchNode.ts
dgflash f2fe9d47b6 1. 存储模块全面优化,修复跨平台兼容性问题,完美支持所有Unicode字符
2. 存储模块性能提升,添加LRU缓存、批量操作支持,优化内存使用
3. 多语言模块性能与内存管理优化,组件查询性能提升
4. 时间模块类型安全与性能优化,使用泛型替代any,对象池机制减少内存分配
5. 事件系统修复双重注册、重复注册等严重问题,实现EventData对象池减少GC压力
6. RandomManager修复4个逻辑BUG,包括边界问题和越界问题
7. 音频模块内存与性能优化,避免重复加载,优化数据结构,添加完整清理机制
8. CCView与CCViewVM合并,支持按需启用MVVM
9. Collection模块优化,AsyncQueue添加队列容量限制,Collection查询性能提升
10. ECS系统全面优化,对象池复用减少内存分配,循环性能提升
11. 优化MVVM组件性能
2026-01-09 21:54:05 +08:00

98 lines
2.5 KiB
TypeScript

/*
* @Author: dgflash
* @Date: 2022-06-21 12:05:14
* @LastEditors: dgflash
* @LastEditTime: 2022-07-20 13:58:32
*/
import { BehaviorTree } from './BehaviorTree';
import { BTreeNode } from './BTreeNode';
/** 复合节点 */
export abstract class BranchNode extends BTreeNode {
/** 子节点数组 */
children: Array<BTreeNode>;
/** 当前任务索引 */
protected _actualTask: number = 0;
/** 正在运行的节点 */
protected _runningNode: BTreeNode | null = null;
protected _nodeRunning: BTreeNode | null = null;
/** 外部参数对象 */
protected _blackboard: any;
constructor(nodes: Array<BTreeNode>) {
super();
this.children = nodes || [];
}
start() {
this._actualTask = 0;
super.start();
}
run(blackboard?: any) {
if (this.children.length === 0) { // 没有子任务直接视为执行失败
if (this._control) {
this._control.fail();
}
}
else {
this._blackboard = blackboard;
this.start();
if (this._actualTask < this.children.length) {
this._run();
}
}
this.end();
}
/** 执行当前节点逻辑 */
protected _run(blackboard?: any) {
// 直接使用子节点,不需要通过 getNode 查询(性能优化)
const node = this.children[this._actualTask];
if (node) {
this._runningNode = node;
node.setControl(this);
node.start(this._blackboard);
node.run(this._blackboard);
}
}
running(node: BTreeNode) {
this._nodeRunning = node;
if (this._control) {
this._control.running(node);
}
}
success() {
this._nodeRunning = null;
if (this._runningNode) {
this._runningNode.end(this._blackboard);
}
}
fail() {
this._nodeRunning = null;
if (this._runningNode) {
this._runningNode.end(this._blackboard);
}
}
/** 清理节点资源 */
destroy() {
// 清理所有子节点
if (this.children) {
this.children.forEach(child => {
if (child && typeof child.destroy === 'function') {
child.destroy();
}
});
}
this._runningNode = null;
this._nodeRunning = null;
this._blackboard = null;
super.destroy();
}
}