| 48 | * 执行上下文提供对运行时服务的访问 |
| 49 | */ |
| 50 | export class ExecutionContext { |
| 51 | /** Current blueprint asset (当前蓝图资产) */ |
| 52 | readonly blueprint: BlueprintAsset; |
| 53 | |
| 54 | /** Owner entity (所有者实体) */ |
| 55 | readonly entity: Entity; |
| 56 | |
| 57 | /** Current scene (当前场景) */ |
| 58 | readonly scene: IScene; |
| 59 | |
| 60 | /** Frame delta time (帧增量时间) */ |
| 61 | deltaTime: number = 0; |
| 62 | |
| 63 | /** Total time since start (开始以来的总时间) */ |
| 64 | time: number = 0; |
| 65 | |
| 66 | /** Instance variables (实例变量) */ |
| 67 | private _instanceVariables: Map<string, unknown> = new Map(); |
| 68 | |
| 69 | /** Local variables (per-execution) (局部变量,每次执行) */ |
| 70 | private _localVariables: Map<string, unknown> = new Map(); |
| 71 | |
| 72 | /** Global variables (shared) (全局变量,共享) */ |
| 73 | private static _globalVariables: Map<string, unknown> = new Map(); |
| 74 | |
| 75 | /** Node output cache for current execution (当前执行的节点输出缓存) */ |
| 76 | private _outputCache: Map<string, Record<string, unknown>> = new Map(); |
| 77 | |
| 78 | /** Connection lookup by target (按目标的连接查找) */ |
| 79 | private _connectionsByTarget: Map<string, BlueprintConnection[]> = new Map(); |
| 80 | |
| 81 | /** Connection lookup by source (按源的连接查找) */ |
| 82 | private _connectionsBySource: Map<string, BlueprintConnection[]> = new Map(); |
| 83 | |
| 84 | constructor(blueprint: BlueprintAsset, entity: Entity, scene: IScene) { |
| 85 | this.blueprint = blueprint; |
| 86 | this.entity = entity; |
| 87 | this.scene = scene; |
| 88 | |
| 89 | // Initialize instance variables with defaults |
| 90 | // 使用默认值初始化实例变量 |
| 91 | for (const variable of blueprint.variables) { |
| 92 | if (variable.scope === 'instance') { |
| 93 | this._instanceVariables.set(variable.name, variable.defaultValue); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // Build connection lookup maps |
| 98 | // 构建连接查找映射 |
| 99 | this._buildConnectionMaps(); |
| 100 | } |
| 101 | |
| 102 | private _buildConnectionMaps(): void { |
| 103 | for (const conn of this.blueprint.connections) { |
| 104 | // By target |
| 105 | const targetKey = `${conn.toNodeId}.${conn.toPin}`; |
| 106 | if (!this._connectionsByTarget.has(targetKey)) { |
| 107 | this._connectionsByTarget.set(targetKey, []); |
nothing calls this directly
no outgoing calls
no test coverage detected